187 lines
6.6 KiB
JavaScript
187 lines
6.6 KiB
JavaScript
import useTranslation from "next-translate/useTranslation";
|
|
import Head from "next/head";
|
|
import { useRouter } from "next/router";
|
|
import { connect } from "react-redux";
|
|
import { getBasicSearch, getIP } from "../actions";
|
|
import Breadcrumbs from "../components/breadcrumbs";
|
|
import CookieBanner from "../components/cookieBanner";
|
|
import Footer from "../components/footer";
|
|
import Header from "../components/header";
|
|
import SearchResults from "../components/searchresults";
|
|
import { getSearchDetails } from "../components/utils";
|
|
import { setSearch } from "../store/search/action";
|
|
import {
|
|
setSearchDetails,
|
|
setSearchResults,
|
|
} from "../store/searchOutput/action";
|
|
import { setShowReps } from "../store/currentView/action";
|
|
import { wrapper } from "../store/store";
|
|
import _ from "lodash";
|
|
|
|
const Home = (props) => {
|
|
const { footerLinks, pages, isLinkedCase, showLoginCheck } = props;
|
|
let { t, lang } = useTranslation();
|
|
|
|
const router = useRouter();
|
|
const { locale } = router;
|
|
const { appealtypes } = router.query;
|
|
|
|
const pageTitle = isLinkedCase
|
|
? t("search:searchresults-title-label-linked-case") +
|
|
" - " +
|
|
t("common:service-name")
|
|
: t("search:page-title") + " - " + t("common:service-name");
|
|
|
|
return (
|
|
<div>
|
|
<Head>
|
|
<title>{pageTitle}</title>
|
|
<>
|
|
<link
|
|
rel="canonical"
|
|
href={t("common:gov-wales-link") + router.asPath}
|
|
/>
|
|
<meta
|
|
key="og:locale"
|
|
property="og:locale"
|
|
content={router.locale}
|
|
/>
|
|
{/* If they have a Twitter Handle, include the meta details below */}
|
|
<meta
|
|
key="og:site_name"
|
|
property="og:site_name"
|
|
content={t("common:service-name")}
|
|
/>
|
|
<meta
|
|
key="twitter:site"
|
|
property="twitter:site"
|
|
content="@UKGovWales"
|
|
/>
|
|
|
|
<meta
|
|
name="description"
|
|
content={t("common:service-description")}
|
|
/>
|
|
<meta
|
|
property="og:site_name"
|
|
content={t("common:gov-wales-label")}
|
|
/>
|
|
<meta
|
|
property="og:title"
|
|
content={t("search:page-title")}
|
|
/>
|
|
<meta
|
|
property="og:description"
|
|
content={t("common:service-description")}
|
|
/>
|
|
<meta property="og:type" content="website" />
|
|
<meta
|
|
property="og:url"
|
|
content={t("common:gov-wales-link")}
|
|
/>
|
|
<meta
|
|
property="og:image"
|
|
content="https://gov.wales/themes/custom/govwales/images/content/og-global-1200.png"
|
|
/>
|
|
<meta name="twitter:card" content="summary" />
|
|
<meta
|
|
name="twitter:title"
|
|
content={t("common:gov-wales-label")}
|
|
/>
|
|
<meta
|
|
name="twitter:url"
|
|
content={t("common:gov-wales-link") + router.asPath}
|
|
/>
|
|
<meta
|
|
name="twitter:image"
|
|
content="https://gov.wales/themes/custom/govwales/images/content/og-global-120.png"
|
|
/>
|
|
</>
|
|
</Head>
|
|
<div id="page_wrapper">
|
|
<CookieBanner />
|
|
<Header courseName={t("common:service-name")} />
|
|
<div className="govuk-width-container">
|
|
<Breadcrumbs slug={appealtypes} />
|
|
<SearchResults
|
|
searchString={props.search.searchString}
|
|
searchResultsObj={props.searchResultsObj}
|
|
isLinkedCase={isLinkedCase}
|
|
showLoginCheck={showLoginCheck}
|
|
/>
|
|
</div>
|
|
<Footer footerLinks={footerLinks} ticketnumber={props} />
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export const getServerSideProps = wrapper.getServerSideProps(
|
|
(store) => async (ctx) => {
|
|
const { query, req, res } = ctx;
|
|
getIP(req);
|
|
console.log("query-", query);
|
|
|
|
let isLinked =
|
|
typeof query.lk != "undefined" && query.lk == "1" ? true : false;
|
|
|
|
//console.log("is linked:", isLinked);
|
|
const showLoginCheck = process.env.SHOWLOGIN || false;
|
|
const showReps = process.env.SHOWREPRESENTATIONS || false;
|
|
store.dispatch(setShowReps(showReps, showLoginCheck));
|
|
|
|
let searchResultsObj = await getBasicSearch(query.q);
|
|
|
|
searchResultsObj =
|
|
searchResultsObj.status == 502
|
|
? {
|
|
value: [],
|
|
errorCode: searchResultsObj.status,
|
|
errorMsg: searchResultsObj.statusText,
|
|
}
|
|
: searchResultsObj;
|
|
|
|
if (_.has(searchResultsObj, "status") == true) {
|
|
return {
|
|
redirect: {
|
|
//destination: "/dns-not-found",
|
|
destination: "/error",
|
|
permanent: false,
|
|
},
|
|
};
|
|
} else {
|
|
const searchDetailsObj = await getSearchDetails(searchResultsObj);
|
|
|
|
store.dispatch(setSearchResults(searchResultsObj));
|
|
store.dispatch(setSearchDetails(searchDetailsObj));
|
|
store.dispatch(setSearch(query.q));
|
|
}
|
|
|
|
return {
|
|
props: {
|
|
isLinkedCase: isLinked,
|
|
showLoginCheck: showLoginCheck,
|
|
},
|
|
};
|
|
}
|
|
// }
|
|
// }
|
|
);
|
|
|
|
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);
|