183 lines
6.1 KiB
JavaScript
183 lines
6.1 KiB
JavaScript
import _ from "lodash";
|
|
import { useState } from "react";
|
|
import Head from "next/head";
|
|
import Header from "../components/header";
|
|
import Banner from "../components/banner";
|
|
import CookieBanner from "../components/cookieBanner";
|
|
import Breadcrumbs from "../components/breadcrumbs";
|
|
import Search from "../components/search";
|
|
import Footer from "../components/footer";
|
|
import Errorpage from "../components/errorpage";
|
|
import styles from "../styles/Home.module.css";
|
|
import { useSelector, shallowEqual, connect } from "react-redux";
|
|
import { wrapper } from "../store/store";
|
|
|
|
import { useRouter } from "next/router";
|
|
import useTranslation from "next-translate/useTranslation";
|
|
import CRMError from "../components/crmError";
|
|
|
|
import {
|
|
setAppealType,
|
|
setAppealTypeTitle,
|
|
setAppealTypeID,
|
|
setAppealLPA,
|
|
getAppealTypeObj,
|
|
} from "../store/appealType/action";
|
|
import {
|
|
getAppealsTypes,
|
|
getLPA,
|
|
updateCase,
|
|
createCase,
|
|
getToken,
|
|
} from "../actions";
|
|
import { setLPA } from "../store/lpa/action";
|
|
|
|
const Home = (props) => {
|
|
const { footerLinks, pages } = props;
|
|
let { t, lang } = useTranslation();
|
|
|
|
const router = useRouter();
|
|
const { locale } = router;
|
|
const { appealtypes } = router.query;
|
|
|
|
//console.log(props, props.LPAData);
|
|
var hasError =
|
|
_.has(props.LPAData.LPAData, "errorCode") ||
|
|
_.has(props.appealType.appealType, "errorCode")
|
|
? true
|
|
: false;
|
|
|
|
return (
|
|
<div>
|
|
<Head>
|
|
<title>
|
|
{t("search:page-title")} - {t("common:service-name")}
|
|
</title>
|
|
{/* Language by default is EN, if multilingual site this will need updated */}
|
|
<>
|
|
<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} />
|
|
{hasError ? (
|
|
<CRMError props={props} whichError="advancedSearch" />
|
|
) : (
|
|
<Search
|
|
lpadata={props.LPAData}
|
|
appealType={props.appealType}
|
|
/>
|
|
)}
|
|
</div>
|
|
<Footer footerLinks={footerLinks} />
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export const getServerSideProps = wrapper.getServerSideProps(
|
|
(store) =>
|
|
async ({ query, req, res }) => {
|
|
let token = await getToken();
|
|
|
|
var tokenIssuedAt = new Date();
|
|
var tokenExpiryTimeAt = new Date();
|
|
tokenExpiryTimeAt.setSeconds(
|
|
tokenExpiryTimeAt.getSeconds() + token.expires_in
|
|
);
|
|
|
|
console.log(
|
|
"token issued:",
|
|
tokenIssuedAt.toUTCString(),
|
|
"\n",
|
|
"token expires:",
|
|
tokenExpiryTimeAt.toUTCString()
|
|
);
|
|
console.log(token);
|
|
token = token.access_token;
|
|
|
|
const [appealTypeData, lpaData] = await Promise.all([
|
|
await getAppealsTypes(token),
|
|
await getLPA(token),
|
|
]);
|
|
|
|
store.dispatch(setAppealType(appealTypeData));
|
|
store.dispatch(setLPA(lpaData));
|
|
}
|
|
);
|
|
|
|
const mapStateToProps = (state) => {
|
|
return {
|
|
search: state.search,
|
|
searchResultsObj: state.searchResultsObj,
|
|
formData: state.formData,
|
|
appealType: state.appealType,
|
|
LPAData: state.LPAData,
|
|
//form: state.form,
|
|
accountDetails: state.accountDetails,
|
|
};
|
|
};
|
|
|
|
export default connect(mapStateToProps)(Home);
|