438 lines
15 KiB
JavaScript
438 lines
15 KiB
JavaScript
// import fs from "fs";
|
|
// import { JSONPath as jsonpath } from "jsonpath-plus";
|
|
// import useTranslation from "next-translate/useTranslation";
|
|
// import Head from "next/head";
|
|
// import { useRouter } from "next/router";
|
|
// import { useEffect } from "react";
|
|
// import { connect } from "react-redux";
|
|
// import xpath from "xpath";
|
|
// import {
|
|
// getAppealsTypesForNewAppeal,
|
|
// getIP,
|
|
// getMandatoryFields,
|
|
// getPickLists,
|
|
// getProgressFromBlob,
|
|
// getPersonalAccount,
|
|
// } from "../../actions";
|
|
// import Breadcrumbs from "../../components/breadcrumbs";
|
|
// import CookieBanner from "../../components/cookieBanner";
|
|
// import Footer from "../../components/footer";
|
|
// import Header from "../../components/header";
|
|
// import BuildCheckSection from "../../components/newappeal/buildchecksection";
|
|
// import BuildSection from "../../components/newappeal/buildsection";
|
|
// import CompleteAppeal from "../../components/newappeal/complete";
|
|
// import TimeOut from "../../components/timeout";
|
|
|
|
// import { getSession } from "next-auth/react";
|
|
// import {
|
|
// setContainerID,
|
|
// setLoggedInUserEmail,
|
|
// setLoggedInUserId,
|
|
// setAccountDetails,
|
|
// } from "../../store/accountDetails/action";
|
|
// import {
|
|
// setAppealLPA,
|
|
// setAppealType,
|
|
// setAppealTypeID,
|
|
// setAppealTypeTitle,
|
|
// setCaseReference,
|
|
// } from "../../store/appealType/action";
|
|
// import { setForm } from "../../store/formData/action";
|
|
// import { wrapper } from "../../store/store";
|
|
// import ServiceBanner from "../../components/myportal/servicebanner";
|
|
|
|
// let Home = (props) => {
|
|
// const { footerLinks, pages, formData } = props;
|
|
// let { t, lang } = useTranslation();
|
|
|
|
// const router = useRouter();
|
|
// const { locale } = router;
|
|
// const { appealtypes } = router.query;
|
|
|
|
// useEffect(() => {
|
|
// //setFormTitle(formTitle);
|
|
// setCaseReference(router.query.refno);
|
|
// }, []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
|
|
// const formXML = props.formData.formData;
|
|
// const parser = new DOMParser();
|
|
// var doc = parser.parseFromString(formXML, "text/xml");
|
|
// var titles = xpath.select(
|
|
// "//form/tabs/tab[*]/labels/label[@description]/@description",
|
|
// doc
|
|
// );
|
|
// var sectionCount = xpath.select("/form/tabs/tab[*]", doc);
|
|
// sectionCount = sectionCount.length;
|
|
|
|
// var tabs = xpath.select("//form/tabs/tab[*]", doc);
|
|
|
|
// let optionsStr = props.appealType.appealTypeOptions.value;
|
|
|
|
// let selectedObj = jsonpath({
|
|
// path: "$..[?(@ && @.attributevalue=='" + router.query.apt + "')]",
|
|
// json: optionsStr,
|
|
// eval: true,
|
|
// });
|
|
|
|
// //let optionsTitleObj = [];
|
|
|
|
// //const optionsTitleObj = selectedObj.reduce(
|
|
// // (obj, arrValue) => (
|
|
// // (obj[arrValue] = arrValue
|
|
// // .replace(/(\band|[\s\-\+\(\)\,\&])/g, "")
|
|
// // .toLowerCase()
|
|
// // .slice(0, 39)),
|
|
// // obj
|
|
// // ),
|
|
// // {}
|
|
// // );
|
|
|
|
// const formTitle = selectedObj[0].value;
|
|
|
|
// const { onSubmit } = 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 />
|
|
|
|
// <div className="govuk-width-container">
|
|
// <Breadcrumbs slug={appealtypes} formTitle={formTitle} />
|
|
// <ServiceBanner props={props} />
|
|
// <main
|
|
// className="govuk-main-wrapper--auto-spacing"
|
|
// id="main-content"
|
|
// role="main"
|
|
// >
|
|
// {props.appealType.currentSection == 9999 ? (
|
|
// <CompleteAppeal props={props} />
|
|
// ) : props.appealType.currentSection ==
|
|
// sectionCount + 1 ? (
|
|
// <BuildCheckSection
|
|
// formXML={formXML}
|
|
// sectionCount={sectionCount}
|
|
// onSubmit={onSubmit}
|
|
// formTitle={formTitle}
|
|
// appealType={props.appealType}
|
|
// props={props}
|
|
// key={1}
|
|
// mandatoryFieldsData={
|
|
// props.formData.mandatoryFieldsData
|
|
// }
|
|
// />
|
|
// ) : (
|
|
// <>
|
|
// <BuildSection
|
|
// formXML={formXML}
|
|
// sectionCount={sectionCount}
|
|
// onSubmit={onSubmit}
|
|
// formTitle={formTitle}
|
|
// mandatoryFieldsData={
|
|
// props.formData.mandatoryFieldsData
|
|
// }
|
|
// props={props}
|
|
// />
|
|
// </>
|
|
// )}
|
|
// </main>
|
|
// </div>
|
|
// <Footer footerLinks={footerLinks} ticketnumber={props} />
|
|
// </div>
|
|
// <TimeOut />
|
|
// </div>
|
|
// );
|
|
// };
|
|
|
|
// export const getServerSideProps = wrapper.getServerSideProps(
|
|
// (store) => async (ctx) => {
|
|
// const { query, req, res } = ctx;
|
|
// getIP(req);
|
|
// const { cookies } = req;
|
|
|
|
// console.log(cookies);
|
|
// console.log("the query", query);
|
|
// console.log("ref:", query.id);
|
|
// let loggedInUser = cookies.pinsUser;
|
|
|
|
// let thisSession = await getSession(ctx);
|
|
// //console.log("nextAuth Session:", thisSession);
|
|
|
|
// if (!thisSession) {
|
|
// console.log("not has sesssion.......");
|
|
// return {
|
|
// redirect: {
|
|
// destination: "/auth/signin",
|
|
// permanent: false,
|
|
// },
|
|
// };
|
|
// }
|
|
|
|
// let loggedInUserIdent = thisSession.user.id;
|
|
// let loggedInUserEmail = thisSession.user.email;
|
|
|
|
// console.log("logged ident:", loggedInUserIdent, loggedInUserEmail);
|
|
|
|
// const [
|
|
// appealTypeData,
|
|
// mandatoryFieldsData,
|
|
// pickListData,
|
|
// //blobList,
|
|
// ] = await Promise.all([
|
|
// await getAppealsTypesForNewAppeal(),
|
|
// await getMandatoryFields(query.appealtypes),
|
|
// await getPickLists(query.appealtypes),
|
|
|
|
// //await getFilesFromBlob(query.casereference),
|
|
// ]);
|
|
|
|
// const blobProgress = await getProgressFromBlob(
|
|
// loggedInUserIdent,
|
|
// query.id
|
|
// );
|
|
|
|
// const accountDetails = await getPersonalAccount(loggedInUser);
|
|
|
|
// console.log("anything here", loggedInUser, query.id, blobProgress);
|
|
|
|
// let caseReference = {};
|
|
|
|
// caseReference.ticketnumber = query.id;
|
|
// caseReference.incidentid = query.id;
|
|
// caseReference.caseDetails = blobProgress; //searchDetailsObj;
|
|
|
|
// var path = require("path");
|
|
// const configDirectory = path.resolve(process.cwd(), "data/formsxml");
|
|
// var xmlStr = fs.readFileSync(
|
|
// path.join(configDirectory, query.appealtypes + ".xml"),
|
|
// "utf8"
|
|
// );
|
|
// // xmlStr = formdata.value[0].formxml;
|
|
// xmlStr = xmlStr.replace(/\t/g, "");
|
|
// xmlStr = xmlStr.replace(/\n/g, "");
|
|
// xmlStr = xmlStr.replace(/> <"/g, "><");
|
|
// xmlStr = xmlStr.toString();
|
|
|
|
// store.dispatch(setLoggedInUserId(loggedInUser));
|
|
// store.dispatch(setLoggedInUserEmail(loggedInUserEmail));
|
|
// store.dispatch(setAppealLPA(query.lpa));
|
|
// store.dispatch(setAppealTypeID(query.apt));
|
|
// store.dispatch(setCaseReference(caseReference));
|
|
// store.dispatch(setForm(xmlStr, mandatoryFieldsData, pickListData));
|
|
// store.dispatch(setAppealType(appealTypeData));
|
|
// store.dispatch(setContainerID(thisSession.user.id));
|
|
// store.dispatch(setAccountDetails(accountDetails));
|
|
|
|
// //store.dispatch(setFilesForAppeal(blobList));
|
|
|
|
// return {
|
|
// props: { url: process.env.NEXTAUTH_URL },
|
|
// };
|
|
// }
|
|
// );
|
|
|
|
// const mapStateToProps = (state) => {
|
|
// return {
|
|
// search: state.search,
|
|
// searchResultsObj: state.searchResultsObj,
|
|
// formData: state.formData,
|
|
// appealType: state.appealType,
|
|
// form: state.form,
|
|
// accountDetails: state.accountDetails,
|
|
// };
|
|
// };
|
|
|
|
// const mapDispatchToProps = (dispatch) => {
|
|
// return {
|
|
// setFormTitle: (title) => {
|
|
// dispatch(setAppealTypeTitle(title));
|
|
// },
|
|
// setCaseReference: (refno) => {
|
|
// dispatch(setCaseReference(refno));
|
|
// },
|
|
// };
|
|
// };
|
|
|
|
// export default connect(mapStateToProps, mapDispatchToProps)(Home);
|
|
|
|
// pages/newappeal/[appealtypes].js
|
|
import { JSONPath as jsonpath } from "jsonpath-plus";
|
|
import xpath from "xpath";
|
|
import { useMemo } from "react";
|
|
import { connect } from "react-redux";
|
|
import { useRouter } from "next/router";
|
|
|
|
import { wrapper } from "../../store/store";
|
|
|
|
import NewAppealPageShell from "../../components/newappeal/newAppealPageShell";
|
|
import NewAppealFlow from "../../components/newappeal/newAppealFlow";
|
|
|
|
import { loadNewAppealPage } from "../../lib/newappeal/loadNewAppealPage";
|
|
import { hydrateNewAppealStore } from "../../lib/newappeal/hydrateNewAppealStore";
|
|
|
|
let Home = (props) => {
|
|
const { footerLinks } = props;
|
|
|
|
const router = useRouter();
|
|
const { appealtypes } = router.query;
|
|
|
|
const formXML = props.formData?.formData;
|
|
|
|
// Memoise XML parsing so it doesn't rerun on every render
|
|
const { sectionCount } = useMemo(() => {
|
|
if (!formXML) return { sectionCount: 0 };
|
|
|
|
const parser = new DOMParser();
|
|
const doc = parser.parseFromString(formXML, "text/xml");
|
|
const count = xpath.select("/form/tabs/tab[*]", doc)?.length || 0;
|
|
return { sectionCount: count };
|
|
}, [formXML]);
|
|
|
|
// Safely compute formTitle from appeal type options + apt
|
|
const formTitle = useMemo(() => {
|
|
const optionsStr = props.appealType?.appealTypeOptions?.value;
|
|
const apt = router.query.apt;
|
|
|
|
if (!optionsStr || !apt) return "New appeal";
|
|
|
|
const selectedObj = jsonpath({
|
|
path: "$..[?(@ && @.attributevalue=='" + apt + "')]",
|
|
json: optionsStr,
|
|
eval: true,
|
|
});
|
|
|
|
const title = selectedObj?.[0]?.value;
|
|
return title || "New appeal";
|
|
}, [props.appealType?.appealTypeOptions?.value, router.query.apt]);
|
|
|
|
const { onSubmit } = props;
|
|
|
|
return (
|
|
<NewAppealPageShell
|
|
appealtypes={appealtypes}
|
|
formTitle={formTitle}
|
|
footerLinks={footerLinks}
|
|
propsForFooter={props}
|
|
propsForServiceBanner={props}
|
|
>
|
|
<NewAppealFlow
|
|
formXML={formXML}
|
|
sectionCount={sectionCount}
|
|
currentSection={props.appealType?.currentSection}
|
|
onSubmit={onSubmit}
|
|
formTitle={formTitle}
|
|
mandatoryFieldsData={props.formData?.mandatoryFieldsData}
|
|
propsForChildren={props}
|
|
/>
|
|
</NewAppealPageShell>
|
|
);
|
|
};
|
|
|
|
export const getServerSideProps = wrapper.getServerSideProps(
|
|
(store) => async (ctx) => {
|
|
const result = await loadNewAppealPage(ctx);
|
|
|
|
if (result?.redirect) {
|
|
return { redirect: result.redirect };
|
|
}
|
|
|
|
// Hydrate Redux from one place
|
|
hydrateNewAppealStore(store, ctx.query, result);
|
|
|
|
return {
|
|
props: { url: process.env.NEXTAUTH_URL },
|
|
};
|
|
}
|
|
);
|
|
|
|
const mapStateToProps = (state) => {
|
|
return {
|
|
search: state.search,
|
|
searchResultsObj: state.searchResultsObj,
|
|
formData: state.formData,
|
|
appealType: state.appealType,
|
|
form: state.form,
|
|
accountDetails: state.accountDetails,
|
|
};
|
|
};
|
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
return {
|
|
// Keep as-is; you can clean these later once you confirm usage
|
|
setFormTitle: (title) => {
|
|
// dispatch(setAppealTypeTitle(title)); // optional later
|
|
},
|
|
setCaseReference: (refno) => {
|
|
// dispatch(setCaseReferenceAction(refno)); // optional later
|
|
},
|
|
};
|
|
};
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Home);
|