Files
pedwfrontend/pages/case/id/[incident].js
T

247 lines
9.0 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,
getIncidentbyID,
getPersonalAccount,
getPortalLogin,
} from "../../../actions";
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 {
getFormCollectionByID,
getSearchDetails,
} from "../../../components/utils";
import { setAccountDetails } from "../../../store/accountDetails/action";
import { setCurrentReference } from "../../../store/currentView/action";
import { setSearch } from "../../../store/search/action";
import { wrapper } from "../../../store/store";
const CaseHome = (props) => {
const { footerLinks, pages } = props;
let { t, lang } = useTranslation();
const router = useRouter();
const { locale } = router;
const { incident } = router.query;
return (
<div>
<Head>
<title>
Reference:{" "}
{props.currentView.caseReference.currentReference}{" "}
</title>
</Head>
<div id="page_wrapper">
<CookieBanner />
<Header serviceName="Developments of National Significance" />
<div className="govuk-width-container">
<Breadcrumbs slug={props.ticketnumber} props={props} />
<Case
props={props}
myCases={props.myCases.myCases}
myCasesDetails={props.myCases.myCasesDetails}
directSearchResultsObj={
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]
.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}
/>
</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.incident);
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.......");
}
const searchResultsObj = await getIncidentbyID(query.incident);
const searchDetailsObj = await getSearchDetails(searchResultsObj);
//console.log(
// "\n======================================\n",
// searchResultsObj,
// "\n======================================\n"
// );
//console.log(
// "\n======================================\n",
// searchDetailsObj[0],
// "\n======================================\n"
// );
var whichAppeal = getFormCollectionByID(
searchResultsObj.value[0].pinswg_appealcasetype
).LogicalName;
var defaultPostcode =
whichAppeal == "pinswg_ldps" ||
whichAppeal == "pinswg_harbourrevisionorders"
? "pinswg_postcode"
: whichAppeal == "pinswg_transportandworkacts" ||
whichAppeal == "pinswg_electricityacts" ||
whichAppeal == "pinswg_dnses"
? "pinswg_postcode"
: "pinswg_siteaddresspostcode";
var defaultFirstLineAddress =
whichAppeal == "pinswg_ldps" ||
whichAppeal == "pinswg_harbourrevisionorders"
? "pinswg_postcode"
: whichAppeal == "pinswg_transportandworkacts" ||
whichAppeal == "pinswg_electricityacts" ||
whichAppeal == "pinswg_dnses"
? "pinswg_addressline1"
: "pinswg_siteaddressline1";
store.dispatch(
req.headers.hasOwnProperty("referer")
? req.headers.referer.indexOf("?") > -1
? setSearch(req.headers.referer.split("?")[1])
: setSearch(
searchDetailsObj[0].value[0][defaultPostcode] == null
? "postcode=" +
searchDetailsObj[0].value[0][
defaultPostcode
]
: "addressline1=" +
searchDetailsObj[0].value[0][
defaultFirstLineAddress
]
)
: setSearch(
"postcode=" +
searchDetailsObj[0].value[0][defaultPostcode]
)
);
if (
searchResultsObj["@odata.count"] < 1 ||
searchResultsObj["@odata.count"] > 1
) {
return {
redirect: {
destination: "/404",
permanent: false,
},
};
} else {
store.dispatch(
setCurrentReference({
"ticketnumber": searchResultsObj.value[0].ticketnumber,
"currentReference": searchResultsObj.value[0].title,
"currentType": "searchResultsObj",
"incidentid": searchResultsObj.value[0].incidentid,
"appealType":
searchResultsObj.value[0].pinswg_appealcasetype,
})
);
}
return {
props: {
searchResultsObj: {
searchResultsObj: searchResultsObj,
searchDetailsObj: searchDetailsObj,
},
currentType: "directResultsObj",
docsOffline: process.env.DOCAPI_OFFLINE || false,
},
};
}
);
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));
},
};
};
export default connect(mapStateToProps, mapDispatchToProps)(CaseHome);