Merged PR 2242: Refactor: New Appeal flow structural cleanup (Slices 1–8, no behaviour change)
## Summary This PR merges the completed new-appeal refactor stream (Slices 1–8) into SIPS-Development. This refactor was executed in controlled slices with regression validation at each step. ## Scope Structural and readability improvements only: - XML/form derivation extraction - payload and file helper extraction - side-effect facade introduction - BuildSection and BuildCheckSection decomposition - BuildCheckRow formatter map refactor - nested prop boundary cleanup - start-flow cleanup (CreateCase / AboutYou) ## Behaviour No intended behavioural changes. The following were explicitly preserved: - S78 journey behaviour - payload shapes and field names/ids - HASCAS mapping logic - appellant/agent branching - validation rules and messages - redirect/query parameters (`lpa`, `apt`, `id`) - navigation and side-effect sequencing - EN/CY output parity ## Validation Full regression has been performed on: - start flow (CreateCase / AboutYou) - save and resume flows - file upload handling - check answers rendering - submit/finalisation sequence - confirmation flow - CRM insertion path - EN/CY parity Additional checks: - docsOffline branch behaviour - completion and partial-save email paths - negative-path validation scenarios - lint (warnings baseline unchanged) ## Risk Low: - changes are structural only - no business logic changes - no contract changes ## Rollback Safe rollback via reverting this merge commit. ## Notes This refactor reduces coupling and prepares the new-appeal flow for future appeal-type expansion. Related work items: #22570, #22576, #22577, #22583, #22586, #22587, #22588, #22590
This commit is contained in:
@@ -4,9 +4,16 @@ import { useRouter } from "next/router";
|
||||
import { useState } from "react";
|
||||
import { connect } from "react-redux";
|
||||
import { formValueSelector, reduxForm } from "redux-form";
|
||||
import xpath from "xpath";
|
||||
import { uploadFiles } from "../../actions/services/documentService";
|
||||
import { sendEmail } from "../../actions/services/notifyService";
|
||||
import { mergeWithExistingFilesList } from "../../lib/newappeal/fileListHelpers";
|
||||
import {
|
||||
uploadAppealFilesEffect,
|
||||
sendPartialSaveEmailEffect
|
||||
} from "../../lib/newappeal/journeyEffects";
|
||||
import {
|
||||
normalizeYesNoBooleans,
|
||||
removeNullKeys,
|
||||
stripInternalKeys
|
||||
} from "../../lib/newappeal/payloadCleanup";
|
||||
import {
|
||||
setCurrentSection,
|
||||
setDocumentsList,
|
||||
@@ -16,9 +23,22 @@ import {
|
||||
} from "../../store/appealType/action";
|
||||
import { getFormCollectionByID, getProgressObj, updateLinks } from "../utils";
|
||||
import BuildRow from "./buildrow";
|
||||
import {
|
||||
parseXml,
|
||||
selectAllTabTitleDescriptions,
|
||||
selectCurrentSectionRows,
|
||||
selectCurrentSectionTitleDescriptions,
|
||||
selectErrorFieldLabelDescription,
|
||||
selectFormTabs
|
||||
} from "../../lib/newappeal/formDerivation";
|
||||
|
||||
import { FieldsTranslations } from "../elements";
|
||||
import BuildProgress from "./buildprogress";
|
||||
import ErrorSummary from "./buildSection/ErrorSummary";
|
||||
import PrimaryActionButtons from "./buildSection/PrimaryActionButtons";
|
||||
import SaveStatusIndicator from "./buildSection/SaveStatusIndicator";
|
||||
import SectionHeader from "./buildSection/SectionHeader";
|
||||
import SidebarProgressPanel from "./buildSection/SidebarProgressPanel";
|
||||
|
||||
let BuildSection = (props) => {
|
||||
const [currentSectionSelected, setCurrentSectionSelected] = useState(1);
|
||||
@@ -52,29 +72,22 @@ let BuildSection = (props) => {
|
||||
mandatoryFieldsData
|
||||
} = props;
|
||||
|
||||
const legacyProps = props.props;
|
||||
const legacyAccountDetails = legacyProps.accountDetails;
|
||||
const legacyFormState = legacyProps.form;
|
||||
const legacyAppealType = legacyProps.appealType;
|
||||
const legacyUrl = legacyProps.url;
|
||||
|
||||
const documentListObj = props.appealType.documentList;
|
||||
const currentSection = props.appealType.currentSection;
|
||||
|
||||
const parser = new DOMParser();
|
||||
var doc = parser.parseFromString(props.formXML, "text/xml");
|
||||
var titles = xpath.select(
|
||||
"//form/tabs/tab[" + currentSection + " ]/labels/label/@description",
|
||||
doc
|
||||
);
|
||||
var rowXML = xpath.select(
|
||||
"/form/tabs/tab[" +
|
||||
currentSection +
|
||||
"]/columns//sections/section/rows/row",
|
||||
//"/form/tabs/tab/columns//sections/section/rows/row",
|
||||
doc
|
||||
);
|
||||
var doc = parseXml(props.formXML);
|
||||
var titles = selectCurrentSectionTitleDescriptions(doc, currentSection);
|
||||
var rowXML = selectCurrentSectionRows(doc, currentSection);
|
||||
|
||||
var formObjXML = xpath.select("/form/tabs", doc);
|
||||
var formObjXML = selectFormTabs(doc);
|
||||
|
||||
var titleList = xpath.select(
|
||||
"//form/tabs/tab[*]/labels/label/@description",
|
||||
doc
|
||||
);
|
||||
var titleList = selectAllTabTitleDescriptions(doc);
|
||||
|
||||
const progObj = getProgressObj(
|
||||
formXML,
|
||||
@@ -120,11 +133,11 @@ let BuildSection = (props) => {
|
||||
// _.includes(key, "pinswg_fileUpload") == true && delete dataObj[key];
|
||||
// }
|
||||
|
||||
await uploadFiles(
|
||||
await uploadAppealFilesEffect(
|
||||
dataObj,
|
||||
fileListObj,
|
||||
props.props.accountDetails.containerID,
|
||||
props.props.appealType.caseReference.ticketnumber
|
||||
legacyAccountDetails.containerID,
|
||||
legacyAppealType.caseReference.ticketnumber
|
||||
).then((data) => {
|
||||
//console.log("$1", data);
|
||||
setCompletedUploadFiles(true);
|
||||
@@ -167,12 +180,10 @@ let BuildSection = (props) => {
|
||||
|
||||
//console.log(buildAppealFilesArray);
|
||||
|
||||
buildAppealFilesArray = values.hasOwnProperty("filesList")
|
||||
? (buildAppealFilesArray.concat(values.filesList),
|
||||
buildAppealFilesArray.filter(function (item, idx) {
|
||||
return item.name;
|
||||
}))
|
||||
: buildAppealFilesArray;
|
||||
buildAppealFilesArray = mergeWithExistingFilesList(
|
||||
buildAppealFilesArray,
|
||||
values
|
||||
);
|
||||
|
||||
Object.assign(values, { "filesList": buildAppealFilesArray });
|
||||
|
||||
@@ -218,25 +229,15 @@ let BuildSection = (props) => {
|
||||
Object.assign(updateBody, {
|
||||
"pinswg_appealcasetype": props.appealType.appealTypeID,
|
||||
"pinswg_Appellant@odata.bind":
|
||||
"/contacts(" + props.props.accountDetails.loggedinUserId + ")",
|
||||
"/contacts(" + legacyAccountDetails.loggedinUserId + ")",
|
||||
"pinswg_name": props.appealType.caseReference.ticketnumber,
|
||||
[updateBindAppealTypeToIncident + "@odata.bind"]:
|
||||
"/incidents(" + incidentId + ")"
|
||||
});
|
||||
|
||||
updateBody = JSON.stringify(updateBody);
|
||||
updateBody = updateBody.replace(/:"Yes"/gm, `:true`);
|
||||
updateBody = updateBody.replace(/:"No"/gm, `:false`);
|
||||
updateBody = JSON.parse(updateBody);
|
||||
|
||||
Object.keys(updateBody).forEach((key) => {
|
||||
if (updateBody[key] === null) {
|
||||
delete updateBody[key];
|
||||
}
|
||||
if (key.indexOf("_") == 0) {
|
||||
delete updateBody[key];
|
||||
}
|
||||
});
|
||||
updateBody = normalizeYesNoBooleans(updateBody);
|
||||
updateBody = removeNullKeys(updateBody);
|
||||
updateBody = stripInternalKeys(updateBody);
|
||||
|
||||
//console.log(updateBody);
|
||||
|
||||
@@ -246,12 +247,12 @@ let BuildSection = (props) => {
|
||||
const reference = "PEDW-PARTIAL";
|
||||
const templateId = "021b0a7b-df00-41f1-b94e-c269bee98c75";
|
||||
const templateIdCY = "f3c4a56b-bfb8-4d39-97dd-888df3062b0a";
|
||||
const emailAddress = props.props.accountDetails.loggedinUserEmail;
|
||||
const emailAddress = legacyAccountDetails.loggedinUserEmail;
|
||||
const personalisation = {
|
||||
"caseReference": props.appealType.caseReference.ticketnumber,
|
||||
"emailAddress": props.props.accountDetails.loggedinUserEmail,
|
||||
"emailAddress": legacyAccountDetails.loggedinUserEmail,
|
||||
"returnLink":
|
||||
props.props.url +
|
||||
legacyUrl +
|
||||
(router.locale != "en" ? "/cy/fymhorth/" : "/myportal/") +
|
||||
appTypeCollection.UrlName +
|
||||
"?lpa=" +
|
||||
@@ -283,7 +284,7 @@ let BuildSection = (props) => {
|
||||
// );
|
||||
|
||||
sendSavedEmail == true &&
|
||||
sendEmail(
|
||||
sendPartialSaveEmailEffect(
|
||||
router.locale != "en" ? templateIdCY : templateId,
|
||||
emailAddress,
|
||||
personalisation,
|
||||
@@ -359,71 +360,38 @@ let BuildSection = (props) => {
|
||||
const [hasErrors, setHasErrors] = useState("");
|
||||
|
||||
const getErrors = () => {
|
||||
let errorsobj = props.props.form["appealForm"];
|
||||
let errorsobj = legacyFormState["appealForm"];
|
||||
//setHasErrors(errorsobj.hasOwnProperty("syncErrors"));
|
||||
window.scrollTo(0, 0);
|
||||
};
|
||||
|
||||
let errorsobj = {};
|
||||
const ShowErrorHeader = (props) => {
|
||||
errorsobj = props.props.appealForm.syncErrors;
|
||||
errorsobj = _.keys(errorsobj);
|
||||
|
||||
const getErrorItems = () => {
|
||||
let errorsobj = _.keys(
|
||||
_.get(props, "props.form.appealForm.syncErrors", {})
|
||||
);
|
||||
const getErrorLabel = (whichField) => {
|
||||
var doc = parser.parseFromString(props.formXML, "text/xml");
|
||||
var errorFieldLabel = xpath.select(
|
||||
"//*[control/@id='" + whichField + "']//@description",
|
||||
doc
|
||||
var doc = parseXml(props.formXML);
|
||||
var errorFieldLabel = selectErrorFieldLabelDescription(
|
||||
doc,
|
||||
whichField
|
||||
);
|
||||
|
||||
return errorFieldLabel[0].value;
|
||||
};
|
||||
|
||||
const ShowErrors = () => {
|
||||
let errorList = [];
|
||||
for (let i = 0; i < errorsobj.length; ++i) {
|
||||
//get label from error key - search rowxml for id = errorobj
|
||||
let errorItems = [];
|
||||
for (let i = 0; i < errorsobj.length; ++i) {
|
||||
errorItems.push({
|
||||
"field": errorsobj[i],
|
||||
"label": getErrorLabel(errorsobj[i])
|
||||
});
|
||||
}
|
||||
|
||||
errorList.push(
|
||||
<li key={i}>
|
||||
<a href={"#" + errorsobj[i] + "_label"}>
|
||||
{" "}
|
||||
{getErrorLabel(errorsobj[i])}
|
||||
</a>
|
||||
</li>
|
||||
);
|
||||
}
|
||||
|
||||
return errorList;
|
||||
};
|
||||
|
||||
return !_.isEmpty(errorsobj) ? (
|
||||
<div
|
||||
className="govuk-error-summary"
|
||||
aria-labelledby="error-summary-title"
|
||||
role="alert"
|
||||
tabIndex="-1"
|
||||
data-module="govuk-error-summary"
|
||||
>
|
||||
<h2
|
||||
className="govuk-error-summary__title"
|
||||
id="error-summary-title"
|
||||
>
|
||||
The following fields have a problem :
|
||||
</h2>
|
||||
<div className="govuk-error-summary__body">
|
||||
<ul className="govuk-list govuk-error-summary__list">
|
||||
<ShowErrors />
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
""
|
||||
);
|
||||
return errorItems;
|
||||
};
|
||||
|
||||
const hasUploadFiles = () => {
|
||||
const formArr = props.props.form["appealForm"].values;
|
||||
const formArr = legacyFormState["appealForm"].values;
|
||||
const prefix = "pinswg_fileUpload";
|
||||
const hasFiles = Object.keys(formArr).some((key) =>
|
||||
key.startsWith(prefix)
|
||||
@@ -435,19 +403,12 @@ let BuildSection = (props) => {
|
||||
return (
|
||||
<div className="govuk-grid-row">
|
||||
<div className="govuk-grid-column-two-thirds wgForm ">
|
||||
<h1 className="govuk-heading-m ">
|
||||
{FieldsTranslations(titles[0].value)}
|
||||
</h1>
|
||||
<SectionHeader title={FieldsTranslations(titles[0].value)} />
|
||||
<form onSubmit={handleSubmit(onHandleSubmit)}>
|
||||
{hasErrors == true ? (
|
||||
<ShowErrorHeader
|
||||
hasErrors={hasErrors}
|
||||
props={props.props.form}
|
||||
formXML={formXML}
|
||||
/>
|
||||
) : (
|
||||
""
|
||||
)}
|
||||
<ErrorSummary
|
||||
hasErrors={hasErrors == true}
|
||||
errorItems={getErrorItems()}
|
||||
/>
|
||||
<BuildRow
|
||||
rowXML={rowXML}
|
||||
whichSection={props.whichSection}
|
||||
@@ -466,7 +427,7 @@ let BuildSection = (props) => {
|
||||
}
|
||||
/>
|
||||
|
||||
<div className="govuk-button-group">
|
||||
<PrimaryActionButtons>
|
||||
{props.sectionCount != currentSection ? (
|
||||
<>
|
||||
<button
|
||||
@@ -476,11 +437,10 @@ let BuildSection = (props) => {
|
||||
onClick={() => {
|
||||
getErrors();
|
||||
let valuesObj = _.has(
|
||||
props.props.form[props.form],
|
||||
legacyFormState[props.form],
|
||||
"values"
|
||||
)
|
||||
? props.props.form[props.form]
|
||||
.values
|
||||
? legacyFormState[props.form].values
|
||||
: {};
|
||||
|
||||
//console.log("valuesobj:", valuesObj);
|
||||
@@ -503,26 +463,19 @@ let BuildSection = (props) => {
|
||||
</button>
|
||||
{currentSection > 1 &&
|
||||
(savingStatus ? (
|
||||
<span className=" progress-save-active">
|
||||
{router.locale == "cy"
|
||||
? "Nôl data"
|
||||
: "Saving data"}
|
||||
<img
|
||||
className="data-loading-icon"
|
||||
src="/assets/images/loading.gif"
|
||||
alt={
|
||||
router.locale == "cy"
|
||||
? "Nôl data"
|
||||
: "Saving data"
|
||||
}
|
||||
/>
|
||||
</span>
|
||||
<SaveStatusIndicator
|
||||
text={
|
||||
router.locale == "cy"
|
||||
? "Nôl data"
|
||||
: "Saving data"
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<button
|
||||
className="govuk-button progress-save "
|
||||
onClick={() => {
|
||||
let valuesObj =
|
||||
props.props.form[props.form]
|
||||
legacyFormState[props.form]
|
||||
.values || {};
|
||||
|
||||
// console.log(
|
||||
@@ -572,26 +525,19 @@ let BuildSection = (props) => {
|
||||
{t("common:submit-button")}{" "}
|
||||
</button>
|
||||
{savingStatus ? (
|
||||
<span className=" progress-save-active">
|
||||
{router.locale == "cy"
|
||||
? "Nôl data"
|
||||
: "Saving data"}
|
||||
<img
|
||||
className="data-loading-icon"
|
||||
src="/assets/images/loading.gif"
|
||||
alt={
|
||||
router.locale == "cy"
|
||||
? "Nôl data"
|
||||
: "Saving data"
|
||||
}
|
||||
/>
|
||||
</span>
|
||||
<SaveStatusIndicator
|
||||
text={
|
||||
router.locale == "cy"
|
||||
? "Nôl data"
|
||||
: "Saving data"
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<button
|
||||
className="govuk-button progress-save "
|
||||
onClick={() => {
|
||||
let valuesObj =
|
||||
props.props.form[props.form]
|
||||
legacyFormState[props.form]
|
||||
.values || {};
|
||||
|
||||
// console.log(
|
||||
@@ -631,29 +577,25 @@ let BuildSection = (props) => {
|
||||
) : (
|
||||
""
|
||||
)} */}
|
||||
</div>
|
||||
</PrimaryActionButtons>
|
||||
</form>
|
||||
</div>
|
||||
<div className="govuk-grid-column-one-third">
|
||||
<div className="at-nav-container">
|
||||
{/* <span>
|
||||
Last section is {lastIndex} - {currentSection}
|
||||
</span> */}
|
||||
<BuildProgress
|
||||
progObj={progObj}
|
||||
props={props}
|
||||
titleList={titleList}
|
||||
documentListObj={documentListObj}
|
||||
formObjXML={formXML}
|
||||
mandatoryFieldsData={mandatoryFieldsData}
|
||||
currentSection={currentSection}
|
||||
initialValues={props.initialValues}
|
||||
setCurrentSection={setCurrentSection}
|
||||
/>
|
||||
|
||||
<hr className="govuk-section-break govuk-section-break--m govuk-section-break--visible" />
|
||||
</div>
|
||||
</div>
|
||||
<SidebarProgressPanel>
|
||||
{/* <span>
|
||||
Last section is {lastIndex} - {currentSection}
|
||||
</span> */}
|
||||
<BuildProgress
|
||||
progObj={progObj}
|
||||
props={props}
|
||||
titleList={titleList}
|
||||
documentListObj={documentListObj}
|
||||
formObjXML={formXML}
|
||||
mandatoryFieldsData={mandatoryFieldsData}
|
||||
currentSection={currentSection}
|
||||
initialValues={props.initialValues}
|
||||
setCurrentSection={setCurrentSection}
|
||||
/>
|
||||
</SidebarProgressPanel>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user