176 lines
6.4 KiB
JavaScript
176 lines
6.4 KiB
JavaScript
import useTranslation from "next-translate/useTranslation";
|
|
import Head from "next/head";
|
|
import { useRouter } from "next/router";
|
|
import { connect } from "react-redux";
|
|
import { getBasicDNSURLSearch } from "../../actions";
|
|
import CookieBanner from "../../components/cookieBanner";
|
|
import Footer from "../../components/footer";
|
|
import Header from "../../components/header";
|
|
import { getSearchDetails } from "../../components/utils";
|
|
import { setCurrentReference } from "../../store/currentView/action";
|
|
import { setSearch } from "../../store/search/action";
|
|
import {
|
|
setSearchDetails,
|
|
setSearchResults,
|
|
} from "../../store/searchOutput/action";
|
|
import { wrapper } from "../../store/store";
|
|
import Case from "../../components/case";
|
|
import Breadcrumbs from "../../components/breadcrumbs";
|
|
|
|
const CaseHome = (props) => {
|
|
const { footerLinks, pages } = props;
|
|
let { t, lang } = useTranslation();
|
|
|
|
const router = useRouter();
|
|
const { locale } = router;
|
|
const { developmentName } = router.query;
|
|
|
|
return (
|
|
<div>
|
|
<Head>
|
|
<title>
|
|
Reference:{" "}
|
|
{props.currentView.caseReference.currentReference}{" "}
|
|
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} />
|
|
|
|
<Case
|
|
props={props}
|
|
myCases={props.myCases.myCases}
|
|
myCasesDetails={props.myCases.myCasesDetails}
|
|
searchResultsObj={
|
|
props.searchResultsObj.searchResultsObj
|
|
}
|
|
searchDetailsObj={
|
|
props.searchResultsObj.searchDetailsObj
|
|
}
|
|
documentDetailsObj={
|
|
props.searchResultsObj.documentDetailsObj
|
|
}
|
|
myRepresentations={
|
|
props.myRepresentations.myRepresentations
|
|
}
|
|
watchedCases={props.watchedCases.watchedCases}
|
|
watchedCasesDetails={
|
|
props.watchedCases.watchedCasesDetails
|
|
}
|
|
awaitingSubmission={
|
|
props.awaitingSubmission.awaitingSubmission
|
|
}
|
|
caseReference={
|
|
props.currentView.caseReference.currentReference
|
|
}
|
|
currentType={
|
|
props.currentView.caseReference.currentType
|
|
}
|
|
appealTypeID={
|
|
props.currentView.caseReference.appealType
|
|
}
|
|
incidentid={props.currentView.caseReference.incidentid}
|
|
representationsObj={
|
|
props.searchResultsObj.representationsObj
|
|
}
|
|
/>
|
|
</div>
|
|
<Footer footerLinks={footerLinks} />
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export const getServerSideProps = wrapper.getServerSideProps(
|
|
(store) => async (ctx) => {
|
|
const { query, req, res } = ctx;
|
|
const { cookies } = req;
|
|
|
|
console.log(cookies);
|
|
console.log("the query", query.developmentName);
|
|
let loggedInUser = cookies.pinsUser;
|
|
|
|
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);
|
|
|
|
store.dispatch(setSearchResults(searchResultsObj));
|
|
store.dispatch(setSearchDetails(searchDetailsObj));
|
|
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(
|
|
setCurrentReference({
|
|
"currentReference": searchResultsObj.value[0].title,
|
|
"currentType": "searchResultsObj",
|
|
"incidentid": searchResultsObj.value[0].incidentid,
|
|
"appealType":
|
|
searchResultsObj.value[0].pinswg_appealcasetype,
|
|
})
|
|
);
|
|
}
|
|
}
|
|
// console.log(searchResultsObj);
|
|
}
|
|
);
|
|
|
|
const mapStateToProps = (state) => {
|
|
return {
|
|
currentView: state.currentView,
|
|
search: state.search,
|
|
searchResultsObj: state.searchResultsObj,
|
|
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);
|