Files
pedwfrontend/pages/newappeal/index.js
T
2024-06-05 19:50:56 +01:00

215 lines
7.4 KiB
JavaScript

import useTranslation from "next-translate/useTranslation";
import Head from "next/head";
import { getSession, useSession } from "next-auth/react";
import _ from "lodash";
import { useRouter } from "next/router";
import { connect } from "react-redux";
import {
getAppealsTypesForNewAppeal,
getLPA,
getPersonalAccount,
} from "../../actions";
import Breadcrumbs from "../../components/breadcrumbs";
import CookieBanner from "../../components/cookieBanner";
import Footer from "../../components/footer";
import Header from "../../components/header";
import CreateCase from "../../components/newappeal/createCase";
import {
setAccountDetails,
setContainerID,
setLoggedInUserId,
} from "../../store/accountDetails/action";
import { setAppealType } from "../../store/appealType/action";
import { setLPA } from "../../store/lpa/action";
import { wrapper } from "../../store/store";
import TimeOut from "../../components/timeout";
const Home = (props) => {
const { footerLinks, pages, formData, loggedInUserIdent } = props;
let { t, lang } = useTranslation();
const router = useRouter();
const { locale } = router;
const { appealtypes } = router.query;
const { appealType, LPAData } = props;
return (
<div>
<Head>
<title>
{t("newappeal:page-title")} - {t("common:service-name")}
</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("newappeal: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} />
<main
className="govuk-main-wrapper--auto-spacing"
id="main-content"
role="main"
>
<h1>{t("newappeal:page-title")}</h1>
<CreateCase
LPAData={props.LPAData}
appealType={props.setAppealType}
loggedInUser={props.accountDetails.loggedinUserId}
whichForm={props.form}
containerID={props.accountDetails.containerID}
/>
</main>
</div>
<Footer footerLinks={footerLinks} ticketnumber={props} />
</div>
<TimeOut />
</div>
);
};
export const getServerSideProps = wrapper.getServerSideProps(
(store) => async (ctx) => {
const { req, res } = ctx;
const { cookies } = req;
console.log(
"\n////////////////////////////\n",
"/newappeal - cookies ",
cookies,
"\n////////////////////////////\n"
);
let thisSession = await getSession(ctx);
//console.log("nextAuth Session:", thisSession);
// if (_.has(thisSession, "user") == false) {
// return {
// redirect: {
// destination: "/error",
// permanent: false,
// },
// };
// }
if (!thisSession) {
console.log("not has sesssion.......");
return {
redirect: {
destination: "/auth/signin",
permanent: false,
},
};
} else {
let loggedInUserIdent = thisSession.user.id;
let loggedInUser = cookies.pinsUser;
console.log("has loggedInUser", loggedInUser);
const [appealTypeData, lpaData, accountDetails] = await Promise.all(
[
await getAppealsTypesForNewAppeal(),
await getLPA(),
await getPersonalAccount(loggedInUser),
]
);
console.log(
"\n////////////////////////////\n Acccount Details:",
accountDetails,
"\n////////////////////////////\n"
);
//const lpaData = require("../../data/lpa.json");
//const appealTypeData = require("../../data/appealtypes.json");
store.dispatch(setAppealType(appealTypeData));
store.dispatch(setLPA(lpaData));
store.dispatch(setLoggedInUserId(loggedInUser));
store.dispatch(setAccountDetails(accountDetails));
store.dispatch(setContainerID(thisSession.user.id));
return {
props: { loggedInUserIdent: loggedInUserIdent },
};
}
}
);
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);