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 EventsDetails from "./events"; import MediaDetails from "./media"; import { createWatchedCases, deleteWatchedCases, getWatchedCasesProxy, setCaseInvolvment } from "../../actions/services/portalService"; import { getLinkedCases } from "../../actions/services/searchService"; import { getPortalModuleDetailsProxy } from "../../actions/services/caseService"; 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 { getLivePublishedEvent, isEventLiveNow } from "./summary/utils/liveEvent"; import * as CaseTypes from "./summaryTypes"; // ✅ must match filename exactly import { capitalizeFirstLetter, formatDates, hasValidKey, isObjectNotEmpty, hasOwnPropertyAndNotNull, linkedCasesList, getBilingualText } from "./summary/utils/helpers"; import { isConsultationWindowOpen, isGeneralRepresentationWindowOpen, canShowRepButtonForAppealType, getEntryCtaLabelKey, shouldSuppressBlockedMessage, getGeneralBlockedEndDate, isRepresentationPeriodEnded } from "./summary/utils/representationEntry"; import { resolveSearchResultsHref, isDnsRoutePath } from "../../lib/routing/routeState"; import CaseNoticeBanner from "./caseNoticeBanner"; import WatchModal from "./watchmodal"; import EIADetails from "./eia"; import GoogleMapComponent from "../mapping"; import OSPoint from "ospoint"; 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; //let showLoginCheck = props.showLoginCheck; const { data: session, status } = useSession(); const [isModalOpen, setIsModalOpen] = useState(false); const [whichTab, setWhichTab] = useState("case-details"); 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 selectEmailNotifications = ( emailaddress, loggedInUser, incidentID, appealType ) => { let updateBody = { "pinswg_WatchedCase@odata.bind": "/incidents(" + incidentID + ")", "pinswg_Contact@odata.bind": "/contacts(" + loggedInUser + ")", "pinswg_appealcasetype": +appealType, "pinswg_emailnotifications": true }; console.log("Email signed up"); createWatchedCases(updateBody) .then((data) => data) .then(() => { getWatchedCasesProxy(props.accountDetails.loggedinUserId).then( (data) => { (setWatchedCases(data), getDetailsProxy(data, "myWatchedCases").then( (data) => { setWatchedCasesDetails(data); } )); } ); }); }; const isWatchedCase = (whichIncident) => { let isWatched = jsonpath({ path: "$..value[?(@ && @._pinswg_watchedcase_value=='" + whichIncident + "')]", json: watchedCases, eval: true }); return isWatched; }; const isEmailSignUp = (whichIncident) => { let isEmail = jsonpath({ path: "$..value[?(@ && @._pinswg_watchedcase_value=='" + whichIncident + "' && @.pinswg_emailnotifications==true)]", json: watchedCases, eval: true }); return isEmail; }; const deleteItem = (caseID, topThreeType) => { let cookies = parseCookies(); topThreeType == "watchedCases" && deleteWatchedCases(caseID) .then((data) => data) .then(() => { getWatchedCasesProxy(cookies.pinsUser).then((data) => { let showWatchedCases = (submittedArr) => { const required = submittedArr.value.filter((el) => { return ( el.pinswg_representationsubmitted == null ); }); let newObj = {}; return Object.assign(newObj, { "@odata.count": required.length, "value": required }); }; data = showWatchedCases(data); 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); } )); }); }); }; 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"; const hasEventsTabData = isObjectNotEmpty(props, "eventsObj") && Array.isArray(props.eventsObj?.value) && props.eventsObj.value.length > 0; const hasMediaTabData = isObjectNotEmpty(props, "mediaObj") && Array.isArray(props.mediaObj?.value) && props.mediaObj.value.length > 0; const livePublishedEvent = hasEventsTabData ? getLivePublishedEvent(props.eventsObj) : null; let point = {}; let siteCoords = {}; let center = {}; point = new OSPoint( detailsObj.pinswg_anticipatedgridreferencenorthingtext || detailsObj.pinswg_anticipatedgridrefnorthing, detailsObj.pinswg_anticipatedgridreferenceeastingtext || detailsObj.pinswg_anticipatedgridrefeasting ); siteCoords = point.toOSGB36(); //console.log(siteCoords); center = { id: "", lat: isNaN(parseFloat(siteCoords.latitude)) ? 52.412272 : parseFloat(siteCoords.latitude), lng: isNaN(parseFloat(siteCoords.longitude)) ? -3.437989 : parseFloat(siteCoords.longitude) }; const zoom = isNaN(parseFloat(siteCoords.latitude)) ? 7 : 12; const isDnsRoute = isDnsRoutePath(router.pathname); const searchHref = resolveSearchResultsHref({ query: router.query, hasSession: Boolean(session), includeViewAll: true, fallbackToMyPortalWhenNoFlags: true, isDnsRoute }); let showDetailsBlock = showDetails == true ? ( <>
A live streamed event is happening now.
{livePublishedEvent.pinswg_eventname && ({livePublishedEvent.pinswg_eventname}
)} Watch live stream
{t(
"case:representation-date-passed-label",
{
startDate:
formatDates(
detailsObj.pinswg_consultationopen
),
endDate:
formatDates(
detailsObj.pinswg_consultationclose
)
}
)}
{" "}
{t(
"case:representation-date-passed-additional-label"
)}{" "}
{t(
"home:login-contact-email"
)}
{t(
"case:representation-date-passed-label",
{
startDate:
formatDates(
detailsObj.pinswg_startdate
),
endDate:
props
.currentView
.caseReference
.appealType ==
846040019
? formatDates(
getGeneralBlockedEndDate(
detailsObj,
props
.currentView
.caseReference
.appealType
)
)
: formatDates(
getGeneralBlockedEndDate(
detailsObj,
props
.currentView
.caseReference
.appealType
)
)
}
)}
{" "}
{t(
"case:representation-date-passed-additional-label"
)}{" "}
{t(
"home:login-contact-email"
)}