519 lines
20 KiB
JavaScript
519 lines
20 KiB
JavaScript
import useTranslation from "next-translate/useTranslation";
|
|
import Head from "next/head";
|
|
import { useRouter } from "next/router";
|
|
import { connect } from "react-redux";
|
|
import { consoleLogger, getIP } from "../../../actions/core/logger";
|
|
import {
|
|
getPersonalAccount,
|
|
getPortalLogin
|
|
} from "../../../actions/services/accountService";
|
|
import {
|
|
getCaseMessage,
|
|
getPortalModuleDetails,
|
|
getSIPSEvents,
|
|
getSIPSMedia
|
|
} from "../../../actions/services/caseService";
|
|
import { getRepsFromBlob } from "../../../actions/services/documentService";
|
|
import {
|
|
getMyCases,
|
|
getMyLPACases,
|
|
getWatchedCases
|
|
} from "../../../actions/services/portalService";
|
|
import { getBasicSearch } from "../../../actions/services/searchService";
|
|
import { getFormCollectionByID } from "../../../components/utils";
|
|
import { normalizeSpecialistProcess } from "../../../lib/domain/case-lifecycle";
|
|
import { getSession } from "next-auth/react";
|
|
import Breadcrumbs from "../../../components/breadcrumbs";
|
|
import Case from "../../../components/case";
|
|
import CookieBanner from "../../../components/cookieBanner";
|
|
import Footer from "../../../components/footer";
|
|
import Header from "../../../components/header";
|
|
import { getSearchDetails } from "../../../components/utils";
|
|
import {
|
|
setAccountDetails,
|
|
setContainerID,
|
|
setLoggedInUserId
|
|
} from "../../../store/accountDetails/action";
|
|
import {
|
|
setCurrentReference,
|
|
setCurrentView
|
|
} from "../../../store/currentView/action";
|
|
import { setMyCases, setMyCasesDetails } from "../../../store/myCases/action";
|
|
import {
|
|
setMyRepresentations,
|
|
setMyRepresentationsDetails,
|
|
setMySubmittedReps,
|
|
setMySubmittedRepsDetails
|
|
} from "../../../store/myRepresentations/action";
|
|
import { setSearch } from "../../../store/search/action";
|
|
import {
|
|
setSearchDetails,
|
|
setSearchResults,
|
|
setEventDetails,
|
|
setMediaDetails
|
|
} from "../../../store/searchOutput/action";
|
|
import { wrapper } from "../../../store/store";
|
|
import {
|
|
setWatchedCases,
|
|
setWatchedCasesDetails
|
|
} from "../../../store/watchedCases/action";
|
|
import ServiceBanner from "../../../components/myportal/servicebanner";
|
|
import TimeOut from "../../../components/timeout";
|
|
|
|
const CaseHome = (props) => {
|
|
const { footerLinks } = props;
|
|
useTranslation();
|
|
|
|
const router = useRouter();
|
|
const { ticketnumber } = router.query;
|
|
|
|
return (
|
|
<div>
|
|
<Head>
|
|
<title>
|
|
Reference:{" "}
|
|
{props.currentView.caseReference.currentReference ||
|
|
props.searchResultsObj.searchResultsObj.value[0]
|
|
.title}{" "}
|
|
</title>
|
|
</Head>
|
|
<div id="page_wrapper">
|
|
<CookieBanner />
|
|
<Header serviceName="Developments of National Significance" />
|
|
<div className="govuk-width-container">
|
|
<Breadcrumbs slug={ticketnumber} props={props} />
|
|
<ServiceBanner props={props} />
|
|
<Case
|
|
props={props}
|
|
myCases={props.myCases.myCases}
|
|
myCasesDetails={props.myCases.myCasesDetails}
|
|
searchResultsObj={
|
|
props.searchResultsObj.searchResultsObj
|
|
}
|
|
searchDetailsObj={
|
|
props.searchResultsObj.searchDetailsObj
|
|
}
|
|
documentDetailsObj={props.documentDetailsObj}
|
|
myRepresentations={
|
|
props.myRepresentations.myRepresentations
|
|
}
|
|
watchedCases={props.watchedCases.watchedCases}
|
|
watchedCasesDetails={
|
|
props.watchedCases.watchedCasesDetails
|
|
}
|
|
awaitingSubmission={
|
|
props.awaitingSubmission.awaitingSubmission
|
|
}
|
|
caseReference={
|
|
props.currentView.caseReference.currentReference
|
|
}
|
|
ticketnumber={
|
|
props.currentView.caseReference.ticketnumber ||
|
|
router.query.ticketnumber
|
|
}
|
|
currentType={props.currentType}
|
|
appealTypeID={
|
|
props.currentView.caseReference.appealType
|
|
}
|
|
incidentid={props.currentView.caseReference.incidentid}
|
|
representationsObj={
|
|
props.searchResultsObj.representationsObj
|
|
}
|
|
showLoginCheck={true}
|
|
messagesObj={props.messagesObj}
|
|
showFilteredDocs={props.showFilteredDocs}
|
|
showMaps={props.showMaps}
|
|
eventsObj={props.searchResultsObj.eventsObj}
|
|
mediaObj={props.searchResultsObj.mediaObj}
|
|
/>
|
|
</div>
|
|
<Footer
|
|
footerLinks={footerLinks}
|
|
props={props}
|
|
ticketnumber={props.currentView.caseReference.ticketnumber}
|
|
/>
|
|
<TimeOut />
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export const getServerSideProps = wrapper.getServerSideProps(
|
|
(store) => async (ctx) => {
|
|
const { query, req } = ctx;
|
|
getIP(req);
|
|
|
|
consoleLogger({
|
|
name: "MyPortalCaseTicketLoaderStart",
|
|
message: "myportal case ticket loader invoked",
|
|
hasTicketNumber: !!query?.ticketnumber,
|
|
hasViewKey: Object.prototype.hasOwnProperty.call(query, "key")
|
|
});
|
|
|
|
const showLoginCheck = process.env.SHOWLOGIN || false;
|
|
const thisSession = await getSession(ctx);
|
|
let loggedInUser = {};
|
|
|
|
if (thisSession) {
|
|
loggedInUser = await getPortalLogin(thisSession.user.email);
|
|
|
|
loggedInUser = loggedInUser?.value?.[0]?.contactid;
|
|
if (!loggedInUser) {
|
|
consoleLogger({
|
|
name: "MyPortalCaseTicketMissingContact",
|
|
message:
|
|
"myportal case ticket loader missing CRM contact id; redirecting to signin",
|
|
hasSessionEmail: !!thisSession?.user?.email
|
|
});
|
|
return {
|
|
redirect: {
|
|
destination: "/auth/signin",
|
|
permanent: false
|
|
}
|
|
};
|
|
}
|
|
} else {
|
|
consoleLogger({
|
|
name: "MyPortalCaseTicketMissingSession",
|
|
message:
|
|
"myportal case ticket loader missing session; redirecting to signin"
|
|
});
|
|
return {
|
|
redirect: {
|
|
destination: "/auth/signin",
|
|
permanent: false
|
|
}
|
|
};
|
|
}
|
|
|
|
const accountDetails = await getPersonalAccount(loggedInUser);
|
|
|
|
const lpaid =
|
|
accountDetails[
|
|
"pinswg_contact_associatedlpa@OData.Community.Display.V1.FormattedValue"
|
|
];
|
|
|
|
store.dispatch(setContainerID(thisSession.user.id));
|
|
store.dispatch(setAccountDetails(accountDetails));
|
|
store.dispatch(setLoggedInUserId(loggedInUser));
|
|
|
|
const developmentQuery = query.ticketnumber;
|
|
|
|
const pattern = /CAS-\d{5}-[A-Z0-9]{6}/;
|
|
const match = query.ticketnumber.match(pattern);
|
|
|
|
if (!match) {
|
|
consoleLogger({
|
|
name: "MyPortalCaseTicketUnexpectedFormat",
|
|
message: "ticketnumber does not match CAS expected format",
|
|
hasTicketNumber: !!query?.ticketnumber
|
|
});
|
|
}
|
|
|
|
const searchResultsObj = await getBasicSearch(developmentQuery);
|
|
const searchDetailsObj = await getSearchDetails(searchResultsObj);
|
|
|
|
let eventsObj = {};
|
|
let mediaObj = {};
|
|
|
|
if (searchResultsObj.value[0].pinswg_appealcasetype == 846040002) {
|
|
eventsObj = await getSIPSEvents(
|
|
searchDetailsObj[0].value[0].pinswg_sipsid
|
|
);
|
|
store.dispatch(setEventDetails(eventsObj));
|
|
}
|
|
|
|
if (searchResultsObj.value[0].pinswg_appealcasetype == 846040002) {
|
|
mediaObj = await getSIPSMedia(searchResultsObj.value[0].incidentid);
|
|
|
|
store.dispatch(setMediaDetails(mediaObj));
|
|
}
|
|
|
|
store.dispatch(setSearch(developmentQuery));
|
|
|
|
if (searchResultsObj["@odata.count"] < 1) {
|
|
consoleLogger({
|
|
name: "MyPortalCaseTicketSearchNotFound",
|
|
message:
|
|
"myportal case ticket loader search count < 1; redirecting to 404",
|
|
ticketnumber: query?.ticketnumber
|
|
});
|
|
return {
|
|
redirect: {
|
|
destination: "/404",
|
|
permanent: false
|
|
}
|
|
};
|
|
} else {
|
|
if (searchResultsObj["@odata.count"] > 1) {
|
|
consoleLogger({
|
|
name: "MyPortalCaseTicketSearchAmbiguous",
|
|
message:
|
|
"myportal case ticket loader search count > 1; redirecting to 404",
|
|
ticketnumber: query?.ticketnumber,
|
|
count: searchResultsObj["@odata.count"]
|
|
});
|
|
return {
|
|
redirect: {
|
|
//destination: "/dns-not-found",
|
|
destination: "/404",
|
|
permanent: false
|
|
}
|
|
};
|
|
} else {
|
|
if (Object.prototype.hasOwnProperty.call(query, "key")) {
|
|
let whichViewKey = query.key;
|
|
|
|
switch (whichViewKey) {
|
|
case "awaitingSubmissionDetails":
|
|
store.dispatch(
|
|
setCurrentView({
|
|
"viewName": "Awaiting Submission",
|
|
"viewKey": "awaitingSubmissionDetails"
|
|
})
|
|
);
|
|
break;
|
|
case "watchedCases":
|
|
store.dispatch(
|
|
setCurrentView({
|
|
"viewName": "Watched Cases",
|
|
"viewKey": "watchedCases"
|
|
})
|
|
);
|
|
break;
|
|
case "myCases":
|
|
const myCases =
|
|
accountDetails.pinswg_typeofinvolvement ==
|
|
846040012
|
|
? await getMyLPACases(lpaid)
|
|
: await getMyCases(loggedInUser);
|
|
|
|
const myCasesDetails = await getDetails(
|
|
myCases,
|
|
"myCases"
|
|
);
|
|
store.dispatch(setMyCases(myCases));
|
|
store.dispatch(setMyCasesDetails(myCasesDetails));
|
|
store.dispatch(
|
|
setCurrentView({
|
|
"viewName": "My Cases",
|
|
"viewKey": "myCases"
|
|
})
|
|
);
|
|
break;
|
|
case "myRepresentations":
|
|
const myRepresentations = await getRepsFromBlob(
|
|
thisSession.user.id
|
|
);
|
|
|
|
const myRepresentationsDetails = await getDetails(
|
|
myRepresentations,
|
|
"myRepresentations"
|
|
);
|
|
|
|
store.dispatch(
|
|
setMyRepresentations(myRepresentations)
|
|
);
|
|
store.dispatch(
|
|
setMyRepresentationsDetails(
|
|
myRepresentationsDetails
|
|
)
|
|
);
|
|
store.dispatch(
|
|
setCurrentView({
|
|
"viewName": "My Representations",
|
|
"viewKey": "myRepresentations"
|
|
})
|
|
);
|
|
|
|
default:
|
|
// code block
|
|
}
|
|
}
|
|
const watchedCases = await getWatchedCases(loggedInUser);
|
|
|
|
const showWatchedCases = (submittedArr) => {
|
|
const required = submittedArr.value.filter((el) => {
|
|
return el.pinswg_representationsubmitted == null;
|
|
});
|
|
|
|
const newObj = {};
|
|
return Object.assign(newObj, {
|
|
"@odata.count": required.length,
|
|
"value": required
|
|
});
|
|
};
|
|
|
|
const filteredWatchedCases = showWatchedCases(watchedCases);
|
|
|
|
const watchedCasesDetails = await getDetails(
|
|
filteredWatchedCases,
|
|
"myWatchedCases"
|
|
);
|
|
|
|
store.dispatch(setWatchedCases(filteredWatchedCases));
|
|
store.dispatch(setWatchedCasesDetails(watchedCasesDetails));
|
|
store.dispatch(setSearchResults(searchResultsObj));
|
|
store.dispatch(setSearchDetails(searchDetailsObj));
|
|
store.dispatch(
|
|
setCurrentReference({
|
|
"statuscode": searchResultsObj.value[0].statuscode,
|
|
"ticketnumber": searchResultsObj.value[0].ticketnumber,
|
|
"currentReference": searchResultsObj.value[0].title,
|
|
"currentType": "searchResultsObj",
|
|
"incidentid": searchResultsObj.value[0].incidentid,
|
|
"appealType":
|
|
searchResultsObj.value[0].pinswg_appealcasetype,
|
|
"showLoginCheck": showLoginCheck,
|
|
"appellant":
|
|
searchResultsObj?.value[0].customerid_contact
|
|
?.emailaddress1,
|
|
"specialistProcess": normalizeSpecialistProcess(
|
|
searchDetailsObj[0].value[0]
|
|
)
|
|
})
|
|
);
|
|
|
|
const mySubmittedReps = watchedCases.value.filter(
|
|
(el) => el.pinswg_representationsubmitted != null
|
|
);
|
|
|
|
const mySubmittedRepsDetails = await getDetails(
|
|
mySubmittedReps,
|
|
"mySubmittedReps"
|
|
);
|
|
|
|
store.dispatch(setMySubmittedReps(mySubmittedReps));
|
|
store.dispatch(
|
|
setMySubmittedRepsDetails(mySubmittedRepsDetails)
|
|
);
|
|
}
|
|
}
|
|
return {
|
|
props: {
|
|
searchResultsObj: {
|
|
searchResultsObj: searchResultsObj,
|
|
searchDetailsObj: searchDetailsObj,
|
|
eventsObj: eventsObj,
|
|
mediaObj: mediaObj
|
|
},
|
|
currentType: "directResultsObj",
|
|
docsOffline: process.env.DOCAPI_OFFLINE || false,
|
|
messagesObj: await getCaseMessage(
|
|
searchResultsObj.value[0].incidentid
|
|
),
|
|
showFilteredDocs: process.env.SHOWFILTERDOCS || false,
|
|
showMaps: process.env.SHOWMAPS
|
|
}
|
|
};
|
|
}
|
|
);
|
|
|
|
const getDetails = (resultsObj, detailsType) => {
|
|
let detailsArr = [];
|
|
|
|
resultsObj =
|
|
detailsType == "mySubmittedReps" ? resultsObj : resultsObj.value;
|
|
|
|
if (detailsType == "myRepresentations") {
|
|
resultsObj.map((searchDetail) => {
|
|
detailsArr.push(
|
|
getCase(searchDetail["incidentID"]).then((data) => {
|
|
let caseID = "";
|
|
|
|
switch (detailsType) {
|
|
case "myCases":
|
|
caseID = data.pinswg_title;
|
|
break;
|
|
case "mySubmittedReps":
|
|
caseID =
|
|
data[
|
|
"_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue"
|
|
];
|
|
break;
|
|
case "awaitingSubmission":
|
|
case "myWatchedCases":
|
|
case "myRepresentations":
|
|
caseID = data.ticketnumber;
|
|
break;
|
|
default:
|
|
caseID = data.pinswg_title;
|
|
}
|
|
return getPortalModuleDetails(
|
|
getFormCollectionByID(data.pinswg_appealcasetype)
|
|
.LogicalCollectionName,
|
|
caseID
|
|
);
|
|
})
|
|
);
|
|
});
|
|
}
|
|
|
|
resultsObj.map((searchDetail) => {
|
|
let caseID = "";
|
|
|
|
switch (detailsType) {
|
|
case "myCases":
|
|
caseID = searchDetail.pinswg_title;
|
|
break;
|
|
case "myWatchedCases":
|
|
case "mySubmittedReps":
|
|
caseID =
|
|
searchDetail[
|
|
"_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue"
|
|
];
|
|
break;
|
|
case "awaitingSubmission":
|
|
caseID = searchDetail.ticketnumber;
|
|
break;
|
|
case "myRepresentations":
|
|
caseID = searchDetail.casereference;
|
|
break;
|
|
default:
|
|
caseID = searchDetail.pinswg_title;
|
|
}
|
|
|
|
searchDetail.pinswg_appealcasetype != null &&
|
|
detailsArr.push(
|
|
getPortalModuleDetails(
|
|
getFormCollectionByID(searchDetail.pinswg_appealcasetype)
|
|
.LogicalCollectionName,
|
|
caseID
|
|
)
|
|
);
|
|
});
|
|
|
|
const detArr = Promise.all(detailsArr);
|
|
return detArr;
|
|
};
|
|
|
|
const mapStateToProps = (state) => {
|
|
return {
|
|
accountDetails: state.accountDetails,
|
|
currentView: state.currentView,
|
|
search: state.search,
|
|
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,
|
|
mySubmittedReps: state.myRepresentations.mySubmittedReps
|
|
};
|
|
};
|
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
return {
|
|
setCurrentReference: (currentReference) => {
|
|
dispatch(setCurrentReference(refno));
|
|
},
|
|
setLoggedInUserId: (loggedInUser) => {
|
|
dispatch(setLoggedInUserId(loggedInUser));
|
|
}
|
|
};
|
|
};
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(CaseHome);
|