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 { useEffect, useState } from "react"; import { connect } from "react-redux"; import transLookup from "../../data/lookuptranslations.json"; import Documents from "./documents"; import { createWatchedCases, deleteWatchedCases, getLinkedCases, getPortalModuleDetailsProxy, getWatchedCasesProxy, setCaseInvolvment, } from "../../actions"; import { setCurrentLinkedCases, setCurrentReference, setCurrentView, } from "../../store/currentView/action"; import { setWatchedCases, setWatchedCasesDetails, } from "../../store/watchedCases/action"; import { signIn, useSession } from "next-auth/react"; import { destroyCookie, parseCookies, setCookie } from "nookies"; import { getFormCollectionByID, getDetailsProxy } from "../utils"; import Pinswg_advertsid from "./summaryTypes/pinswg_advertsid"; import Pinswg_callinss77id from "./summaryTypes/pinswg_callinss77id"; import Pinswg_commonlandid from "./summaryTypes/pinswg_commonlandid"; import Pinswg_communityinfrastructurelevyid from "./summaryTypes/pinswg_communityinfrastructurelevyid"; import Pinswg_compulsorypurchaseordersid from "./summaryTypes/pinswg_compulsorypurchaseordersid"; import Pinswg_dnsid from "./summaryTypes/pinswg_dnsid"; import Pinswg_electricityactid from "./summaryTypes/pinswg_electricityactid"; import Pinswg_enforcementlistedbuildingconseid from "./summaryTypes/pinswg_enforcementlistedbuildingconseid"; import Pinswg_enforcementnoticeappeals174id from "./summaryTypes/pinswg_enforcementnoticeappeals174id"; import Pinswg_environmentalpermittingid from "./summaryTypes/pinswg_environmentalpermittingid"; import Pinswg_harbourrevisionorderid from "./summaryTypes/pinswg_harbourrevisionorderid"; import Pinswg_hedgeshedgerowstreepreservatioid from "./summaryTypes/pinswg_hedgeshedgerowstreepreservatioid"; import Pinswg_householderappealhasid from "./summaryTypes/pinswg_householderappealhasid"; import Pinswg_lawfuldevelopmentcertificatappid from "./summaryTypes/pinswg_lawfuldevelopmentcertificatappid"; import Pinswg_ldpid from "./summaryTypes/pinswg_ldpid"; import Pinswg_listedbuildingandconservationrid from "./summaryTypes/pinswg_listedbuildingandconservationrid"; import Pinswg_maintenanceoflands217id from "./summaryTypes/pinswg_maintenanceoflands217id"; import Pinswg_miscellaneouscasewordid from "./summaryTypes/pinswg_miscellaneouscasewordid"; import Pinswg_nonvalidationid from "./summaryTypes/pinswg_nonvalidationid"; import Pinswg_planningappeals78id from "./summaryTypes/pinswg_planningappeals78id"; import Pinswg_planningconditionss73s79id from "./summaryTypes/pinswg_planningconditionss73s79id"; import Pinswg_planningobligationappeals106id from "./summaryTypes/pinswg_planningobligationappeals106id"; import Pinswg_rowid from "./summaryTypes/pinswg_rowid"; import Pinswg_transportandworkactid from "./summaryTypes/pinswg_transportandworkactid"; import Pinswg_wayleaveid from "./summaryTypes/pinswg_wayleaveid"; import CaseNoticeBanner from "./caseNoticeBanner"; import WatchModal from "./watchmodal"; const CaseSummary = (props) => { let { t } = useTranslation(); const router = useRouter(); const { locale } = router; const { appealTypeID, incidentid, caseReference, myCases, myRepresentations, watchedCases, awaitingSubmission, searchResultsObj, searchDetailsObj, directSearchResultsObj, currentType, setCurrentLinkedCases, linkedCasesReference, setCurrentReference, setWatchedCases, setWatchedCasesDetails, showMap, currentView, messagesObj, docsOffline, ticketnumber, } = props; const showLoginCheck = currentType == "directResultsObj" ? "true" : currentView.showLogin; const { data: session, status } = useSession(); const [isModalOpen, setIsModalOpen] = useState(false); const handleOpenModal = () => { setIsModalOpen(true); }; const handleCloseModal = () => { setIsModalOpen(false); }; const cookies = parseCookies(); const isLPA = props.accountDetails.accountDetails[ "pinswg_typeofinvolvement@OData.Community.Display.V1.FormattedValue" ] == "LPA" ? true : false; const selectWatchedCase = (loggedInUser, incidentID, appealType) => { let updateBody = { "pinswg_WatchedCase@odata.bind": "/incidents(" + incidentID + ")", "pinswg_Contact@odata.bind": "/contacts(" + loggedInUser + ")", "pinswg_appealcasetype": +appealType, }; createWatchedCases(updateBody) .then((data) => data) .then(() => { getWatchedCasesProxy(loggedInUser).then((data) => { setWatchedCases(data), getDetailsProxy(data, "myWatchedCases").then((data) => { setWatchedCasesDetails(data); }); }); }); setCaseInvolvment(incidentid, loggedInUser); }; const isWatchedCase = (whichIncident) => { let isWatched = jsonpath({ path: "$..value[?(@ && @._pinswg_watchedcase_value=='" + whichIncident + "')]", json: watchedCases, eval: true, }); return isWatched; }; const deleteItem = (caseID, topThreeType) => { let cookies = parseCookies(); topThreeType == "watchedCases" && deleteWatchedCases(caseID) .then((data) => data) .then(() => { getWatchedCasesProxy(cookies.pinsUser).then((data) => { setWatchedCases(data), getDetailsProxy(data, "myWatchedCases").then( (data) => { setWatchedCasesDetails(data); } ); }); }); }; const noRepresentationLink = ["/dnsdetails", "/dns/[developmentName]"]; let setCaseQueryObj = currentType == "directResultsObj" ? props.searchResultsObj : props[currentType]; let setCaseDetailsObj = currentType == "directResultsObj" ? props.searchDetailsObj : props[currentType + "Details"]; var casesObj = {}; currentType == "searchResultsObj" ? (casesObj = jsonpath({ path: '$..[?(@ && @.ticketnumber=="' + ticketnumber + '")]', json: searchResultsObj, eval: true, })) : currentType == "watchedCases" ? (casesObj = jsonpath({ path: '$..[?(@ && @.ticketnumber=="' + ticketnumber + '")]', json: setCaseQueryObj, eval: true, })) : currentType == "myCases" ? (casesObj = jsonpath({ path: '$..[?(@ && @.pinswg_title=="' + caseReference + '")]', json: setCaseQueryObj, eval: true, })) : currentType == "directResultsObj" ? (casesObj = jsonpath({ path: '$..[?(@ && @.ticketnumber=="' + ticketnumber + '")]', json: setCaseQueryObj, eval: true, })) : (casesObj = jsonpath({ path: '$..[?(@ && @.reference=="' + caseReference + '")]', json: setCaseQueryObj, eval: true, })); casesObj = Object.assign({}, ...casesObj); var detailsObj = {}; currentType == "searchResultsObj" ? (detailsObj = jsonpath({ path: '$..[?(@ && @.pinswg_name=="' + caseReference + '")]', json: searchDetailsObj, eval: true, })) : currentType == "directResultsObj" ? (detailsObj = setCaseDetailsObj[0].value[0]) : (detailsObj = jsonpath({ path: '$..[?(@ && @.pinswg_name=="' + caseReference + '")]', jsopn: setCaseDetailsObj, eval: true, })); detailsObj = typeof detailsObj == "object" ? detailsObj : detailsObj[0]; let showDetails = typeof detailsObj != "undefined" ? true : false; var timestamp = showDetails ? detailsObj.hasOwnProperty("pinswg_representation_period_end_date") ? Date.parse(detailsObj.pinswg_representation_period_end_date) : "n/a" : "n/a"; if (isNaN(timestamp) == false) { var d = new Date(timestamp); } let hasEndDate = typeof d != "undefined"; let showDetailsBlock = showDetails == true ? ( <>

{t("case:summary-reference-label")}:{" "} {currentType == "searchResultsObj" ? detailsObj.pinswg_name : currentType == "directResultsObj" ? casesObj.title : currentType == "watchedCases" ? casesObj.pinswg_title : casesObj.reference}

{props.messagesObj["@odata.count"] > 0 && ( )}
{getFormCollectionByID(appealTypeID) .PrimaryIdAttribute == "pinswg_dnsid" ? t("case:summary-applicantonly-label") : getFormCollectionByID(appealTypeID) .PrimaryIdAttribute == "pinswg_nonvalidationid" ? t("case:summary-appellantonly-label") : t("case:summary-applicant-label")}
{casesObj.pinswg_appellantagent == 846040001 ? casesObj.pinswg_appellantfirstname + " " + casesObj.pinswg_appellantlastname : detailsObj[ "_pinswg_appellant_value@OData.Community.Display.V1.FormattedValue" ] || "not entered"}
{detailsObj.pinswg_agentcontactname != null && (_.has( detailsObj, "pinswg_agentcontactname" ) ? (
{t("case:summary-agent-label")}
{_.has( detailsObj, "pinswg_agentcontactname" ) ? detailsObj.pinswg_agentcontactname : ""}
) : ( "" ))}
{t("case:summary-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 : ""} {_.has( detailsObj, "pinswg_siteaddressline1" ) && detailsObj.pinswg_siteaddressline1 != null &&
} {_.has( detailsObj, "pinswg_siteaddressline2" ) ? 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 : ""}
{casesObj.description != null && (
{t("case:summary-description-label")}
{casesObj.description.indexOf(";") < 0 ? casesObj.description : router.locale == "cy" ? casesObj.description.split(";")[1] : casesObj.description.split( ";" )[0]}
)} {detailsObj.pinswg_casestage != null && (
{t("case:summary-case-stage-label")}
{router.locale == "cy" ? jsonpath({ path: '$..[?(@ && @.value=="' + detailsObj[ "pinswg_casestage@OData.Community.Display.V1.FormattedValue" ] + '")].value_cy', json: transLookup, eval: true, }) : detailsObj[ "pinswg_casestage@OData.Community.Display.V1.FormattedValue" ] || t( "case:summary-no-date-entered-label" )}
)}
{t("case:summary-last-modified-label")}
{detailsObj.modifiedon > casesObj.modifiedon ? formatDates(detailsObj.modifiedon) : formatDates(casesObj.modifiedon)}
{showLoginCheck == "true" && ( <>
{(_.has(detailsObj, "pinswg_startdate") || _.has( detailsObj, "pinswg_applicationacceptedasvalid" ) || _.has( detailsObj, "pinswg_startdates" )) && showReps( detailsObj.pinswg_startdate || detailsObj.pinswg_startdates || detailsObj.pinswg_applicationacceptedasvalid, detailsObj.pinswg_finalcommentsduedate || detailsObj.pinswg_endofrepresentationperiod ) && ( <> {showRepButton( props.currentView .caseReference .appealType ) ? ( <> {t( "case:summary-make-representation-label" )} { //spinnerState(); router.back(); }} className="govuk-button govuk-button--secondary" > {t( "case:summary-back-button-label" )} ) : !isLPA && props.currentView .caseReference .appealType == 846040004 ? ( "" ) : ( <>

{t( "case:representation-date-passed-label", { startDate: formatDates( detailsObj.pinswg_startdate ), endDate: props .currentView .caseReference .appealType == 846040019 ? formatDates( detailsObj.pinswg_statementduedate ) : formatDates( detailsObj.pinswg_finalcommentsduedate ), } )}
{" "} {t( "case:representation-date-passed-additional-label" )}{" "} {t( "home:login-contact-email" )}

)} )}
{session && (isWatchedCase( props.currentView.caseReference .incidentid ).length > 0 == true ? ( ) : ( <> {/* */} ))} {!session && ( <> {/* */} )}
{_.has(detailsObj, "pinswg_startdate") && (detailsObj.pinswg_startdate != null || detailsObj.pinswg_finalcommentsduedate != null) && showRepsEnded( detailsObj.pinswg_startdate, detailsObj.pinswg_finalcommentsduedate ) && (
{t( "case:representation-period-ended-on-label" )} {props.currentView.caseReference .appealType == 846040019 ? formatDates( detailsObj.pinswg_statementduedate ) : formatDates( detailsObj.pinswg_finalcommentsduedate )}
)}
)} {showSummary(casesObj, detailsObj)} {/* */} ) : ( <>

{t("case:summary-no-details-label")}

{showLoginCheck == "true" && (
{noRepresentationLink.includes( router.pathname ) == true ? ( "" ) : ( {t( "case:summary-make-representation-label" )} )} { // spinnerState(); router.back(); }} className="govuk-button govuk-button--secondary" > {t("case:summary-back-button-label")}
)} ); function showSummary(casesObj, detailsObj) { let appealIDObj = getFormCollectionByID(appealTypeID).PrimaryIdAttribute; switch (appealIDObj) { case "pinswg_advertsid": return ( ); break; case "pinswg_callinss77id": return ( ); break; case "pinswg_commonlandid": return ( ); break; case "pinswg_communityinfrastructurelevyid": return ( ); break; case "pinswg_compulsorypurchaseordersid": return ( ); break; case "pinswg_dnsid": return ( ); break; case "pinswg_electricityactid": return ( ); break; case "pinswg_enforcementlistedbuildingconseid": return ( ); break; case "pinswg_enforcementnoticeappeals174id": return ( ); break; case "pinswg_enforcementpermittingid": return ( ); break; case "pinswg_harbourrevisionorderid": return ( ); break; case "pinswg_hedgeshedgerowstreepreservatioid": return ( ); break; case "pinswg_householderappealhasid": return ( ); break; case "pinswg_lawfuldevelopmentcertificatappid": return ( ); break; case "pinswg_ldpid": return ( ); break; case "pinswg_listedbuildingandconservationrid": return ( ); break; case "pinswg_maintenanceoflands217id": return ( ); break; case "pinswg_miscellaneouscasewordid": return ( ); break; case "pinswg_nonvalidationid": return ( ); break; case "pinswg_planningappeals78id": return ( ); break; case "pinswg_planningconditionss73s79id": return ( ); break; case "pinswg_planningobligationappeals106id": return ( ); break; case "pinswg_rowid": return ( ); break; case "pinswg_transportandworkactid": return ( ); break; case "pinswg_wayleaveid": return ( ); break; } } useEffect(() => { const linkCaseObj = async () => { let docObj = await getLinkedCases(incidentid).then((data) => { //console.log(data); setCurrentLinkedCases(data); return data; }); return linkCaseObj; }; const linkedCases = linkCaseObj(); }, [incidentid, setCurrentLinkedCases]); let now = new Date(); let expDate = new Date(now); expDate.setDate(now.getDate() + 365); function formatDates(dateObj, showTime) { 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(); var hh = dateObj.getHours(); hh = ("0" + hh).slice(-2); var mins = dateObj.getMinutes(); mins = ("0" + mins).slice(-2); const dateStr = showTime ? hh == 0 && mins == 0 ? "" : hh + ":" + mins : dd + "/" + mm + "/" + yyyy + " "; return dateStr; } function linkedCasesList(linkedCasesReference) { //console.log(linkedCasesReference); linkedCasesReference = linkedCasesReference.value || []; return ( <>
    {linkedCasesReference.map((item, key) => { return (
  • {item.title}
  • ); //console.log(item.incidentid, item.title); })}
); } function showReps(startDate, endDate) { let date = new Date(); date = new Date(date.toDateString()); const start = new Date(startDate); const end = new Date(endDate); return date >= start && date <= end ? true : false; } function showRepButton(appealType) { switch (appealType) { case 846040012: case 846040013: case 846040014: //for ROW case 846040015: case 846040020: case 846040021: case 846040023: case 846040024: return false; case 846040004: return isLPA ? true : false; case 846040015: return props.searchDetailsObj[0].value[0] .pinswg_specialistcaseprocess == 846040001 ? showReps( props.searchDetailsObj[0].value[0].pinswg_startdate, props.searchDetailsObj[0].value[0] .pinswg_finalcommentsduedate ) : true; case 846040018: let shouldShow = props.searchDetailsObj[0].value[0] .pinswg_speacialistcaseprocess == 846040000 && isLPA ? true : props.searchDetailsObj[0].value[0] .pinswg_speacialistcaseprocess == 846040001 ? true : false; return shouldShow; case 846040019: return showReps( props.searchDetailsObj[0].value[0].pinswg_startdate, props.searchDetailsObj[0].value[0].pinswg_statementduedate ); default: return true; } } function showRepsEnded(startDate, endDate) { let date = new Date(); date = new Date(date.toDateString()); const start = new Date(startDate); const end = new Date(endDate); return date > start && date > end ? true : false; } if (status == "authenticated" && cookies.pedwWatchCase != null) { selectWatchedCase( props.accountDetails.accountDetails.contactid, incidentid, appealTypeID ); destroyCookie({}, "pedwWatchCase", { path: "/" }); } return <>{showDetailsBlock}; }; const mapStateToProps = (state) => { return { accountDetails: state.accountDetails, currentView: state.currentView, search: state.search, // searchResultsObj: state.searchResultsObj, documentDetailsObj: state.searchResultsObj.documentDetailsObj, formData: state.formData, appealType: state.appealType, form: state.form, myCases: state.myCases, watchedCases: state.watchedCases, myRepresentations: state.myRepresentations, awaitingSubmission: state.awaitingSubmission, }; }; const mapDispatchToProps = (dispatch) => { return { setCurrentLinkedCases: (parentIncidentid) => { dispatch(setCurrentLinkedCases(parentIncidentid)); }, setCurrentReference: (currentReference) => { dispatch(setCurrentReference(currentReference)); }, setWatchedCases: (watchedCases) => { dispatch(setWatchedCases(watchedCases)); }, setWatchedCasesDetails: (watchedCasesDetails) => { dispatch(setWatchedCasesDetails(watchedCasesDetails)); }, setCurrentView: (currentView) => { dispatch(setCurrentView(currentView)); }, }; }; export default connect(mapStateToProps, mapDispatchToProps)(CaseSummary);