import Link from "next/link"; import { useRouter } from "next/router"; import useTranslation from "next-translate/useTranslation"; import { setCurrentReference } from "../../store/currentView/action"; import { connect } from "react-redux"; import jsonpath from "jsonpath"; import transLookup from "../../data/lookuptranslations.json"; import { getFormCollectionByID } from "../../components/utils"; const ViewAllResults = (props) => { const { searchString, searchResultsObj, currentView, setCurrentReference, myportal, } = props; let { t } = useTranslation(); const router = useRouter(); const { locale } = router; var resultsArr = props[currentView.viewKey][currentView.viewKey].value || [ {}, ]; 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; } console.log( currentView.viewKey, props[currentView.viewKey], props[currentView.viewKey][currentView.viewKey].value ); var searchDetailsObj = props[currentView.viewKey][currentView.viewKey + "Details"] || {}; let resultsRowArr = []; resultsArr.map((item, key) => { let detailsObj = jsonpath.query( searchDetailsObj, '$..value[?(@.pinswg_name=="' + item.pinswg_title + '")]' ); detailsObj = detailsObj[0]; resultsRowArr.push(
{ setCurrentReference({ "currentReference": currentView.viewKey != "watchedCases" ? resultsArr[key].ticketnumber : resultsArr[key][ "_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue" ], "currentType": currentView.viewKey, "incidentid": currentView.viewKey != "watchedCases" ? resultsArr[key].incidentid : resultsArr[key][ "_pinswg_watchedcase_value" ], "appealType": resultsArr[key].pinswg_appealcasetype, }); }} > Case Reference: {currentView.viewKey != "watchedCases" ? resultsArr[key].ticketnumber : resultsArr[key][ "_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue" ]}
{t("search:searchresults-site-address-label")}: {/* {getFormCollectionByID(appealTypeID).PrimaryIdAttribute == "pinswg_dnsid" ? detailsObj.pinswg_projectlocation != null ? detailsObj.pinswg_projectlocation.indexOf(";") < 0 ? detailsObj.pinswg_projectlocation : router.locale == "cy" ? detailsObj.pinswg_projectlocation.split( ";" )[1] : detailsObj.pinswg_projectlocation.split( ";" )[0] : "" : ""} */} {_.has(detailsObj, "pinswg_siteaddressline1") ? detailsObj.pinswg_siteaddressline1 : ""} {/* {detailsObj.pinswg_siteaddressline1 != null &&
} */} {_.has(detailsObj, "pinswg_siteaddressline1") && detailsObj.pinswg_siteaddressline1 != null &&
} {_.has(detailsObj, "pinswg_siteaddressline1") ? detailsObj.pinswg_siteaddressline2 : ""} {_.has(detailsObj, "pinswg_siteaddressline2") && detailsObj.pinswg_siteaddressline2 != null &&
} {_.has(detailsObj, "pinswg_siteaddresstown") ? detailsObj.pinswg_siteaddresstown : ""} {_.has(detailsObj, "pinswg_siteaddresstown") && detailsObj.pinswg_siteaddresstown != null &&
} {_.has(detailsObj, "pinswg_siteaddresscounty") ? detailsObj.pinswg_siteaddresscounty : ""} {_.has(detailsObj, "pinswg_siteaddresscounty") && detailsObj.pinswg_siteaddresscounty != null &&
} {_.has(detailsObj, "pinswg_siteaddresspostcode") ? detailsObj.pinswg_siteaddresspostcode : ""}
{currentView.viewKey == "awaitingSubmission" ? "Created on" : t("search:searchresults-applicant-label")} {currentView.viewKey == "awaitingSubmission" ? formatDates(item.createdon) : _.has(detailsObj, [ "_pinswg_appellant_value@OData.Community.Display.V1.FormattedValue", ]) ? detailsObj[ "_pinswg_appellant_value@OData.Community.Display.V1.FormattedValue" ] : resultsArr[key][ "_customerid_value@OData.Community.Display.V1.FormattedValue" ]}
{t("search:searchresults-authority-label")}: {_.has(detailsObj, [ "_pinswg_associatedlpa_value@OData.Community.Display.V1.FormattedValue", ]) ? router.locale == "cy" ? jsonpath.query( transLookup, '$..[?(@.value=="' + item[ "_pinswg_associatedlpa_value@OData.Community.Display.V1.FormattedValue" ] + '")].value_cy' ) : detailsObj[ "_pinswg_associatedlpa_value@OData.Community.Display.V1.FormattedValue" ] || "N/A" : ""}
{t("search:searchresults-case-type-label")}: {router.locale == "cy" ? jsonpath.query( transLookup, '$..[?(@.value=="' + item[ "pinswg_appealcasetype@OData.Community.Display.V1.FormattedValue" ] + '")].value_cy' ) : item[ "pinswg_appealcasetype@OData.Community.Display.V1.FormattedValue" ] || "N/A"}
{t("search:searchresults-status-label")}: {router.locale == "cy" ? jsonpath.query( transLookup, '$..[?(@.value=="' + item[ "statuscode@OData.Community.Display.V1.FormattedValue" ] + '")].value_cy' ) : item[ "statuscode@OData.Community.Display.V1.FormattedValue" ] || "N/A"}
); }); return ( <>

{currentView.viewName}

{t("search:searchresults-case-reference-label")}
{t("search:searchresults-site-address-label")}
{currentView.viewKey == "awaitingSubmission" ? (
Created on
) : (
{t("search:searchresults-applicant-label")}
)}
{t("search:searchresults-authority-label")}
{t("search:searchresults-case-type-label")}
{t("search:searchresults-status-label")}
{resultsRowArr}
router.back()} className="govuk-button" > Back
); }; const mapDispatchToProps = (dispatch) => { return { setCurrentReference: (currentReference) => { dispatch(setCurrentReference(currentReference)); }, }; }; export default connect(null, mapDispatchToProps)(ViewAllResults);