Files
pedwfrontend/pages/myportal/dns/[developmentName].js
T
Robert Bond 9140476a2a Merged PR 2285: tweak to live link
tweak to live link

Related work items: #22423
2026-04-29 17:03:50 +00:00

304 lines
11 KiB
JavaScript

import { getSession } from "next-auth/react";
import useTranslation from "next-translate/useTranslation";
import Head from "next/head";
import { useRouter } from "next/router";
import { connect } from "react-redux";
import { getIP } from "../../../actions/core/logger";
import {
getPersonalAccount,
getPortalLogin
} from "../../../actions/services/accountService";
import {
getCaseMessage,
getSIPSEvents,
getSIPSMedia
} from "../../../actions/services/caseService";
import { getBasicDNSURLSearch } from "../../../actions/services/searchService";
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 } from "../../../store/accountDetails/action";
import { setCurrentReference } from "../../../store/currentView/action";
import { setSearch } from "../../../store/search/action";
import {
setEventDetails,
setSearchDetails,
setSearchResults,
setMediaDetails
} from "../../../store/searchOutput/action";
import { wrapper } from "../../../store/store";
import ServiceBanner from "../../../components/myportal/servicebanner";
const CaseHome = (props) => {
const {
footerLinks,
pages,
setSearchResults,
setSearchDetails,
searchResultsObj
} = props;
let { t, lang } = useTranslation();
const router = useRouter();
const { locale } = router;
const { developmentName } = router.query;
return (
<div>
<Head>
<title>
Reference:{" "}
{props.currentView.caseReference.currentReference ||
props.searchResultsObj.searchResultsObj.value[0]
.title}{" "}
Developments of National Significance
</title>
</Head>
<div id="page_wrapper">
<CookieBanner />
<Header serviceName="Developments of National Significance" />
<div className="govuk-width-container">
<Breadcrumbs slug={developmentName} props={props} />
<ServiceBanner props={props} />
<Case
props={props}
myCases={props.myCases.myCases}
myCasesDetails={props.myCases.myCasesDetails}
directSearchResultsObj={
props.searchResultsObj.searchResultsObj
}
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.searchResultsObj.searchResultsObj.value[0]
.caseReference
}
ticketnumber={
props.searchResultsObj.searchResultsObj.value[0]
.ticketnumber
}
currentType={props.currentType}
appealTypeID={
props.searchResultsObj.searchResultsObj.value[0]
.pinswg_appealcasetype
}
incidentid={
props.searchResultsObj.searchResultsObj.value[0]
.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.searchResultsObj.searchResultsObj.value[0]
.ticketnumber
}
/>
</div>
</div>
);
};
export const getServerSideProps = wrapper.getServerSideProps(
(store) => async (ctx) => {
const { query, req, res } = ctx;
getIP(req);
const { cookies } = req;
console.log(cookies);
console.log("the query", query.developmentName);
let thisSession = await getSession(ctx);
let loggedInUser = {};
if (thisSession) {
console.log(" has sesssion.......");
[loggedInUser] = await Promise.all([
await getPortalLogin(thisSession.user.email)
]);
loggedInUser = loggedInUser.value[0].contactid;
const accountDetails = await getPersonalAccount(loggedInUser);
store.dispatch(setAccountDetails(accountDetails));
} else {
console.log("not has sesssion.......");
}
let developmentQuery =
query.developmentName.indexOf("CAS-") == 0
? query.developmentName
: query.developmentName.split("-").join(" ");
console.log(developmentQuery);
const searchResultsObj = await getBasicDNSURLSearch(developmentQuery);
const searchDetailsObj = await getSearchDetails(searchResultsObj);
var eventsObj = {};
var 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));
}
// console.log(
// "\n======================================\n",
// searchResultsObj,
// "\n======================================\n"
// );
// console.log(
// "\n======================================\n",
// searchDetailsObj[0],
// "\n======================================\n"
// );
store.dispatch(setSearch(developmentQuery));
//console.log({
// "currentReference": searchResultsObj.value[0].title,
// "currentType": "searchResultsObj",
// "incidentid": searchResultsObj.value[0].incidentid,
// "appealType": searchResultsObj.value[0].pinswg_appealcasetype,
// });
console.log(
searchResultsObj["@odata.count"] > 1 ||
searchResultsObj["@odata.count"] < 1
);
if (searchResultsObj["@odata.count"] < 1) {
return {
redirect: {
destination: "/404",
permanent: false
}
};
} else {
if (searchResultsObj["@odata.count"] > 1) {
return {
redirect: {
//destination: "/dns-not-found",
destination: "/404",
permanent: false
}
};
} else {
// 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": true,
"specialistProcess":
searchDetailsObj[0].value[0]
.pinswg_speacialistcaseprocess != null ||
searchDetailsObj[0].value[0]
.pinswg_specialistcaseprocess != null
? searchDetailsObj[0].value[0]
.pinswg_speacialistcaseprocess ||
searchDetailsObj[0].value[0]
.pinswg_specialistcaseprocess
: ""
})
);
}
}
let messagesObj = await getCaseMessage(
searchResultsObj.value[0].incidentid
);
console.log(messagesObj);
return {
props: {
searchResultsObj: {
searchResultsObj: searchResultsObj,
searchDetailsObj: searchDetailsObj,
eventsObj: eventsObj,
mediaObj: mediaObj
},
currentType: "directResultsObj",
docsOffline: process.env.DOCAPI_OFFLINE || false,
messagesObj: messagesObj,
showFilteredDocs: process.env.SHOWFILTERDOCS || false,
showMaps: process.env.SHOWMAPS
}
};
}
);
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 {
setCurrentReference: (currentReference) => {
dispatch(setCurrentReference(refno));
},
setSearchResults: (searchResultsObj) => {
dispatch(setSearchResults(searchResultsObj));
},
setSearchDetails: (searchDetailsObj) => {
dispatch(setSearchDetails(searchDetailsObj));
}
};
};
export default connect(mapStateToProps, mapDispatchToProps)(CaseHome);