From 9241fe0b84dc9eca4c16a3b11fabb4780bfafa50 Mon Sep 17 00:00:00 2001
From: robbond
Date: Thu, 15 Jan 2026 13:20:07 +0000
Subject: [PATCH 1/3] updated restriction to disallow partial reps and appeals
from being submitted when not docapi
---
components/admin/tabs/documents.js | 34 +-
components/case/documents.js | 34 +-
components/case/representation/index.js | 2 +
.../representationCompleteSubmit.js | 33 +
components/case/summary.js | 32 -
components/myportal/makenewappeal.js | 33 +-
components/newappeal/buildchecksection.js | 69 +-
components/representation.js | 1 +
components/utils/index.js | 27 +
i18n.js | 2 +-
locales/cy/myrepresentations.json | 4 +-
locales/cy/newappeal.json | 3 +-
locales/en/myrepresentations.json | 4 +-
locales/en/newappeal.json | 3 +-
pages/myportal/[appealtypes].js | 765 ++++++++++--------
pages/myportal/representation.js | 2 +
pages/newappeal/[appealtypes].js | 651 +++++++++------
17 files changed, 956 insertions(+), 743 deletions(-)
diff --git a/components/admin/tabs/documents.js b/components/admin/tabs/documents.js
index 94bc359a..a95e4ab6 100644
--- a/components/admin/tabs/documents.js
+++ b/components/admin/tabs/documents.js
@@ -5,7 +5,7 @@ import { useRouter } from "next/router";
import { useCallback, useEffect, useRef, useState } from "react";
import { connect } from "react-redux";
import transLookup from "../../../data/lookuptranslations.json";
-import { formatDates } from "../../utils";
+import { formatDates, getDocLink } from "../../utils";
import PaginationControl from "../../../components/case/pagination";
import DocumentLink from "../../utils/downloads";
import { useDownloadQueue } from "../../utils/downloadmanager";
@@ -305,37 +305,7 @@ const DocumentsTab = (props) => {
setSelectedDocumentOrigin("all")
);
};
- let ShowDocLinks = false;
- let checkShowDocLinks = docsOffline != false ? true : false;
-
- const getDocLink = (docsOffline) => {
- var startTime = docsOffline.split(",")[0];
- var endTime = docsOffline.split(",")[1];
-
- // console.log(startTime);
- // console.log(endTime);
-
- var currentDate = new Date();
-
- var startDate = new Date(currentDate.getTime());
- startDate.setHours(startTime.split(":")[0]);
- startDate.setMinutes(startTime.split(":")[1]);
- startDate.setSeconds(startTime.split(":")[2]);
-
- var endDate = new Date(currentDate.getTime());
- endDate.setHours(endTime.split(":")[0]);
- endDate.setMinutes(endTime.split(":")[1]);
- endDate.setSeconds(endTime.split(":")[2]);
-
- // console.log(startDate);
- // console.log(endDate);
- // console.log(currentDate);
-
- var valid = startDate < currentDate && endDate > currentDate;
- ShowDocLinks = valid;
- };
-
- checkShowDocLinks && getDocLink(docsOffline);
+ let ShowDocLinks = getDocLink(docsOffline);
const FilteredDocumentView = (documentDetailsArr) => {
documentDetailsArr = documentDetailsArr.value;
diff --git a/components/case/documents.js b/components/case/documents.js
index 35f6db4a..37a12ce5 100644
--- a/components/case/documents.js
+++ b/components/case/documents.js
@@ -5,7 +5,7 @@ import { useRouter } from "next/router";
import { useCallback, useEffect, useRef, useState } from "react";
import { connect } from "react-redux";
import transLookup from "../../data/lookuptranslations.json";
-import { formatDates } from "../utils";
+import { formatDates, getDocLink } from "../utils";
import PaginationControl from "./pagination";
import { sendGAEvent } from "@next/third-parties/google";
@@ -90,37 +90,7 @@ const DocumentDetails = (props) => {
setCurrentPage(1)
);
};
- let ShowDocLinks = false;
- let checkShowDocLinks = docsOffline != false ? true : false;
-
- const getDocLink = (docsOffline) => {
- var startTime = docsOffline.split(",")[0];
- var endTime = docsOffline.split(",")[1];
-
- // console.log(startTime);
- // console.log(endTime);
-
- var currentDate = new Date();
-
- var startDate = new Date(currentDate.getTime());
- startDate.setHours(startTime.split(":")[0]);
- startDate.setMinutes(startTime.split(":")[1]);
- startDate.setSeconds(startTime.split(":")[2]);
-
- var endDate = new Date(currentDate.getTime());
- endDate.setHours(endTime.split(":")[0]);
- endDate.setMinutes(endTime.split(":")[1]);
- endDate.setSeconds(endTime.split(":")[2]);
-
- // console.log(startDate);
- // console.log(endDate);
- // console.log(currentDate);
-
- var valid = startDate < currentDate && endDate > currentDate;
- ShowDocLinks = valid;
- };
-
- checkShowDocLinks && getDocLink(docsOffline);
+ let ShowDocLinks = getDocLink(docsOffline);
const DocumentView = (documentDetailsArr) => {
documentDetailsArr = documentDetailsArr.value;
diff --git a/components/case/representation/index.js b/components/case/representation/index.js
index 27b9092c..5c894c8b 100644
--- a/components/case/representation/index.js
+++ b/components/case/representation/index.js
@@ -66,6 +66,7 @@ let MakeRepresentation = (props) => {
initialValues,
setCurrentReference,
ticketnumber,
+ docsOffline,
} = props;
const formObj = props.props.form;
let setCaseQueryObj = props[currentType] || {};
@@ -1105,6 +1106,7 @@ let MakeRepresentation = (props) => {
questionnaireCount={questionnaireCount}
finaliseAppealProcess={finaliseAppealProcess}
setFinaliseAppealProcess={setFinaliseAppealProcess}
+ docsOffline={docsOffline}
/>
) : (
<>
diff --git a/components/case/representation/representationCompleteSubmit.js b/components/case/representation/representationCompleteSubmit.js
index a4302dd7..b51830ab 100644
--- a/components/case/representation/representationCompleteSubmit.js
+++ b/components/case/representation/representationCompleteSubmit.js
@@ -13,6 +13,7 @@ import {
getThumbnailIconByExtension,
formatDates,
updateLinks,
+ getDocLink,
} from "../../utils";
import {
@@ -41,7 +42,11 @@ const RepCompleteSubmit = (props) => {
questionnaireCount,
finaliseAppealProcess,
setCurrentReference,
+ docsOffline,
} = props;
+
+ let ShowDocLinks = getDocLink(docsOffline);
+
const { acceptedFiles, getRootProps, getInputProps } = useDropzone();
const files = acceptedFiles.map((file) => (
@@ -230,6 +235,7 @@ const RepCompleteSubmit = (props) => {
}
const checkRepDatePassed = () => {
+ return false;
if (repFormData.representationType == "Questionnaire") {
return false;
} else {
@@ -603,6 +609,7 @@ const RepCompleteSubmit = (props) => {
"myrepresentations:rep-check-tandc-para-three"
)}
+
{checkRepDatePassed() ? (
diff --git a/components/case/summary.js b/components/case/summary.js
index ed5aa7ff..b053f450 100644
--- a/components/case/summary.js
+++ b/components/case/summary.js
@@ -104,38 +104,6 @@ const CaseSummary = (props) => {
? true
: false;
- let ShowDocLinks = false;
- let checkShowDocLinks = docsOffline != false ? true : false;
-
- const getDocLink = (docsOffline) => {
- var startTime = docsOffline.split(",")[0];
- var endTime = docsOffline.split(",")[1];
-
- // console.log(startTime);
- // console.log(endTime);
-
- var currentDate = new Date();
-
- var startDate = new Date(currentDate.getTime());
- startDate.setHours(startTime.split(":")[0]);
- startDate.setMinutes(startTime.split(":")[1]);
- startDate.setSeconds(startTime.split(":")[2]);
-
- var endDate = new Date(currentDate.getTime());
- endDate.setHours(endTime.split(":")[0]);
- endDate.setMinutes(endTime.split(":")[1]);
- endDate.setSeconds(endTime.split(":")[2]);
-
- // console.log(startDate);
- // console.log(endDate);
- // console.log(currentDate);
-
- var valid = startDate < currentDate && endDate > currentDate;
- ShowDocLinks = valid;
- };
-
- checkShowDocLinks && getDocLink(docsOffline);
-
const selectWatchedCase = (loggedInUser, incidentID, appealType) => {
let updateBody = {
"pinswg_WatchedCase@odata.bind": "/incidents(" + incidentID + ")",
diff --git a/components/myportal/makenewappeal.js b/components/myportal/makenewappeal.js
index ee1ac54a..a2ceedd7 100644
--- a/components/myportal/makenewappeal.js
+++ b/components/myportal/makenewappeal.js
@@ -1,6 +1,7 @@
import useTranslation from "next-translate/useTranslation";
import Link from "next/link";
import { useRouter } from "next/router";
+import { getDocLink } from "../utils";
export default function MakeNewAppeal(props) {
let { t } = useTranslation();
@@ -10,37 +11,7 @@ export default function MakeNewAppeal(props) {
const router = useRouter();
const { locale } = router;
- let ShowDocLinks = false;
- let checkShowDocLinks = docsOffline != false ? true : false;
-
- const getDocLink = (docsOffline) => {
- var startTime = docsOffline.split(",")[0];
- var endTime = docsOffline.split(",")[1];
-
- // console.log(startTime);
- // console.log(endTime);
-
- var currentDate = new Date();
-
- var startDate = new Date(currentDate.getTime());
- startDate.setHours(startTime.split(":")[0]);
- startDate.setMinutes(startTime.split(":")[1]);
- startDate.setSeconds(startTime.split(":")[2]);
-
- var endDate = new Date(currentDate.getTime());
- endDate.setHours(endTime.split(":")[0]);
- endDate.setMinutes(endTime.split(":")[1]);
- endDate.setSeconds(endTime.split(":")[2]);
-
- // console.log(startDate);
- // console.log(endDate);
- // console.log(currentDate);
-
- var valid = startDate < currentDate && endDate > currentDate;
- ShowDocLinks = valid;
- };
-
- console.log("docsOffline", docsOffline, getDocLink(docsOffline));
+ let ShowDocLinks = getDocLink(docsOffline);
return (
diff --git a/components/newappeal/buildchecksection.js b/components/newappeal/buildchecksection.js
index 58030988..6f18f630 100644
--- a/components/newappeal/buildchecksection.js
+++ b/components/newappeal/buildchecksection.js
@@ -18,6 +18,7 @@ import {
bytesToSize,
getThumbnailIconByExtension,
updateLinks,
+ getDocLink,
} from "../utils";
let BuildCheckSection = (props) => {
@@ -39,6 +40,7 @@ let BuildCheckSection = (props) => {
setCurrentSection,
updateCurrentSection,
mandatoryFieldsData,
+ docsOffline,
} = props;
const parser = new DOMParser();
@@ -180,6 +182,8 @@ let BuildCheckSection = (props) => {
: setConfirmSections(false);
};
+ let ShowDocLinks = getDocLink(docsOffline);
+
return (
@@ -327,23 +331,54 @@ let BuildCheckSection = (props) => {
>
)}
diff --git a/components/representation.js b/components/representation.js
index 77ebb8c7..da9f4232 100644
--- a/components/representation.js
+++ b/components/representation.js
@@ -35,6 +35,7 @@ const CaseRepresentation = (props) => {
props.setShowQuestionnaireSection
}
setCurrentReference={props.setCurrentReference}
+ docsOffline={props.docsOffline}
/>
diff --git a/components/utils/index.js b/components/utils/index.js
index 97a6cd64..bbd892dc 100644
--- a/components/utils/index.js
+++ b/components/utils/index.js
@@ -797,3 +797,30 @@ export const whichRepType = (props) => {
return repType;
};
+
+export const getDocLink = (docsOffline) => {
+ var startTime = docsOffline.split(",")[0];
+ var endTime = docsOffline.split(",")[1];
+
+ // console.log(startTime);
+ // console.log(endTime);
+
+ var currentDate = new Date();
+
+ var startDate = new Date(currentDate.getTime());
+ startDate.setHours(startTime.split(":")[0]);
+ startDate.setMinutes(startTime.split(":")[1]);
+ startDate.setSeconds(startTime.split(":")[2]);
+
+ var endDate = new Date(currentDate.getTime());
+ endDate.setHours(endTime.split(":")[0]);
+ endDate.setMinutes(endTime.split(":")[1]);
+ endDate.setSeconds(endTime.split(":")[2]);
+
+ // console.log(startDate);
+ // console.log(endDate);
+ // console.log(currentDate);
+
+ var valid = startDate < currentDate && endDate > currentDate;
+ return valid;
+};
diff --git a/i18n.js b/i18n.js
index 3b680589..272ba0ea 100644
--- a/i18n.js
+++ b/i18n.js
@@ -57,7 +57,7 @@ module.exports = {
"/myportal/case/id/[incident]": ["case", "home"],
"/myportal/addresssearch": ["search", "case", "myportal"],
"/myportal/addresssearchresults": ["search", "case", "myportal"],
- "/myportal/[appealtypes]": ["newappeal", "home"],
+ "/myportal/[appealtypes]": ["newappeal", "home", "myportal"],
"/newappeal": ["newappeal", "home"],
"/newappeal/*": ["newappeal", "home"],
"/newappeal/[appealtypes]": ["newappeal", "home"],
diff --git a/locales/cy/myrepresentations.json b/locales/cy/myrepresentations.json
index 027f2b3a..c776853d 100644
--- a/locales/cy/myrepresentations.json
+++ b/locales/cy/myrepresentations.json
@@ -252,5 +252,7 @@
"rep-period-passed-heading": "Mae'r cyfnod cynrychioli wedi mynd heibio",
"rep-period-notice-label": "Aeth y dyddiad dyledus ar gyfer y sylw hwn heibio. Ni allwch gyflwyno'r wybodaeth a ddarparwyd gennych mwyach.",
"representation-onbehalfof-hint": " e.e. \"Perchnogion Rhifau 1-5 Stryd Fawr\", neu \"Mr a Mrs Smith\" neu \"ysgutorion ystâd Mr Evans\"",
- "representation-onbehalfof-label": "Rhowch enw'r cwmni/grŵp/sefydliad"
+ "representation-onbehalfof-label": "Rhowch enw'r cwmni/grŵp/sefydliad",
+ "docsoffline-reps-label": "Oherwydd gwaith cynnal a chadw system, ni allwn dderbyn sylwadau ar hyn o bryd. Rhowch gynnig arall arni yn nes ymlaen.",
+ "return-to-myportal-link": "Dychwelyd i Fy Mhorth"
}
\ No newline at end of file
diff --git a/locales/cy/newappeal.json b/locales/cy/newappeal.json
index bd59bbd9..4ba06f38 100644
--- a/locales/cy/newappeal.json
+++ b/locales/cy/newappeal.json
@@ -120,5 +120,6 @@
"new-appeal-finalising-heading": "Cwblhau cyflwyniad eich apêl",
"new-appeal-finalising-label": "Wrthi'n uwchlwytho ffeiliau ar hyn o bryd a chwblhau eich cyflwyniad apêl",
"new-appeal-wait-label": "Arhoswch os gwelwch yn dda",
- "invalid-email-address-errormsg": "Cyfeiriad e-bost annilys"
+ "invalid-email-address-errormsg": "Cyfeiriad e-bost annilys",
+ "return-to-myportal-link": "Dychwelyd i Fy Mhorth"
}
\ No newline at end of file
diff --git a/locales/en/myrepresentations.json b/locales/en/myrepresentations.json
index aaa4e53a..8618b50f 100644
--- a/locales/en/myrepresentations.json
+++ b/locales/en/myrepresentations.json
@@ -252,5 +252,7 @@
"rep-period-passed-heading": "Representation period has passed",
"rep-period-notice-label": "The due date for this representation passed. You can no longer submit the information you have provided.",
"representation-onbehalfof-hint": "e.g. \"Owners of Numbers 1-5 High Street\", or \"Mr and Mrs Smith\" or \"The executors of Mr Evans' estate\"",
- "representation-onbehalfof-label": "Enter the name of the company/group/organisation"
+ "representation-onbehalfof-label": "Enter the name of the company/group/organisation",
+ "docsoffline-reps-label": "Due to system maintenance, we are unable to accept representations at this time. Please try again later.",
+ "return-to-myportal-link": "Return to My Portal"
}
\ No newline at end of file
diff --git a/locales/en/newappeal.json b/locales/en/newappeal.json
index 8580faf2..6414ee36 100644
--- a/locales/en/newappeal.json
+++ b/locales/en/newappeal.json
@@ -120,5 +120,6 @@
"new-appeal-finalising-heading": "Finalising your appeal submission",
"new-appeal-finalising-label": "Currently uploading files and finalising your appeal submission",
"new-appeal-wait-label": "Please wait",
- "invalid-email-address-errormsg": "Invalid email address"
+ "invalid-email-address-errormsg": "Invalid email address",
+ "return-to-myportal-link": "Return to My Portal"
}
\ No newline at end of file
diff --git a/pages/myportal/[appealtypes].js b/pages/myportal/[appealtypes].js
index 950c7e41..62f3631d 100644
--- a/pages/myportal/[appealtypes].js
+++ b/pages/myportal/[appealtypes].js
@@ -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 (
+//
+//
+//
+// {t("newappeal:page-title")} - {t("common:service-name")}
+//
+// <>
+//
+//
+// {/* If they have a Twitter Handle, include the meta details below */}
+//
+//
+
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+// >
+//
+//
+//
+//
+
+//
+//
+//
+//
+// {props.appealType.currentSection == 9999 ? (
+//
+// ) : props.appealType.currentSection ==
+// sectionCount + 1 ? (
+//
+// ) : (
+// <>
+//
+// >
+// )}
+//
+//
+//
+//
+//
+//
+// );
+// };
+
+// 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 (
-
-
-
- {t("newappeal:page-title")} - {t("common:service-name")}
-
- <>
-
-
- {/* If they have a Twitter Handle, include the meta details below */}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- >
-
-
-
-
-
-
-
-
-
- {props.appealType.currentSection == 9999 ? (
-
- ) : props.appealType.currentSection ==
- sectionCount + 1 ? (
-
- ) : (
- <>
-
- >
- )}
-
-
-
-
-
-
+
+
+
);
};
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.
};
};
diff --git a/pages/myportal/representation.js b/pages/myportal/representation.js
index de7bce6e..f8b3a726 100644
--- a/pages/myportal/representation.js
+++ b/pages/myportal/representation.js
@@ -209,6 +209,7 @@ const RepresentationF = (props) => {
}
setCurrentReference={setCurrentReference}
showQuestionnaireSection={showQuestionnaireSection}
+ docsOffline={props.docsOffline}
/>