114 lines
3.9 KiB
JavaScript
114 lines
3.9 KiB
JavaScript
import useTranslation from "next-translate/useTranslation";
|
|
import Head from "next/head";
|
|
import { useRouter } from "next/router";
|
|
import { connect } from "react-redux";
|
|
import { getDNSList } from "../../actions";
|
|
import CookieBanner from "../../components/cookieBanner";
|
|
import Main from "../../components/dns//main";
|
|
import Footer from "../../components/footer";
|
|
import Header from "../../components/header";
|
|
import { wrapper } from "../../store/store";
|
|
|
|
import _ from "lodash";
|
|
import Breadcrumbs from "../../components/breadcrumbs";
|
|
import { getSearchDetails } from "../../components/utils";
|
|
import { setSearch } from "../../store/search/action";
|
|
import {
|
|
setSearchDetails,
|
|
setSearchResults,
|
|
} from "../../store/searchOutput/action";
|
|
|
|
const Home = (props) => {
|
|
const { footerLinks, pages } = props;
|
|
let { t, lang } = useTranslation();
|
|
|
|
const router = useRouter();
|
|
const { locale } = router;
|
|
try {
|
|
return (
|
|
<div>
|
|
<Head>
|
|
<title>Developments of National Significance</title>
|
|
</Head>
|
|
<div id="page_wrapper">
|
|
<CookieBanner />
|
|
<Header serviceName="Developments of National Significance" />
|
|
<div className="govuk-width-container">
|
|
<Breadcrumbs />
|
|
<Main props={props} />
|
|
</div>
|
|
<Footer footerLinks={footerLinks} ticketnumber={props} />
|
|
</div>
|
|
</div>
|
|
);
|
|
} catch (e) {
|
|
console.log(e);
|
|
return <h1>oooops</h1>;
|
|
}
|
|
};
|
|
|
|
export const getServerSideProps = wrapper.getServerSideProps(
|
|
(store) =>
|
|
async ({ query, req, res }) => {
|
|
console.log("query-", query);
|
|
|
|
res.setHeader(
|
|
"Cache-Control",
|
|
"public, s-maxage=10, stale-while-revalidate=59"
|
|
);
|
|
|
|
let searchResultsObj = await getDNSList();
|
|
if (_.has(searchResultsObj, "status") != false) {
|
|
if (searchResultsObj.status == 400) {
|
|
return {
|
|
redirect: {
|
|
//destination: "/dns-not-found",
|
|
destination: "/error",
|
|
permanent: false,
|
|
},
|
|
};
|
|
} else {
|
|
searchResultsObj =
|
|
searchResultsObj.status == 502
|
|
? {
|
|
value: [],
|
|
errorCode: searchResultsObj.status,
|
|
errorMsg: searchResultsObj.statusText,
|
|
}
|
|
: searchResultsObj;
|
|
|
|
const searchDetailsObj = await getSearchDetails(
|
|
searchResultsObj
|
|
);
|
|
store.dispatch(setSearchResults(searchResultsObj));
|
|
store.dispatch(setSearchDetails(searchDetailsObj));
|
|
store.dispatch(setSearch("DNS"));
|
|
}
|
|
} else {
|
|
const searchDetailsObj = await getSearchDetails(
|
|
searchResultsObj
|
|
);
|
|
store.dispatch(setSearchResults(searchResultsObj));
|
|
store.dispatch(setSearchDetails(searchDetailsObj));
|
|
store.dispatch(setSearch("DNS"));
|
|
}
|
|
}
|
|
);
|
|
|
|
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,
|
|
};
|
|
};
|
|
|
|
export default connect(mapStateToProps)(Home);
|