updated link on awaiting submission view allin welsh Related work items: #24389
1152 lines
50 KiB
JavaScript
1152 lines
50 KiB
JavaScript
import { JSONPath as jsonpath } from "jsonpath-plus";
|
|
import _ from "lodash";
|
|
import useTranslation from "next-translate/useTranslation";
|
|
import Link from "next/link";
|
|
import { useRouter } from "next/router";
|
|
import { parseCookies } from "nookies";
|
|
import { useState } from "react";
|
|
import { connect } from "react-redux";
|
|
import {
|
|
deleteAwaitingSubmissionsFromBlob,
|
|
deleteMyRepresentationsFromBlob,
|
|
getAwaitingSubmissionFromBlobProxy,
|
|
getRepsFromBlobProxy
|
|
} from "../../actions/services/documentService";
|
|
import {
|
|
createWatchedCases,
|
|
deleteWatchedCases,
|
|
getWatchedCases,
|
|
getWatchedCasesProxy
|
|
} from "../../actions/services/portalService";
|
|
import { splitWatchedCasesBySubmissionState } from "../../lib/domain/dashboard-policy";
|
|
import { consoleLogger } from "../../actions/core/logger";
|
|
import {
|
|
getDetailsProxy,
|
|
getFormCollectionByID,
|
|
hasOwn
|
|
} from "../../components/utils";
|
|
import transLookup from "../../data/lookuptranslations.json";
|
|
import { setAwaitingSubmissionFromBlob } from "../../store/awaitingSubmission/action";
|
|
import {
|
|
setSearchDetails,
|
|
setSearchResults
|
|
} from "../../store/searchOutput/action";
|
|
|
|
import { setAwaitingSubmissionDetails } from "../../store/awaitingSubmission/action";
|
|
import {
|
|
setWatchedCases,
|
|
setWatchedCasesDetails
|
|
} from "../../store/watchedCases/action";
|
|
|
|
import {
|
|
setCurrentReference,
|
|
setCurrentView
|
|
} from "../../store/currentView/action";
|
|
import {
|
|
setMyRepresentations,
|
|
setMyRepresentationsDetails
|
|
} from "../../store/myRepresentations/action";
|
|
import resolveCrmDisplayValue from "../../lib/i18n/crmDisplay/resolveCrmDisplayValue";
|
|
|
|
const ViewAllResults = (props) => {
|
|
const {
|
|
searchString,
|
|
searchResultsObj,
|
|
setCurrentReference,
|
|
myportal,
|
|
setSearchResults,
|
|
accountDetails,
|
|
setAwaitingSubmissionFromBlob,
|
|
setAwaitingSubmissionDetails,
|
|
setWatchedCasesDetails,
|
|
setWatchedCases,
|
|
setMyRepresentations,
|
|
setMyRepresentationsDetails
|
|
} = props;
|
|
|
|
let { t } = useTranslation();
|
|
|
|
const router = useRouter();
|
|
const { locale } = router;
|
|
const repRaisedDate = (datePart) => {
|
|
var dateObj = new Date(
|
|
datePart.split("-")[0] +
|
|
"-" +
|
|
datePart.split("-")[1] +
|
|
"-" +
|
|
datePart.split("-")[2] +
|
|
" " +
|
|
datePart.split("-")[3].split("_")[0].slice(0, 2) +
|
|
":" +
|
|
datePart.split("-")[3].split("_")[0].slice(2, 4) +
|
|
":" +
|
|
datePart.split("-")[3].split("_")[0].slice(4, 6)
|
|
);
|
|
|
|
return dateObj.toLocaleString();
|
|
};
|
|
|
|
let viewKeyFromUrl = router.query.key;
|
|
|
|
let currentView = props.currentView.currentView;
|
|
//console.log("currentViewKey:", typeof currentViewKey);
|
|
|
|
// typeof currentViewKey == "undefined"
|
|
// ? console.log("no currentview")
|
|
// : console.log("has currentview");
|
|
|
|
let currentViewKey = currentView.viewKey || viewKeyFromUrl;
|
|
|
|
const isAwaitingSubmissionDetails =
|
|
currentViewKey === "awaitingSubmissionDetails";
|
|
const isMySubmittedReps = currentViewKey === "mySubmittedReps";
|
|
const isMyRepresentations = currentViewKey === "myRepresentations";
|
|
const isWatchedCases = currentViewKey === "watchedCases";
|
|
const isMyCases = currentViewKey === "myCases";
|
|
|
|
const resultsArr = isAwaitingSubmissionDetails
|
|
? props["awaitingSubmission"].awaitingSubmissionDetails.case
|
|
: isMySubmittedReps
|
|
? props[currentViewKey][currentViewKey]
|
|
: props[currentViewKey][currentViewKey].value || [];
|
|
|
|
const [orderByState, setOrderbyState] = useState("createdon");
|
|
const [fieldSortState, setfieldSortState] = useState("asc");
|
|
const [showSpinnerState, setShowSpinnerState] = useState(false);
|
|
const [selectedOption, setSelectedOption] = useState(10);
|
|
|
|
function formatDates(dateObj) {
|
|
var dateObj = new Date(dateObj);
|
|
var dd = String(dateObj.getDate()).padStart(2, "0");
|
|
var mm = String(dateObj.getMonth() + 1).padStart(2, "0"); //January is 0!
|
|
var yyyy = dateObj.getFullYear();
|
|
|
|
return dd + "/" + mm + "/" + yyyy;
|
|
}
|
|
|
|
var searchDetailsObj = isAwaitingSubmissionDetails
|
|
? props["awaitingSubmission"].awaitingSubmissionDetails.value
|
|
: isMyRepresentations
|
|
? props["myRepresentations"].myRepresentations.value
|
|
: props[currentViewKey][currentViewKey + "Details"] || [];
|
|
|
|
const getViewTitle = () => {
|
|
if (isAwaitingSubmissionDetails) {
|
|
return t("myportal:awatitingsubmission-card-title");
|
|
}
|
|
if (isWatchedCases) {
|
|
return t("myportal:watchedcases-card-title");
|
|
}
|
|
if (isMyCases) {
|
|
return t("myportal:mycases-card-title");
|
|
}
|
|
if (isMyRepresentations) {
|
|
return t("myportal:myrepresentations-card-title");
|
|
}
|
|
if (isMySubmittedReps) {
|
|
return "Submitted representations";
|
|
}
|
|
return "";
|
|
};
|
|
|
|
const getSortButtonClass = (field) => {
|
|
if (orderByState !== field) {
|
|
return "govuk-link govuk-link--no-underline govuk-!-font-weight-bold govuk-!-font-size-16";
|
|
}
|
|
return fieldSortState === "asc"
|
|
? "govuk-link govuk-link--no-underline govuk-!-font-weight-bold govuk-!-font-size-16 sortAsc"
|
|
: "govuk-link govuk-link--no-underline govuk-!-font-weight-bold govuk-!-font-size-16 sortDesc";
|
|
};
|
|
|
|
const getCaseReferenceSortField = () => {
|
|
return isAwaitingSubmissionDetails ? "title" : "pinswg_title";
|
|
};
|
|
|
|
const getAuthoritySortField = () => {
|
|
return isAwaitingSubmissionDetails
|
|
? "pinswg_lpaname"
|
|
: "_pinswg_associatedlpa_value@OData.Community.Display.V1.FormattedValue";
|
|
};
|
|
|
|
const getEmptyStateTitle = () => getViewTitle();
|
|
|
|
const shouldShowActionColumn = () => {
|
|
return (
|
|
isWatchedCases || isAwaitingSubmissionDetails || isMyRepresentations
|
|
);
|
|
};
|
|
|
|
const getApplicantOrCreatedHeading = () => {
|
|
return isAwaitingSubmissionDetails
|
|
? t("search:searchresults-created-on-label")
|
|
: t("search:searchresults-applicant-label");
|
|
};
|
|
|
|
const getStatusHeading = () => {
|
|
return isMyRepresentations
|
|
? "Created"
|
|
: t("search:searchresults-status-label");
|
|
};
|
|
|
|
const getJsonPathPrefix = () => {
|
|
return isMyRepresentations ? "" : "..value";
|
|
};
|
|
|
|
const getJsonPathName = (item) => {
|
|
if (isAwaitingSubmissionDetails) return item.title;
|
|
if (isWatchedCases) return item.ticketnumber;
|
|
if (isMyRepresentations) return item.pinswg_name;
|
|
return item.pinswg_title;
|
|
};
|
|
|
|
const getCaseLinkHref = (item) => {
|
|
if (isMyRepresentations) {
|
|
return {
|
|
pathname: "/myportal/representation",
|
|
query: {
|
|
case: item.caseRef,
|
|
state: "edit",
|
|
created: item.repfile_name
|
|
}
|
|
};
|
|
}
|
|
|
|
if (isAwaitingSubmissionDetails) {
|
|
return (
|
|
(router.locale === "cy" ? "/fymhorth" : "/myportal") +
|
|
"/" +
|
|
getFormCollectionByID(item.pinswg_appealcasetype).UrlName +
|
|
"?lpa=" +
|
|
item["_pinswg_associatedlpa_value"] +
|
|
"&apt=" +
|
|
item.pinswg_appealcasetype +
|
|
"&casereference=" +
|
|
item.title +
|
|
"&inid=" +
|
|
item.incidentid +
|
|
"&key=" +
|
|
currentViewKey
|
|
);
|
|
}
|
|
|
|
if (router.locale === "cy") {
|
|
return myportal === true
|
|
? "/fymhorth/achos/" +
|
|
item.ticketnumber +
|
|
"?key=" +
|
|
currentViewKey +
|
|
"&va=true"
|
|
: "/achos" + item.ticketnumber;
|
|
}
|
|
|
|
return myportal === true
|
|
? "/myportal/case/" +
|
|
item.ticketnumber +
|
|
"?key=" +
|
|
currentViewKey +
|
|
"&va=true"
|
|
: "/case/" + item.ticketnumber;
|
|
};
|
|
|
|
const getCurrentReference = (item) => {
|
|
if (isWatchedCases) {
|
|
return item[
|
|
"_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue"
|
|
];
|
|
}
|
|
if (isMyRepresentations) {
|
|
return item.caseRef;
|
|
}
|
|
return item.ticketnumber;
|
|
};
|
|
|
|
const getIncidentId = (item) => {
|
|
return isWatchedCases
|
|
? item["_pinswg_watchedcase_value"]
|
|
: item.incidentid;
|
|
};
|
|
|
|
const getReferenceLabel = (item) => {
|
|
if (isWatchedCases) {
|
|
return item[
|
|
"_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue"
|
|
];
|
|
}
|
|
if (isMyRepresentations) {
|
|
return item.caseRef;
|
|
}
|
|
if (isAwaitingSubmissionDetails) {
|
|
return item.title;
|
|
}
|
|
return item.pinswg_title;
|
|
};
|
|
|
|
const handleCaseLinkClick = (item) => {
|
|
if (isWatchedCases) {
|
|
setSearchResults(props.watchedCases.watchedCases);
|
|
setSearchDetails(props.watchedCases.watchedCasesDetails);
|
|
}
|
|
|
|
setCurrentReference({
|
|
"statuscode": item.statuscode ?? null,
|
|
ticketnumber: item.ticketnumber,
|
|
currentReference: getCurrentReference(item),
|
|
currentType: currentViewKey,
|
|
incidentid: getIncidentId(item),
|
|
appealType: item.pinswg_appealcasetype,
|
|
repDetails: isMyRepresentations && item
|
|
});
|
|
|
|
setCurrentView({
|
|
viewName: currentView.viewName,
|
|
viewKey: currentViewKey
|
|
});
|
|
};
|
|
|
|
let resultsRowArr = [];
|
|
|
|
const downloadPDF = async (docProps, ticketnumber) => {
|
|
try {
|
|
const res = await fetch("/api/file/generateappealpdfcopy", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ docProps })
|
|
});
|
|
|
|
if (!res.ok) throw new Error("PDF generation failed");
|
|
|
|
const blob = await res.blob();
|
|
const url = URL.createObjectURL(blob);
|
|
const a = document.createElement("a");
|
|
a.href = url;
|
|
a.download = `Appeal_${ticketnumber || "summary"}.pdf`;
|
|
a.click();
|
|
URL.revokeObjectURL(url);
|
|
} catch (err) {
|
|
console.error("Download error:", err);
|
|
alert("Could not generate PDF.");
|
|
}
|
|
};
|
|
|
|
const buildResultsRowArr = () => {
|
|
resultsArr.map((item, key) => {
|
|
const resultItem = resultsArr[key];
|
|
let detailsObj = jsonpath({
|
|
path:
|
|
"$" +
|
|
getJsonPathPrefix() +
|
|
'[?(@ && @.pinswg_name=="' +
|
|
getJsonPathName(item) +
|
|
'")]',
|
|
json: searchDetailsObj,
|
|
eval: true
|
|
});
|
|
detailsObj = detailsObj[0];
|
|
|
|
//console.log(searchDetailsObj[key]);
|
|
|
|
// searchDetailsObj[key] =
|
|
// currentViewKey == "myRepresentations"
|
|
// ? searchDetailsObj[key].value[0]
|
|
// : searchDetailsObj[key];
|
|
|
|
//console.log(resultsArr[key]);
|
|
resultsRowArr.push(
|
|
<div className="govuk-summary-list__row" key={key}>
|
|
<dd className="govuk-summary-list__value govuk-!-font-size-16 govuk-!-padding-left-2">
|
|
{isMyCases &&
|
|
resultItem.pinswg_publishtoweb === false ? (
|
|
<>
|
|
<div className="cardModuleReference">
|
|
{resultItem.ticketnumber}{" "}
|
|
<b> {t("myportal:appeal-pending-label")}</b>
|
|
</div>
|
|
<span
|
|
className=" govuk-link govuk-link--no-underline "
|
|
style={{ cursor: "pointer" }}
|
|
onClick={() => {
|
|
confirm(
|
|
"Do you want to download a pdf copy of your appeal for " +
|
|
resultItem.ticketnumber
|
|
) &&
|
|
downloadPDF(
|
|
resultItem.incidentid,
|
|
resultItem.ticketnumber
|
|
);
|
|
}}
|
|
>
|
|
<img
|
|
src={
|
|
"/assets/images/documenttypes/pdf.png"
|
|
}
|
|
alt={resultItem.ticketnumber}
|
|
width={25}
|
|
height={25}
|
|
title={
|
|
"Download summary for " +
|
|
resultItem.ticketnumber
|
|
}
|
|
/>
|
|
</span>
|
|
</>
|
|
) : (
|
|
<>
|
|
<Link
|
|
href={getCaseLinkHref(item)}
|
|
onClick={() => handleCaseLinkClick(item)}
|
|
>
|
|
<span className="results-visually-hidden">
|
|
{t(
|
|
"search:searchresults-case-reference-label"
|
|
)}
|
|
:
|
|
</span>
|
|
{getReferenceLabel(item)}
|
|
</Link>
|
|
{isMyRepresentations && (
|
|
<>
|
|
<br />
|
|
<span>
|
|
{resultItem.representationType}
|
|
</span>
|
|
</>
|
|
)}
|
|
</>
|
|
)}
|
|
</dd>
|
|
|
|
<dd className="govuk-summary-list__value govuk-!-font-size-16">
|
|
<span className="results-visually-hidden">
|
|
{t("search:searchresults-site-address-label")}:
|
|
</span>
|
|
|
|
{/* Helper function to extract address lines based on current view and data */}
|
|
{[
|
|
"pinswg_siteaddressline1",
|
|
"pinswg_addressline1",
|
|
"pinswg_siteaddressline2",
|
|
"pinswg_addressline2",
|
|
"pinswg_siteaddresstown",
|
|
"pinswg_addresstown",
|
|
"pinswg_siteaddresscounty",
|
|
"pinswg_siteaddresspostcode",
|
|
"pinswg_postcode",
|
|
"pinswg_projectlocation"
|
|
].map((field, idx) => {
|
|
const isAwaitingSubmission =
|
|
currentViewKey === "awaitingSubmissionDetails";
|
|
const isMyRepresentations =
|
|
currentViewKey === "myRepresentations";
|
|
const searchValue = _.get(
|
|
searchDetailsObj,
|
|
`${key}.${field} `
|
|
);
|
|
const detailsValue = _.get(detailsObj, field);
|
|
|
|
// Determine the display value based on current view
|
|
const valueToDisplay =
|
|
(isAwaitingSubmission && searchValue) ||
|
|
(isMyRepresentations && searchValue) ||
|
|
detailsValue ||
|
|
"";
|
|
|
|
// Only render a line break if there is a valid value and it's not the last address part
|
|
const renderLineBreak = valueToDisplay && idx < 4; // Only insert <br> if it's not the last element
|
|
|
|
return (
|
|
<span key={`${field}-${idx}`}>
|
|
{valueToDisplay}
|
|
{renderLineBreak && <br />}
|
|
</span>
|
|
);
|
|
})}
|
|
</dd>
|
|
|
|
<dd className="govuk-summary-list__value govuk-!-font-size-16">
|
|
<span className="results-visually-hidden">
|
|
{isAwaitingSubmissionDetails
|
|
? t("search:searchresults-created-on-label")
|
|
: t("search:searchresults-applicant-label")}
|
|
</span>
|
|
{isAwaitingSubmissionDetails
|
|
? formatDates(item.createdon)
|
|
: hasOwn(detailsObj, [
|
|
"_pinswg_appellant_value@OData.Community.Display.V1.FormattedValue"
|
|
])
|
|
? detailsObj[
|
|
"_pinswg_appellant_value@OData.Community.Display.V1.FormattedValue"
|
|
]
|
|
: isMyRepresentations
|
|
? searchDetailsObj[key][
|
|
"_pinswg_appellant_value@OData.Community.Display.V1.FormattedValue"
|
|
]
|
|
: resultItem[
|
|
"_customerid_value@OData.Community.Display.V1.FormattedValue"
|
|
]}
|
|
</dd>
|
|
<dd className="govuk-summary-list__value govuk-!-font-size-16">
|
|
<span className="results-visually-hidden">
|
|
{t("search:searchresults-authority-label")}:
|
|
</span>
|
|
{isAwaitingSubmissionDetails &&
|
|
hasOwn(resultItem, "pinswg_lpaname")
|
|
? resolveCrmDisplayValue({
|
|
value: resultItem.pinswg_lpaname,
|
|
locale: router.locale,
|
|
translations: transLookup,
|
|
fallbackValue: "N/A"
|
|
})
|
|
: ""}
|
|
{hasOwn(resultItem, [
|
|
"_pinswg_associatedlpa_value@OData.Community.Display.V1.FormattedValue"
|
|
])
|
|
? resolveCrmDisplayValue({
|
|
value: resultItem[
|
|
"_pinswg_associatedlpa_value@OData.Community.Display.V1.FormattedValue"
|
|
],
|
|
locale: router.locale,
|
|
translations: transLookup,
|
|
fallbackValue: "N/A"
|
|
})
|
|
: ""}
|
|
{hasOwn(searchDetailsObj[key], [
|
|
"_pinswg_localplanningauthority_value@OData.Community.Display.V1.FormattedValue"
|
|
])
|
|
? resolveCrmDisplayValue({
|
|
value:
|
|
searchDetailsObj[key][
|
|
"_pinswg_localplanningauthority_value@OData.Community.Display.V1.FormattedValue"
|
|
] ||
|
|
searchDetailsObj[key]?.value[0][
|
|
"_pinswg_localplanningauthority_value@OData.Community.Display.V1.FormattedValue"
|
|
],
|
|
locale: router.locale,
|
|
translations: transLookup,
|
|
fallbackValue: isMyRepresentations
|
|
? searchDetailsObj[key].value
|
|
: searchDetailsObj[key].value[0][
|
|
"_pinswg_localplanningauthority_value@OData.Community.Display.V1.FormattedValue"
|
|
] || "N/A"
|
|
})
|
|
: ""}
|
|
{hasOwn(resultItem, [
|
|
"_pinswg_localplanningauthority_value@OData.Community.Display.V1.FormattedValue"
|
|
])
|
|
? resolveCrmDisplayValue({
|
|
value: resultItem[
|
|
"_pinswg_localplanningauthority_value@OData.Community.Display.V1.FormattedValue"
|
|
],
|
|
locale: router.locale,
|
|
translations: transLookup,
|
|
fallbackValue: isMyRepresentations
|
|
? ""
|
|
: "N/A"
|
|
})
|
|
: isMyRepresentations &&
|
|
router.locale === "cy" &&
|
|
resolveCrmDisplayValue({
|
|
value: searchDetailsObj[key][
|
|
"_pinswg_localplanningauthority_value@OData.Community.Display.V1.FormattedValue"
|
|
],
|
|
locale: router.locale,
|
|
translations: transLookup
|
|
})}
|
|
</dd>
|
|
<dd className="govuk-summary-list__value govuk-!-font-size-16">
|
|
<span className="results-visually-hidden">
|
|
{t("search:searchresults-case-type-label")}:
|
|
</span>
|
|
|
|
{isAwaitingSubmissionDetails
|
|
? resolveCrmDisplayValue({
|
|
value: getFormCollectionByID(
|
|
item.pinswg_appealcasetype
|
|
).value,
|
|
locale: router.locale,
|
|
translations: transLookup,
|
|
fallbackValue: "N/A"
|
|
})
|
|
: resolveCrmDisplayValue({
|
|
value: item[
|
|
"pinswg_appealcasetype@OData.Community.Display.V1.FormattedValue"
|
|
],
|
|
locale: router.locale,
|
|
translations: transLookup,
|
|
fallbackValue: isMyRepresentations
|
|
? ""
|
|
: "N/A"
|
|
})}
|
|
|
|
{isMyRepresentations &&
|
|
resolveCrmDisplayValue({
|
|
value: getFormCollectionByID(
|
|
searchDetailsObj[key].appealType
|
|
).value,
|
|
locale: router.locale,
|
|
translations: transLookup,
|
|
fallbackValue: getFormCollectionByID(
|
|
searchDetailsObj[key].appealType
|
|
).value
|
|
})}
|
|
{hasOwn(
|
|
searchDetailsObj[key],
|
|
"_pinswg_localplanningauthority_value@OData.Community.Display.V1.FormattedValue"
|
|
)}
|
|
</dd>
|
|
<dd className="govuk-summary-list__value govuk-!-font-size-16">
|
|
<span className="results-visually-hidden">
|
|
{isMyRepresentations
|
|
? "Created"
|
|
: t("search:searchresults-status-label")}
|
|
:
|
|
</span>
|
|
|
|
{isAwaitingSubmissionDetails
|
|
? router.locale === "cy"
|
|
? jsonpath({
|
|
path:
|
|
'$..[?(@ && @.statuscode=="' +
|
|
item.statuscode +
|
|
'")].value_cy',
|
|
json: transLookup,
|
|
eval: true
|
|
})
|
|
: jsonpath({
|
|
path:
|
|
'$..[?(@ && @.statuscode=="' +
|
|
item.statuscode +
|
|
'")].value',
|
|
json: transLookup,
|
|
eval: true
|
|
}) || "N/A"
|
|
: isMyRepresentations
|
|
? repRaisedDate(item.repfile_name) // ? router.locale == "cy"
|
|
: resolveCrmDisplayValue({
|
|
value: item[
|
|
"statuscode@OData.Community.Display.V1.FormattedValue"
|
|
],
|
|
locale: router.locale,
|
|
translations: transLookup,
|
|
fallbackValue: "N/A"
|
|
})}
|
|
</dd>
|
|
{isAwaitingSubmissionDetails && (
|
|
<dd className="govuk-summary-list__value govuk-!-font-size-16 ">
|
|
<button
|
|
title={t(
|
|
"case:do-you-want-to-delete-case-label"
|
|
)}
|
|
className=" cardModuleRemoveCase govuk-summary-list__actionLink"
|
|
onClick={() => {
|
|
confirm(
|
|
t(
|
|
"case:do-you-want-to-delete-case-label"
|
|
) +
|
|
item.ticketnumber +
|
|
"?\n" +
|
|
t(
|
|
"case:do-you-want-to-delete-case-disclaimer-label"
|
|
)
|
|
) &&
|
|
deleteCaseItem(
|
|
props.accountDetails.containerID,
|
|
item.ticketnumber
|
|
);
|
|
}}
|
|
>
|
|
—
|
|
</button>
|
|
</dd>
|
|
)}
|
|
{isMyRepresentations && (
|
|
<dd className="govuk-summary-list__value govuk-!-font-size-16 ">
|
|
<button
|
|
title={t(
|
|
"case:do-you-want-to-delete-rep-label"
|
|
)}
|
|
className=" cardModuleRemoveCase govuk-summary-list__actionLink "
|
|
onClick={() => {
|
|
confirm(
|
|
t(
|
|
"case:do-you-want-to-delete-case-label"
|
|
) +
|
|
item.pinswg_name +
|
|
"?\n" +
|
|
t(
|
|
"case:do-you-want-to-delete-case-disclaimer-label"
|
|
)
|
|
) &&
|
|
deleteRepItem(
|
|
props.accountDetails.containerID,
|
|
item.caseRef,
|
|
item.repfile_name
|
|
);
|
|
}}
|
|
>
|
|
—
|
|
</button>
|
|
</dd>
|
|
)}
|
|
|
|
{isWatchedCases && (
|
|
<dd className="govuk-summary-list__value govuk-!-font-size-14 govuk-summary-list__action">
|
|
<button
|
|
title={t("case:stop-watching-case-link")}
|
|
className=" cardModuleRemoveCase govuk-summary-list__actionLink watched_link"
|
|
onClick={() => {
|
|
confirm(
|
|
t(
|
|
"case:you-have-stopped-watching-label"
|
|
) +
|
|
item[
|
|
"_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue"
|
|
]
|
|
) &&
|
|
deleteItem(
|
|
item.pinswg_watchlistid,
|
|
"watchedCases"
|
|
);
|
|
}}
|
|
>
|
|
<span className="eye"></span>
|
|
</button>
|
|
{item.pinswg_emailnotifications === true ? (
|
|
<button
|
|
className="govuk-summary-list__actionLink mailLink watched_link"
|
|
title={t("common:unsubscribe-title-label")}
|
|
onClick={() => {
|
|
confirm(
|
|
t(
|
|
"case:summary-unsubscribe-mail-label "
|
|
) +
|
|
item.pinswg_title +
|
|
"?"
|
|
) &&
|
|
selectEmailNotifications(
|
|
props.accountDetails
|
|
.accountDetails
|
|
.emailaddress1,
|
|
props.accountDetails
|
|
.loggedinUserId,
|
|
item._pinswg_watchedcase_value,
|
|
item.pinswg_appealcasetype,
|
|
null
|
|
);
|
|
}}
|
|
>
|
|
<span className="mailicon icon"></span>
|
|
</button>
|
|
) : (
|
|
<button
|
|
className="govuk-summary-list__actionLink mailLink "
|
|
title={t("common:subscribe-title-label")}
|
|
onClick={() => {
|
|
confirm(
|
|
t(
|
|
"case:summary-subscribe-mail-label"
|
|
) +
|
|
item.pinswg_title +
|
|
"?"
|
|
) &&
|
|
selectEmailNotifications(
|
|
props.accountDetails
|
|
.accountDetails
|
|
.emailaddress1,
|
|
props.accountDetails
|
|
.loggedinUserId,
|
|
item._pinswg_watchedcase_value,
|
|
item.pinswg_appealcasetype,
|
|
true
|
|
);
|
|
}}
|
|
>
|
|
<span className="mailicon icon"></span>
|
|
</button>
|
|
)}
|
|
</dd>
|
|
)}
|
|
</div>
|
|
);
|
|
});
|
|
};
|
|
|
|
const sortDataBy = (whichField) => {
|
|
setOrderbyState(whichField);
|
|
setfieldSortState("asc");
|
|
|
|
getSearchPageResults(1, whichField, fieldSortState);
|
|
whichField === orderByState
|
|
? fieldSortState === "desc"
|
|
? setfieldSortState("asc")
|
|
: setfieldSortState("desc")
|
|
: setfieldSortState("asc");
|
|
//setCurrentPage(1);
|
|
//setShowSpinnerState(true);
|
|
};
|
|
|
|
const getSearchPageResults = (pageNumber, orderBy, fieldSort) => {
|
|
//console.log(advancedSearch, searchString, pageNumber);
|
|
//console.log(pageNumber, orderBy, fieldSort);
|
|
resultsArr.sort(dynamicSort(orderBy, fieldSort));
|
|
//console.log(resultsArr);
|
|
};
|
|
|
|
function dynamicSort(property, order) {
|
|
var sort_order = 1;
|
|
if (order === "desc") {
|
|
sort_order = -1;
|
|
}
|
|
return function (a, b) {
|
|
// a should come before b in the sorted order
|
|
if (a[property] < b[property]) {
|
|
return -1 * sort_order;
|
|
// a should come after b in the sorted order
|
|
} else if (a[property] > b[property]) {
|
|
return 1 * sort_order;
|
|
// a and b are the same
|
|
} else {
|
|
return 0 * sort_order;
|
|
}
|
|
};
|
|
}
|
|
|
|
const deleteCaseItem = (containerID, caseID) => {
|
|
let cookies = parseCookies();
|
|
//console.log("sssss", containerID, caseID);
|
|
|
|
deleteAwaitingSubmissionsFromBlob(containerID, caseID)
|
|
.then((data) => {
|
|
return data;
|
|
})
|
|
.then(() => {
|
|
getAwaitingSubmissionFromBlobProxy(containerID)
|
|
.then((data) => {
|
|
setAwaitingSubmissionFromBlob(data);
|
|
setAwaitingSubmissionDetails(data);
|
|
})
|
|
.then(() => {
|
|
setCurrentView({
|
|
"viewName": "Awaiting Submission",
|
|
"viewKey": "awaitingSubmissionDetails"
|
|
});
|
|
});
|
|
});
|
|
};
|
|
|
|
const deleteRepItem = (containerID, caseID, repfile) => {
|
|
let cookies = parseCookies();
|
|
//console.log("sssss", containerID, caseID, repfile);
|
|
|
|
deleteMyRepresentationsFromBlob(containerID, caseID, repfile)
|
|
.then((data) => {
|
|
return data;
|
|
})
|
|
.then(() => {
|
|
getRepsFromBlobProxy(containerID)
|
|
.then((data) => {
|
|
setMyRepresentations(data);
|
|
setMyRepresentationsDetails(data);
|
|
})
|
|
.catch((error) => {
|
|
consoleLogger(error);
|
|
res.status(400).json(error);
|
|
})
|
|
.then(() => {
|
|
setCurrentView({
|
|
"viewName": "My Representations",
|
|
"viewKey": "myRepresentations"
|
|
});
|
|
});
|
|
});
|
|
};
|
|
|
|
const deleteItem = (caseID, topThreeType) => {
|
|
let cookies = parseCookies();
|
|
//console.log("sssss", caseID, topThreeType);
|
|
topThreeType === "watchedCases" &&
|
|
deleteWatchedCases(caseID)
|
|
.then((data) => data)
|
|
.then(() => {
|
|
getWatchedCasesProxy(cookies.pinsUser).then((data) => {
|
|
let filteredWatchedCases =
|
|
splitWatchedCasesBySubmissionState(
|
|
data.value
|
|
).watchedCases;
|
|
(setWatchedCases(filteredWatchedCases),
|
|
getDetailsProxy(
|
|
filteredWatchedCases,
|
|
"myWatchedCases"
|
|
)
|
|
.then((data) => {
|
|
setWatchedCasesDetails(data);
|
|
})
|
|
.then(() => {
|
|
setCurrentView({
|
|
"viewName": "Watched Cases",
|
|
"viewKey": "watchedCases"
|
|
});
|
|
}));
|
|
});
|
|
});
|
|
};
|
|
|
|
const isEmailSignUp = (whichIncident) => {
|
|
let isEmail = jsonpath({
|
|
path:
|
|
"$[?(@ && @._pinswg_watchedcase_value=='" +
|
|
whichIncident +
|
|
"' && @.pinswg_emailnotifications==true)]",
|
|
|
|
json: resultsArr,
|
|
eval: true
|
|
});
|
|
return isEmail;
|
|
};
|
|
|
|
const selectEmailNotifications = (
|
|
emailaddress,
|
|
loggedInUser,
|
|
incidentID,
|
|
appealType,
|
|
updateEmailNotifications
|
|
) => {
|
|
let updateBody = {
|
|
"pinswg_WatchedCase@odata.bind": "/incidents(" + incidentID + ")",
|
|
"pinswg_Contact@odata.bind": "/contacts(" + loggedInUser + ")",
|
|
"pinswg_appealcasetype": appealType,
|
|
"pinswg_emailnotifications": updateEmailNotifications
|
|
};
|
|
|
|
console.log("Email signed up");
|
|
createWatchedCases(updateBody)
|
|
.then((data) => data)
|
|
.then(() => {
|
|
getWatchedCasesProxy(props.accountDetails.loggedinUserId).then(
|
|
(data) => {
|
|
data = splitWatchedCasesBySubmissionState(
|
|
data.value
|
|
).watchedCases;
|
|
|
|
data.value.sort(function compare(a, b) {
|
|
var dateA = new Date(a.createdon);
|
|
var dateB = new Date(b.createdon);
|
|
return dateB - dateA;
|
|
});
|
|
|
|
setWatchedCases(data);
|
|
getDetailsProxy(data, "myWatchedCases")
|
|
.then((data) => {
|
|
setWatchedCasesDetails(data);
|
|
})
|
|
.then(() => {
|
|
setCurrentView({
|
|
"viewName": "Watched Cases",
|
|
"viewKey": "watchedCases"
|
|
});
|
|
});
|
|
}
|
|
);
|
|
});
|
|
};
|
|
|
|
buildResultsRowArr();
|
|
return (
|
|
<>
|
|
<div className="govuk-grid-row">
|
|
<div className="govuk-grid-column-full">
|
|
<h1 className="govuk-heading-xl govuk-!-margin-bottom-7">
|
|
{getViewTitle()}
|
|
</h1>
|
|
|
|
{resultsRowArr.length === 0 ? (
|
|
<h3>There are no {getEmptyStateTitle()} records</h3>
|
|
) : (
|
|
<dl className="govuk-summary-list govuk-!-margin-bottom-9 results">
|
|
<div className="govuk-summary-list__row results-headings">
|
|
<dd className="govuk-summary-list__key govuk-!-font-size-16 results_wider govuk-!-padding-left-2">
|
|
<button
|
|
type="button"
|
|
onClick={() =>
|
|
sortDataBy(
|
|
getCaseReferenceSortField()
|
|
)
|
|
}
|
|
className={getSortButtonClass(
|
|
getCaseReferenceSortField()
|
|
)}
|
|
>
|
|
{t(
|
|
"search:searchresults-case-reference-label"
|
|
)}
|
|
</button>
|
|
</dd>
|
|
<dd className="govuk-summary-list__key govuk-!-font-size-16">
|
|
{t(
|
|
"search:searchresults-site-address-label"
|
|
)}
|
|
</dd>
|
|
{isAwaitingSubmissionDetails ? (
|
|
<dd className="govuk-summary-list__key govuk-!-font-size-16">
|
|
<button
|
|
type="button"
|
|
onClick={() =>
|
|
sortDataBy("createdon")
|
|
}
|
|
className={getSortButtonClass(
|
|
"createdon"
|
|
)}
|
|
>
|
|
{getApplicantOrCreatedHeading()}
|
|
</button>
|
|
</dd>
|
|
) : (
|
|
<dd className="govuk-summary-list__key govuk-!-font-size-16">
|
|
{getApplicantOrCreatedHeading()}
|
|
</dd>
|
|
)}
|
|
<dd className="govuk-summary-list__key govuk-!-font-size-16">
|
|
<button
|
|
type="button"
|
|
onClick={() =>
|
|
sortDataBy(getAuthoritySortField())
|
|
}
|
|
className={getSortButtonClass(
|
|
getAuthoritySortField()
|
|
)}
|
|
>
|
|
{t(
|
|
"search:searchresults-authority-label"
|
|
)}{" "}
|
|
</button>
|
|
</dd>
|
|
<dd className="govuk-summary-list__key govuk-!-font-size-16">
|
|
{!isAwaitingSubmissionDetails ? (
|
|
<button
|
|
type="button"
|
|
onClick={() =>
|
|
sortDataBy(
|
|
"pinswg_appealcasetype@OData.Community.Display.V1.FormattedValue"
|
|
)
|
|
}
|
|
className={getSortButtonClass(
|
|
"pinswg_appealcasetype@OData.Community.Display.V1.FormattedValue"
|
|
)}
|
|
>
|
|
{t(
|
|
"search:searchresults-case-type-label"
|
|
)}{" "}
|
|
</button>
|
|
) : (
|
|
t(
|
|
"search:searchresults-case-type-label"
|
|
)
|
|
)}{" "}
|
|
</dd>
|
|
<dd className="govuk-summary-list__key govuk-!-font-size-16">
|
|
{isMyRepresentations ? (
|
|
<button
|
|
type="button"
|
|
onClick={() =>
|
|
sortDataBy("createdDate")
|
|
}
|
|
className={getSortButtonClass(
|
|
"createdDate"
|
|
)}
|
|
>
|
|
Created{" "}
|
|
</button>
|
|
) : (
|
|
getStatusHeading()
|
|
)}
|
|
</dd>
|
|
|
|
{shouldShowActionColumn() && (
|
|
<dd className="govuk-summary-list__key govuk-!-font-size-16 govuk-summary-list__action"></dd>
|
|
)}
|
|
</div>
|
|
{showSpinnerState === true ? (
|
|
<div className="govuk-summary-list__row">
|
|
<div className="govuk-!-margin-top-9 govuk-!-margin-bottom-9 govuk-!-font-weight-bold govuk-!-font-size-20 ">
|
|
{t("common:spinner-fetching-data")}
|
|
<img
|
|
className="data-loading-icon"
|
|
src="/assets/images/loading.gif"
|
|
alt={
|
|
router.locale === "cy"
|
|
? "Nôl data"
|
|
: "Fetching data"
|
|
}
|
|
/>
|
|
</div>
|
|
</div>
|
|
) : (
|
|
resultsRowArr
|
|
)}
|
|
</dl>
|
|
)}
|
|
</div>
|
|
</div>
|
|
<div className="govuk-grid-row">
|
|
<div className="govuk-grid-column-full">
|
|
<div className="govuk-button-group">
|
|
<a
|
|
onClick={() => router.replace("/myportal")}
|
|
className="govuk-button"
|
|
>
|
|
Back
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</>
|
|
);
|
|
};
|
|
|
|
const mapStateToProps = (state) => {
|
|
return {
|
|
currentView: state.currentView,
|
|
accountDetails: state.accountDetails,
|
|
mySubmittedReps: state.myRepresentations.mySubmittedReps,
|
|
myRepresentations: state.myRepresentations
|
|
// search: state.search,
|
|
// searchResultsObj: state.searchResultsObj,
|
|
};
|
|
};
|
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
return {
|
|
setCurrentReference: (currentReference) => {
|
|
dispatch(setCurrentReference(currentReference));
|
|
},
|
|
setSearchResults: (searchResultsObj) => {
|
|
dispatch(setSearchResults(searchResultsObj));
|
|
},
|
|
setSearchDetails: (searchDetailsObj) => {
|
|
dispatch(setSearchDetails(searchDetailsObj));
|
|
},
|
|
setAwaitingSubmissionFromBlob: (awaitingSubmission) => {
|
|
dispatch(setAwaitingSubmissionFromBlob(awaitingSubmission));
|
|
},
|
|
setAwaitingSubmissionDetails: (awaitingSubmission) => {
|
|
dispatch(setAwaitingSubmissionDetails(awaitingSubmission));
|
|
},
|
|
setWatchedCases: (watchedCases) => {
|
|
dispatch(setWatchedCases(watchedCases));
|
|
},
|
|
setWatchedCasesDetails: (watchedCasesDetails) => {
|
|
dispatch(setWatchedCasesDetails(watchedCasesDetails));
|
|
},
|
|
setWatchedCasesDetails: (watchedCasesDetails) => {
|
|
dispatch(setWatchedCasesDetails(watchedCasesDetails));
|
|
},
|
|
setMyRepresentations: (myRepresentations) => {
|
|
dispatch(setMyRepresentations(myRepresentations));
|
|
},
|
|
setMyRepresentationsDetails: (myRepresentationsDetails) => {
|
|
dispatch(setMyRepresentationsDetails(myRepresentationsDetails));
|
|
}
|
|
};
|
|
};
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(ViewAllResults);
|