updated restriction to disallow partial reps and appeals from being submitted when not docapi
This commit is contained in:
+439
-326
@@ -1,345 +1,465 @@
|
||||
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,
|
||||
getAwaitingSubmissionFromBlob,
|
||||
getFilesFromBlob,
|
||||
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 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,
|
||||
// getAwaitingSubmissionFromBlob,
|
||||
// getFilesFromBlob,
|
||||
// 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,
|
||||
// setFilesForAppeal,
|
||||
// } from "../../store/appealType/action";
|
||||
// import {
|
||||
// setAwaitingSubmissionDetails,
|
||||
// setAwaitingSubmissionFromBlob,
|
||||
// } from "../../store/awaitingSubmission/action";
|
||||
// import { setCurrentView, setLocale } from "../../store/currentView/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.casereference);
|
||||
// }, []); // 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("the query", query);
|
||||
// let loggedInUser = cookies.pinsUser;
|
||||
|
||||
// let thisSession = await getSession(ctx);
|
||||
|
||||
// if (!thisSession) {
|
||||
// console.log("not has sesssion.......");
|
||||
// return {
|
||||
// redirect: {
|
||||
// destination: "/auth/signin",
|
||||
// permanent: false,
|
||||
// },
|
||||
// };
|
||||
// }
|
||||
|
||||
// console.log(ctx.locale);
|
||||
// store.dispatch(setLocale(ctx.locale));
|
||||
|
||||
// let loggedInUserIdent = thisSession.user.id;
|
||||
// let loggedInUserEmail = thisSession.user.email;
|
||||
|
||||
// //console.log("logged ident:", loggedInUserIdent);
|
||||
|
||||
// console.log("which appeal: ", query.appealtypes);
|
||||
|
||||
// const accountDetails = await getPersonalAccount(loggedInUser);
|
||||
|
||||
// const [appealTypeData, mandatoryFieldsData, pickListData, blobList] =
|
||||
// await Promise.all([
|
||||
// await getAppealsTypesForNewAppeal(),
|
||||
// await getMandatoryFields(query.appealtypes),
|
||||
// await getPickLists(query.appealtypes),
|
||||
// await getFilesFromBlob(loggedInUserIdent, query.casereference),
|
||||
// ]);
|
||||
|
||||
// const blobProgress = await getProgressFromBlob(
|
||||
// loggedInUserIdent,
|
||||
// query.casereference
|
||||
// );
|
||||
|
||||
// //console.log("/////////\nappeal type data:", appealTypeData);
|
||||
|
||||
// //
|
||||
// // Removed to make progress from Blob not CRM
|
||||
// //
|
||||
|
||||
// // let searchResultsObj = await getPartSavedAppeal(query.casereference);
|
||||
// // //console.log("eeee:", searchResultsObj);
|
||||
// // let searchDetailsObj = await getPartSavedDetails(searchResultsObj);
|
||||
|
||||
// // searchDetailsObj = searchDetailsObj[0].value[0];
|
||||
|
||||
// // Object.keys(searchDetailsObj).forEach((key) => {
|
||||
// // if (searchDetailsObj[key] === null) {
|
||||
// // delete searchDetailsObj[key];
|
||||
// // }
|
||||
// // });
|
||||
|
||||
// //console.log("appeal:", searchDetailsObj);
|
||||
|
||||
// // searchDetailsObj = JSON.stringify(searchDetailsObj);
|
||||
// // searchDetailsObj = searchDetailsObj.replace(/:true/gm, `:"Yes"`);
|
||||
// // searchDetailsObj = searchDetailsObj.replace(/:false/gm, `:"No"`);
|
||||
// // searchDetailsObj = JSON.parse(searchDetailsObj);
|
||||
|
||||
// let caseReference = {};
|
||||
|
||||
// caseReference.ticketnumber = query.casereference;
|
||||
// caseReference.incidentid = query.inid;
|
||||
// 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 = xmlStr.replace(/\t/g, "");
|
||||
// xmlStr = xmlStr.replace(/\n/g, "");
|
||||
// xmlStr = xmlStr.replace(/> <"/g, "><");
|
||||
// xmlStr = xmlStr.toString();
|
||||
|
||||
// if (query.hasOwnProperty("key")) {
|
||||
// const awaitingSubmissionFromBlob =
|
||||
// await getAwaitingSubmissionFromBlob(thisSession.user.id);
|
||||
|
||||
// store.dispatch(
|
||||
// setAwaitingSubmissionFromBlob(awaitingSubmissionFromBlob)
|
||||
// );
|
||||
|
||||
// store.dispatch(
|
||||
// setAwaitingSubmissionDetails(awaitingSubmissionFromBlob)
|
||||
// );
|
||||
// store.dispatch(
|
||||
// setCurrentView({
|
||||
// "viewName": "Awaiting Submission",
|
||||
// "viewKey": "awaitingSubmissionDetails",
|
||||
// })
|
||||
// );
|
||||
// }
|
||||
|
||||
// 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,
|
||||
// awaitingSubmission: state.awaitingSubmission,
|
||||
// currentView: state.currentView,
|
||||
// initialValues: state.appealType.caseReference.caseDetails,
|
||||
// };
|
||||
// };
|
||||
|
||||
// const mapDispatchToProps = (dispatch) => {
|
||||
// return {
|
||||
// setFormTitle: (title) => {
|
||||
// dispatch(setAppealTypeTitle(title));
|
||||
// },
|
||||
// setCaseReference: (refno) => {
|
||||
// dispatch(setCaseReference(refno));
|
||||
// },
|
||||
// setFilesForAppeal: (blobList) => {
|
||||
// dispatch(setFilesForAppeal(blobList));
|
||||
// },
|
||||
// };
|
||||
// };
|
||||
|
||||
// export default connect(mapStateToProps, mapDispatchToProps)(Home);
|
||||
|
||||
// pages/myportal/[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 { getSession } from "next-auth/react";
|
||||
import {
|
||||
setContainerID,
|
||||
setLoggedInUserEmail,
|
||||
setLoggedInUserId,
|
||||
setAccountDetails,
|
||||
} from "../../store/accountDetails/action";
|
||||
import {
|
||||
setAppealLPA,
|
||||
setAppealType,
|
||||
setAppealTypeID,
|
||||
setAppealTypeTitle,
|
||||
setCaseReference,
|
||||
setFilesForAppeal,
|
||||
} from "../../store/appealType/action";
|
||||
import {
|
||||
setAwaitingSubmissionDetails,
|
||||
setAwaitingSubmissionFromBlob,
|
||||
} from "../../store/awaitingSubmission/action";
|
||||
import { setCurrentView, setLocale } from "../../store/currentView/action";
|
||||
import { setForm } from "../../store/formData/action";
|
||||
import { wrapper } from "../../store/store";
|
||||
import ServiceBanner from "../../components/myportal/servicebanner";
|
||||
|
||||
import NewAppealPageShell from "../../components/newappeal/newAppealPageShell";
|
||||
import NewAppealFlow from "../../components/newappeal/newAppealFlow";
|
||||
|
||||
import { loadMyPortalAppealPage } from "../../lib/myportal/loadMyPortalAppealPage";
|
||||
import { hydrateMyPortalAppealStore } from "../../lib/myportal/hydrateMyPortalAppealStore";
|
||||
|
||||
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.casereference);
|
||||
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
const formXML = props.formData?.formData;
|
||||
|
||||
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;
|
||||
// Memoise XML parsing
|
||||
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]);
|
||||
|
||||
var tabs = xpath.select("//form/tabs/tab[*]", doc);
|
||||
// Safe formTitle resolution
|
||||
const formTitle = useMemo(() => {
|
||||
const optionsStr = props.appealType?.appealTypeOptions?.value;
|
||||
const apt = router.query.apt;
|
||||
|
||||
let optionsStr = props.appealType.appealTypeOptions.value || {};
|
||||
if (!optionsStr || !apt) return "New appeal";
|
||||
|
||||
let selectedObj = jsonpath({
|
||||
path: "$..[?(@ && @.attributevalue=='" + router.query.apt + "')]",
|
||||
json: optionsStr,
|
||||
eval: true,
|
||||
});
|
||||
const selectedObj = jsonpath({
|
||||
path: "$..[?(@ && @.attributevalue=='" + 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;
|
||||
return selectedObj?.[0]?.value || "New appeal";
|
||||
}, [props.appealType?.appealTypeOptions?.value, router.query.apt]);
|
||||
|
||||
const { footerLinks } = props;
|
||||
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>
|
||||
<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}
|
||||
docsOffline={props.docsOffline}
|
||||
/>
|
||||
</NewAppealPageShell>
|
||||
);
|
||||
};
|
||||
|
||||
export const getServerSideProps = wrapper.getServerSideProps(
|
||||
(store) => async (ctx) => {
|
||||
const { query, req, res } = ctx;
|
||||
getIP(req);
|
||||
const { cookies } = req;
|
||||
const result = await loadMyPortalAppealPage(ctx);
|
||||
|
||||
console.log("the query", query);
|
||||
let loggedInUser = cookies.pinsUser;
|
||||
|
||||
let thisSession = await getSession(ctx);
|
||||
|
||||
if (!thisSession) {
|
||||
console.log("not has sesssion.......");
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/auth/signin",
|
||||
permanent: false,
|
||||
},
|
||||
};
|
||||
if (result?.redirect) {
|
||||
return { redirect: result.redirect };
|
||||
}
|
||||
|
||||
console.log(ctx.locale);
|
||||
store.dispatch(setLocale(ctx.locale));
|
||||
|
||||
let loggedInUserIdent = thisSession.user.id;
|
||||
let loggedInUserEmail = thisSession.user.email;
|
||||
|
||||
//console.log("logged ident:", loggedInUserIdent);
|
||||
|
||||
console.log("which appeal: ", query.appealtypes);
|
||||
|
||||
const accountDetails = await getPersonalAccount(loggedInUser);
|
||||
|
||||
const [appealTypeData, mandatoryFieldsData, pickListData, blobList] =
|
||||
await Promise.all([
|
||||
await getAppealsTypesForNewAppeal(),
|
||||
await getMandatoryFields(query.appealtypes),
|
||||
await getPickLists(query.appealtypes),
|
||||
await getFilesFromBlob(loggedInUserIdent, query.casereference),
|
||||
]);
|
||||
|
||||
const blobProgress = await getProgressFromBlob(
|
||||
loggedInUserIdent,
|
||||
query.casereference
|
||||
);
|
||||
|
||||
//console.log("/////////\nappeal type data:", appealTypeData);
|
||||
|
||||
//
|
||||
// Removed to make progress from Blob not CRM
|
||||
//
|
||||
|
||||
// let searchResultsObj = await getPartSavedAppeal(query.casereference);
|
||||
// //console.log("eeee:", searchResultsObj);
|
||||
// let searchDetailsObj = await getPartSavedDetails(searchResultsObj);
|
||||
|
||||
// searchDetailsObj = searchDetailsObj[0].value[0];
|
||||
|
||||
// Object.keys(searchDetailsObj).forEach((key) => {
|
||||
// if (searchDetailsObj[key] === null) {
|
||||
// delete searchDetailsObj[key];
|
||||
// }
|
||||
// });
|
||||
|
||||
//console.log("appeal:", searchDetailsObj);
|
||||
|
||||
// searchDetailsObj = JSON.stringify(searchDetailsObj);
|
||||
// searchDetailsObj = searchDetailsObj.replace(/:true/gm, `:"Yes"`);
|
||||
// searchDetailsObj = searchDetailsObj.replace(/:false/gm, `:"No"`);
|
||||
// searchDetailsObj = JSON.parse(searchDetailsObj);
|
||||
|
||||
let caseReference = {};
|
||||
|
||||
caseReference.ticketnumber = query.casereference;
|
||||
caseReference.incidentid = query.inid;
|
||||
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 = xmlStr.replace(/\t/g, "");
|
||||
xmlStr = xmlStr.replace(/\n/g, "");
|
||||
xmlStr = xmlStr.replace(/> <"/g, "><");
|
||||
xmlStr = xmlStr.toString();
|
||||
|
||||
if (query.hasOwnProperty("key")) {
|
||||
const awaitingSubmissionFromBlob =
|
||||
await getAwaitingSubmissionFromBlob(thisSession.user.id);
|
||||
|
||||
store.dispatch(
|
||||
setAwaitingSubmissionFromBlob(awaitingSubmissionFromBlob)
|
||||
);
|
||||
|
||||
store.dispatch(
|
||||
setAwaitingSubmissionDetails(awaitingSubmissionFromBlob)
|
||||
);
|
||||
store.dispatch(
|
||||
setCurrentView({
|
||||
"viewName": "Awaiting Submission",
|
||||
"viewKey": "awaitingSubmissionDetails",
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
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));
|
||||
hydrateMyPortalAppealStore(store, ctx, result);
|
||||
|
||||
return {
|
||||
props: { url: process.env.NEXTAUTH_URL },
|
||||
props: {
|
||||
url: process.env.NEXTAUTH_URL,
|
||||
docsOffline: process.env.DOCAPI_OFFLINE || false,
|
||||
},
|
||||
};
|
||||
}
|
||||
);
|
||||
@@ -354,21 +474,14 @@ const mapStateToProps = (state) => {
|
||||
accountDetails: state.accountDetails,
|
||||
awaitingSubmission: state.awaitingSubmission,
|
||||
currentView: state.currentView,
|
||||
initialValues: state.appealType.caseReference.caseDetails,
|
||||
initialValues: state.appealType.caseReference?.caseDetails,
|
||||
};
|
||||
};
|
||||
|
||||
const mapDispatchToProps = (dispatch) => {
|
||||
return {
|
||||
setFormTitle: (title) => {
|
||||
dispatch(setAppealTypeTitle(title));
|
||||
},
|
||||
setCaseReference: (refno) => {
|
||||
dispatch(setCaseReference(refno));
|
||||
},
|
||||
setFilesForAppeal: (blobList) => {
|
||||
dispatch(setFilesForAppeal(blobList));
|
||||
},
|
||||
// Keep these only if something else uses them;
|
||||
// this page no longer needs the useEffect that called setCaseReference.
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -209,6 +209,7 @@ const RepresentationF = (props) => {
|
||||
}
|
||||
setCurrentReference={setCurrentReference}
|
||||
showQuestionnaireSection={showQuestionnaireSection}
|
||||
docsOffline={props.docsOffline}
|
||||
/>
|
||||
</div>
|
||||
<Footer footerLinks={footerLinks} ticketnumber={props} />
|
||||
@@ -327,6 +328,7 @@ export const getServerSideProps = wrapper.getServerSideProps(
|
||||
return {
|
||||
props: {
|
||||
containerID: thisSession.user.id,
|
||||
docsOffline: process.env.DOCAPI_OFFLINE || false,
|
||||
},
|
||||
};
|
||||
} else {
|
||||
|
||||
+383
-268
@@ -1,295 +1,409 @@
|
||||
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 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 { 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";
|
||||
|
||||
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, pages, formData } = props;
|
||||
let { t, lang } = useTranslation();
|
||||
const { footerLinks } = props;
|
||||
|
||||
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 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;
|
||||
// Memoise XML parsing so it doesn't rerun on every render
|
||||
const { sectionCount } = useMemo(() => {
|
||||
if (!formXML) return { sectionCount: 0 };
|
||||
|
||||
var tabs = xpath.select("//form/tabs/tab[*]", doc);
|
||||
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]);
|
||||
|
||||
let optionsStr = props.appealType.appealTypeOptions.value;
|
||||
// Safely compute formTitle from appeal type options + apt
|
||||
const formTitle = useMemo(() => {
|
||||
const optionsStr = props.appealType?.appealTypeOptions?.value;
|
||||
const apt = router.query.apt;
|
||||
|
||||
let selectedObj = jsonpath({
|
||||
path: "$..[?(@ && @.attributevalue=='" + router.query.apt + "')]",
|
||||
json: optionsStr,
|
||||
eval: true,
|
||||
});
|
||||
if (!optionsStr || !apt) return "New appeal";
|
||||
|
||||
//let optionsTitleObj = [];
|
||||
const selectedObj = jsonpath({
|
||||
path: "$..[?(@ && @.attributevalue=='" + apt + "')]",
|
||||
json: optionsStr,
|
||||
eval: true,
|
||||
});
|
||||
|
||||
//const optionsTitleObj = selectedObj.reduce(
|
||||
// (obj, arrValue) => (
|
||||
// (obj[arrValue] = arrValue
|
||||
// .replace(/(\band|[\s\-\+\(\)\,\&])/g, "")
|
||||
// .toLowerCase()
|
||||
// .slice(0, 39)),
|
||||
// obj
|
||||
// ),
|
||||
// {}
|
||||
// );
|
||||
|
||||
const formTitle = selectedObj[0].value;
|
||||
const title = selectedObj?.[0]?.value;
|
||||
return title || "New appeal";
|
||||
}, [props.appealType?.appealTypeOptions?.value, router.query.apt]);
|
||||
|
||||
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>
|
||||
<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 { query, req, res } = ctx;
|
||||
getIP(req);
|
||||
const { cookies } = req;
|
||||
const result = await loadNewAppealPage(ctx);
|
||||
|
||||
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,
|
||||
},
|
||||
};
|
||||
if (result?.redirect) {
|
||||
return { redirect: result.redirect };
|
||||
}
|
||||
|
||||
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));
|
||||
// Hydrate Redux from one place
|
||||
hydrateNewAppealStore(store, ctx.query, result);
|
||||
|
||||
return {
|
||||
props: { url: process.env.NEXTAUTH_URL },
|
||||
@@ -310,11 +424,12 @@ const mapStateToProps = (state) => {
|
||||
|
||||
const mapDispatchToProps = (dispatch) => {
|
||||
return {
|
||||
// Keep as-is; you can clean these later once you confirm usage
|
||||
setFormTitle: (title) => {
|
||||
dispatch(setAppealTypeTitle(title));
|
||||
// dispatch(setAppealTypeTitle(title)); // optional later
|
||||
},
|
||||
setCaseReference: (refno) => {
|
||||
dispatch(setCaseReference(refno));
|
||||
// dispatch(setCaseReferenceAction(refno)); // optional later
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user