321 lines
11 KiB
JavaScript
321 lines
11 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 {
|
|
getCase,
|
|
getAppealsTypes,
|
|
getAppealsTypesForNewAppeal,
|
|
getMandatoryFields,
|
|
getPickLists,
|
|
getFilesFromBlob,
|
|
getProgressFromBlob,
|
|
getIP,
|
|
} 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 {
|
|
setLoggedInUserId,
|
|
setLoggedInUserEmail,
|
|
setContainerID,
|
|
} from "../../store/accountDetails/action";
|
|
import {
|
|
setAppealLPA,
|
|
setAppealType,
|
|
setAppealTypeID,
|
|
setAppealTypeTitle,
|
|
setCaseReference,
|
|
setFilesForAppeal,
|
|
} from "../../store/appealType/action";
|
|
import { setForm } from "../../store/formData/action";
|
|
import { wrapper } from "../../store/store";
|
|
import { getProgressBlobs } from "../../actions/azurestorage";
|
|
import { getSession, useSession } from "next-auth/react";
|
|
|
|
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(
|
|
"$..[?(@.attributevalue=='" + router.query.apt + "')]",
|
|
optionsStr
|
|
);
|
|
|
|
//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 courseName={t("common:service-name")} />
|
|
|
|
<div className="govuk-width-container">
|
|
<Breadcrumbs slug={appealtypes} formTitle={formTitle} />
|
|
<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
|
|
);
|
|
|
|
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(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);
|