moved alot of stuff from client side

This commit is contained in:
2024-11-18 19:54:23 +00:00
parent 2c5323c9cf
commit e690bc6725
12 changed files with 686 additions and 298 deletions
+254 -206
View File
@@ -389,6 +389,8 @@ let MakeRepresentation = (props) => {
caseReference={caseReference}
setRepFileName={setRepFileName}
updateRepresentation={updateRepresentation}
setSavingStatus={setSavingStatus}
savingStatus={savingStatus}
/>
);
} else {
@@ -408,6 +410,8 @@ let MakeRepresentation = (props) => {
caseReference={caseReference}
setRepFileName={setRepFileName}
updateRepresentation={updateRepresentation}
setSavingStatus={setSavingStatus}
savingStatus={savingStatus}
/>;
break;
case "appellant":
@@ -431,6 +435,8 @@ let MakeRepresentation = (props) => {
props={props}
setRepFileName={setRepFileName}
updateRepresentation={updateRepresentation}
setSavingStatus={setSavingStatus}
savingStatus={savingStatus}
/>
);
break;
@@ -464,6 +470,8 @@ let MakeRepresentation = (props) => {
questionnaireCount={questionnaireCount}
setRepFileName={setRepFileName}
updateRepresentation={updateRepresentation}
setSavingStatus={setSavingStatus}
savingStatus={savingStatus}
/>
);
break;
@@ -488,6 +496,8 @@ let MakeRepresentation = (props) => {
props={props}
setRepFileName={setRepFileName}
updateRepresentation={updateRepresentation}
setSavingStatus={setSavingStatus}
savingStatus={savingStatus}
/>
);
break;
@@ -512,6 +522,8 @@ let MakeRepresentation = (props) => {
props={props}
setRepFileName={setRepFileName}
updateRepresentation={updateRepresentation}
setSavingStatus={setSavingStatus}
savingStatus={savingStatus}
/>
);
break;
@@ -615,6 +627,10 @@ let MakeRepresentation = (props) => {
const sortFileObj = (filelistObj) => {
let blobList = filelistObj;
function removeNullObjects(arr) {
return arr.filter((obj) => obj !== null);
}
function removeObjectsWithUndefinedKey(arr, key) {
return arr.filter((obj) => obj[key] !== undefined);
}
@@ -623,6 +639,7 @@ let MakeRepresentation = (props) => {
return arr.filter((obj) => Object.keys(obj).length > 0);
}
blobList = removeNullObjects(blobList);
blobList = removeEmptyObjects(blobList);
blobList = removeObjectsWithUndefinedKey(blobList, "name");
@@ -819,6 +836,7 @@ let MakeRepresentation = (props) => {
// Object.assign(values, {
// "filesList": buildFileArray,
// })),
uploadRepresentationFiles(values),
generateRepPDF(
values,
@@ -931,54 +949,165 @@ let MakeRepresentation = (props) => {
: values.representationCapacity,
"locale": router.locale,
}));
currentView.representationSubmit != true
? _.isEmpty(currentView.representationCapacity)
? isLPA
? setRepresentationCapacity("lpa")
: setRepresentationCapacity(
values.representationCapacity
.replace(/(\band|[\s\-\+\(\)\,\&])/g, "")
.toLowerCase()
)
: questionnaireCount != 0 &&
showQuestionnaireSection < questionnaireCount
? (setShowQuestionnaireSection(showQuestionnaireSection + 1),
updateRepresentation(values, false, false))
: (updateRepresentation(values, false, false),
setRepresentationSubmit(true))
: currentView.representationSubmit == true
? (console.log("capacity", currentView.representationCapacity),
console.log("has errors:", props.invalid),
Object.assign(values, { "locale": router.locale }),
props.invalid == false &&
updateRepresentation(values, false, false),
// values.hasOwnProperty("representationDocuments") &&
// (values.representationDocuments.map((Blob) =>
// buildFileArray.push({
// "name": Blob.name,
// "size": Blob.size,
// })
// ),
// Object.assign(values, {
// "filesList": buildFileArray,
// })),
console.log(
"====================== rep lpa payload:\n",
JSON.stringify(values)
),
generateRepPDF(
values,
props.props.accountDetails.containerID,
currentView.caseReference.currentReference
),
uploadRepresentationFiles(values),
setRepresentationSubmitConfirmation(true))
: console.log("nit updated");
if (currentView.representationSubmit != true) {
if (_.isEmpty(currentView.representationCapacity)) {
if (isLPA) {
setRepresentationCapacity(
values.representationCapacity
.replace(/(\band|[\s\-\+\(\)\,\&])/g, "")
.toLowerCase()
);
} else {
setRepresentationCapacity(
values.representationCapacity
.replace(/(\band|[\s\-\+\(\)\,\&])/g, "")
.toLowerCase()
);
}
} else {
if (values.representationType == "Questionnaire") {
if (
questionnaireCount != 0 &&
showQuestionnaireSection < questionnaireCount
) {
setShowQuestionnaireSection(
showQuestionnaireSection + 1
);
updateRepresentation(values, false, false);
} else {
updateRepresentation(values, false, false);
setRepresentationSubmit(true);
}
} else {
updateRepresentation(values, false, false);
setRepresentationSubmit(true);
}
}
} else {
if (currentView.representationSubmit == true) {
console.log("capacity", currentView.representationCapacity);
console.log("has errors:", props.invalid);
Object.assign(values, { "locale": router.locale });
props.invalid == false &&
updateRepresentation(values, false, false);
// values.hasOwnProperty("representationDocuments") &&
// (values.representationDocuments.map((Blob) =>
// buildFileArray.push({
// "name": Blob.name,
// "size": Blob.size,
// })
// ),
// Object.assign(values, {
// "filesList": buildFileArray,
// })),
console.log(
"====================== rep lpa payload:\n",
JSON.stringify(values)
);
generateRepPDF(
values,
props.props.accountDetails.containerID,
currentView.caseReference.currentReference
);
uploadRepresentationFiles(values);
setRepresentationSubmitConfirmation(true);
} else {
console.log("nit updated");
}
}
// currentView.representationSubmit != true
// ? _.isEmpty(currentView.representationCapacity)
// ? isLPA
// ? setRepresentationCapacity("lpa")
// : setRepresentationCapacity(
// values.representationCapacity
// .replace(/(\band|[\s\-\+\(\)\,\&])/g, "")
// .toLowerCase()
// )
// : questionnaireCount != 0 &&
// showQuestionnaireSection < questionnaireCount
// ? (setShowQuestionnaireSection(showQuestionnaireSection + 1),
// updateRepresentation(values, false, false))
// : (updateRepresentation(values, false, false),
// setRepresentationSubmit(true))
// : currentView.representationSubmit == true
// ? (console.log("capacity", currentView.representationCapacity),
// console.log("has errors:", props.invalid),
// Object.assign(values, { "locale": router.locale }),
// props.invalid == false &&
// updateRepresentation(values, false, false),
// // values.hasOwnProperty("representationDocuments") &&
// // (values.representationDocuments.map((Blob) =>
// // buildFileArray.push({
// // "name": Blob.name,
// // "size": Blob.size,
// // })
// // ),
// // Object.assign(values, {
// // "filesList": buildFileArray,
// // })),
// console.log(
// "====================== rep lpa payload:\n",
// JSON.stringify(values)
// ),
// generateRepPDF(
// values,
// props.props.accountDetails.containerID,
// currentView.caseReference.currentReference
// ),
// uploadRepresentationFiles(values),
// setRepresentationSubmitConfirmation(true))
// : console.log("nit updated");
//window.alert(`You submitted:\n\n${JSON.stringify(values, null, 2)}`);
};
const cleanFilesList = (blobList) => {
let newblobList = blobList.filesList;
function removeNullObjects(arr) {
if (arr.length === 0) {
return arr;
}
return arr.filter((obj) => obj !== null);
}
function removeObjectsWithUndefinedKey(arr, key) {
if (arr.length === 0) {
return arr;
}
return arr.filter((obj) => obj[key] !== undefined);
}
function removeEmptyObjects(arr) {
if (arr.length === 0) {
return arr;
}
return arr.filter(
(obj) =>
obj &&
typeof obj === "object" &&
Object.keys(obj).length > 0
);
}
newblobList = removeNullObjects(newblobList);
newblobList = removeEmptyObjects(newblobList);
newblobList = removeObjectsWithUndefinedKey(newblobList, "name");
Object.assign(blobList, {
"filesList": newblobList,
});
return blobList;
};
const uploadRepresentationFiles = (values) => {
values = values.hasOwnProperty("filesList")
? cleanFilesList(values)
: values;
// get filelists from values object
let fileListObj = _.filter(values, function (v, key) {
return _.includes(key, "representationDocuments");
@@ -1011,19 +1140,8 @@ let MakeRepresentation = (props) => {
const repForm = props.props.form;
// try {
// let value = props.initialValues;
// setRepresentationCapacity(
// props.initialValues.representationCapacity.toLowerCase()
// );
// //setRepresentationSubmit(false);
// } catch {
// console.log("not has props");
// }
return (
<div>
<div>hello {currentView.representationSubmit ? "yep" : "no"}</div>
<form onSubmit={handleSubmit(onHandleSubmit)}>
{currentView.representationSubmit == true ? (
<RepCompleteSubmit
@@ -1045,7 +1163,7 @@ let MakeRepresentation = (props) => {
/>
) : (
<>
{!session ? (
{/* {!session ? (
<>
<div>
<p className="govuk-body">
@@ -1077,172 +1195,103 @@ let MakeRepresentation = (props) => {
)}
</button>
</>
) : (
<>
<h1 className="govuk-heading-l">
{t(
"myrepresentations:make-a-representation-on-label"
)}{" "}
{currentView.caseReference.currentReference}{" "}
</h1>
{currentView.caseReference.caseReference}
<div id="rep-form">
<div className="govuk-grid-column-three-quarters wgForm">
{whichControl()}
</div>
) : ( */}
<>
<h1 className="govuk-heading-l">
{t(
"myrepresentations:make-a-representation-on-label"
)}{" "}
{currentView.caseReference.currentReference}{" "}
</h1>
<div id="rep-form">
<div className="govuk-grid-column-three-quarters wgForm">
{whichControl()}
</div>
<div className="govuk-grid-column-one-quarter">
{" "}
<div className="card">
<div className="card-body">
<h2 className="govuk-heading-s">
{t(
"myrepresentations:timetable-title"
)}{" "}
<div className="govuk-grid-column-one-quarter">
{" "}
<div className="card">
<div className="card-body">
<h2 className="govuk-heading-s">
{t(
"myrepresentations:timetable-title"
)}{" "}
{currentView.caseReference
.appealType == 846040011}
</h2>
<div className="govuk-summary-list">
<div className="govuk-body-s">
{currentView.caseReference
.appealType ==
846040011}
</h2>
<div className="govuk-summary-list">
<div className="govuk-body-s">
{currentView
.caseReference
.appealType ==
846040011
? t(
"myrepresentations:local-impact-report"
)
: t(
"myrepresentations:questionnaire-due-label"
)}
:
<span className="govuk-body-s">
{" "}
{formatDates(
detailsObj.pinswg_questionnaireduedate ||
detailsObj.pinswg_endofrepresentationperiod
)}
</span>
</div>
.appealType == 846040011
? t(
"myrepresentations:local-impact-report"
)
: t(
"myrepresentations:questionnaire-due-label"
)}
:
<span className="govuk-body-s">
{" "}
{formatDates(
detailsObj.pinswg_questionnaireduedate ||
detailsObj.pinswg_endofrepresentationperiod
)}
</span>
</div>
<div className="govuk-body-s">
{t(
"myrepresentations:statements-due-label"
)}
:
<span className="govuk-body-s">
{" "}
{formatDates(
detailsObj.pinswg_statementduedate ||
detailsObj.pinswg_statementsduedate ||
detailsObj.pinswg_endofrepresentationperiod
)}
</span>
</div>
{currentView.caseReference
.appealType !=
846040011 && (
<div className="govuk-body-s">
{t(
"myrepresentations:statements-due-label"
"myrepresentations:final-comments-due-label"
)}
:
<span className="govuk-body-s">
{" "}
{formatDates(
detailsObj.pinswg_statementduedate ||
detailsObj.pinswg_statementsduedate ||
detailsObj.pinswg_endofrepresentationperiod
detailsObj.pinswg_finalcommentsduedate
)}
</span>
</div>
{currentView.caseReference
.appealType !=
846040011 && (
<div className="govuk-body-s">
{t(
"myrepresentations:final-comments-due-label"
)}
:
<span className="govuk-body-s">
{" "}
{formatDates(
detailsObj.pinswg_finalcommentsduedate
)}
</span>
</div>
)}
</div>
)}
</div>
</div>{" "}
{/* {typeof props.props.currentView
.representationCapacity !=
"undefined" &&
props.props.currentView
.representationCapacity.length >
0 && (
<div className="govuk-grid-row">
{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>
) : (
<button
className="govuk-button govuk-button--secondary progress-save "
onClick={() => {
let valuesObj =
props.props
.form[
props
.form
].values ||
{};
console.log(
"valuesobj:",
valuesObj
);
delete valuesObj[
"_pinswg_appellant_value"
];
console.log(
"on save:",
valuesObj
);
updateRepresentation(
valuesObj,
false,
true
);
}}
>
{t(
"common:save-exit-button"
)}
</button>
)}
ee
</div>
)} */}
<div>
{formObj.hasOwnProperty(
"representationForm"
) &&
formObj[
"representationForm"
].hasOwnProperty("values") &&
formObj[
"representationForm"
].values.hasOwnProperty(
"representationType"
) &&
formObj["representationForm"]
.values
.representationType ==
"Questionnaire" &&
whichProgress()}
</div>
</div>
<div>
{formObj.hasOwnProperty(
"representationForm"
) &&
formObj[
"representationForm"
].hasOwnProperty("values") &&
formObj[
"representationForm"
].values.hasOwnProperty(
"representationType"
) &&
formObj["representationForm"].values
.representationType ==
"Questionnaire" &&
whichProgress()}
</div>
</div>
</>
)}
</div>
</>
{/* )} */}
</>
)}
</form>
@@ -1266,7 +1315,6 @@ const mapStateToProps = (state) => {
const mapDispatchToProps = (dispatch) => {
return {
setRepresentationCapacity: (representationCapacity) => {
//dispatch(reset("representationForm"));
dispatch(setRepresentationCapacity(representationCapacity));
},
setRepresentationSubmit: (representationSubmit) => {
@@ -27,9 +27,10 @@ const RepAgent = (props) => {
currentView,
setRepFileName,
updateRepresentation,
setSavingStatus,
savingStatus,
} = props;
const { acceptedFiles, getRootProps, getInputProps } = useDropzone();
const [savingStatus, setSavingStatus] = useState(false);
setRepFileName(formObj.representationForm.values);
@@ -179,7 +180,7 @@ const RepAgent = (props) => {
props.props.props.accountDetails
.containerID
}
filenamePrefix={props}
filenamePrefix={props.formObj}
/>
</div>
{props.currentView.caseReference.hasOwnProperty(
@@ -30,9 +30,10 @@ const RepAppellant = (props) => {
currentView,
setRepFileName,
updateRepresentation,
setSavingStatus,
savingStatus,
} = props;
const { acceptedFiles, getRootProps, getInputProps } = useDropzone();
const [savingStatus, setSavingStatus] = useState(false);
setRepFileName(formObj.representationForm.values);
@@ -157,7 +158,7 @@ const RepAppellant = (props) => {
props.props.props.accountDetails
.containerID
}
filenamePrefix={props}
filenamePrefix={props.formObj}
/>
</div>
{props.currentView.caseReference.hasOwnProperty(
@@ -966,16 +966,33 @@ export const RenderFileUpload = (field) => {
let blobList = filelistObj;
function removeNullObjects(arr) {
if (arr.length === 0) {
return arr;
}
return arr.filter((obj) => obj !== null);
}
function removeObjectsWithUndefinedKey(arr, key) {
if (arr.length === 0) {
return arr;
}
return arr.filter((obj) => obj[key] !== undefined);
}
function removeEmptyObjects(arr) {
return arr.filter((obj) => Object.keys(obj).length > 0);
if (arr.length === 0) {
return arr;
}
return arr.filter(
(obj) =>
obj && typeof obj === "object" && Object.keys(obj).length > 0
);
}
blobList = removeEmptyObjects(blobList);
blobList = removeObjectsWithUndefinedKey(blobList, "name");
blobList = removeNullObjects(blobList);
let buildAppealFilesArray = [];
@@ -1079,7 +1096,7 @@ export const RenderFileUpload = (field) => {
{field.meta.touched && field.meta.error && (
<span className="error">{field.meta.error}</span>
)}
{blobList && Array.isArray(files) && (
{/* {files && Array.isArray(files) && (
<ul>
{files.map(
(file, i) =>
@@ -1100,7 +1117,7 @@ export const RenderFileUpload = (field) => {
)
)}
</ul>
)}
)} */}
{blobList.map((blob, i) => (
<div
key={blob.name + "_" + i}
@@ -1169,8 +1186,19 @@ export function FileUploadField(props) {
setFilesForAppeal={props.setFilesForAppeal}
containerID={props.containerID}
filenamePrefix={
props.filenamePrefix.formObj.representationForm.values
.repfile_name
props.filenamePrefix.hasOwnProperty("representationForm") &&
props.filenamePrefix.representationForm.hasOwnProperty(
"values"
) &&
props.filenamePrefix.representationForm.values.hasOwnProperty(
"repfile_name"
)
? props.filenamePrefix.representationForm.values
.repfile_name
: props.filenamePrefix.hasOwnProperty("formObj")
? props.filenamePrefix.formObj["representationForm"]
.values.repfile_name
: ""
}
/>
</>
@@ -26,11 +26,12 @@ const RepInterestedPartyPerson = (props) => {
setRepresentationSubmit,
setRepFileName,
updateRepresentation,
setSavingStatus,
savingStatus,
} = props;
const required = (value) => (value ? undefined : "Required");
const { acceptedFiles, getRootProps, getInputProps } = useDropzone();
const [savingStatus, setSavingStatus] = useState(false);
setRepFileName(formObj.representationForm.values);
@@ -175,7 +176,7 @@ const RepInterestedPartyPerson = (props) => {
props.props.props.accountDetails
.containerID
}
filenamePrefix={props}
filenamePrefix={props.formObj}
/>
</div>
{props.currentView.caseReference.hasOwnProperty(
@@ -19,7 +19,6 @@ import S78_Questionnaire from "./representationQuestionnaires/representationLPAQ
let RepLPA = (props) => {
let { t } = useTranslation();
const router = useRouter();
const { locale } = router;
const {
@@ -38,9 +37,11 @@ let RepLPA = (props) => {
setQuestionnaireCount,
setRepFileName,
updateRepresentation,
setSavingStatus,
savingStatus,
} = props;
const { acceptedFiles, getRootProps, getInputProps } = useDropzone();
const [savingStatus, setSavingStatus] = useState(false);
const files = acceptedFiles.map((file) => (
<li key={file.path}>
{file.path} - {file.size} bytes
@@ -197,6 +198,13 @@ let RepLPA = (props) => {
) &&
setRepFileName(props.formObj["representationForm"].values);
let filesListObj =
props.formObj.hasOwnProperty("representationForm") &&
props.formObj["representationForm"].hasOwnProperty("values") &&
props.formObj["representationForm"].values.hasOwnProperty("filesList")
? props.formObj["representationForm"].values.filesList
: {};
return (
<>
<div className="govuk-grid-row">
@@ -291,6 +299,35 @@ let RepLPA = (props) => {
>
{" "}
<div className="govuk-form-group govuk-!-margin-bottom-9">
{console.log(
"--------",
props.formObj.hasOwnProperty(
"representationForm"
) &&
props.formObj[
"representationForm"
].hasOwnProperty("values") &&
props.formObj[
"representationForm"
].values.hasOwnProperty(
"filesList"
)
? props.props.props.form[
"representationForm"
].values.filesList
: ""
)}
{/* {props.formObj.hasOwnProperty(
"representationForm"
) &&
props.formObj[
"representationForm"
].hasOwnProperty("values") &&
props.formObj[
"representationForm"
].values.hasOwnProperty(
"filesList"
) && ( */}
<FileUploadField
name={"representationDocuments"}
id={"representationDocuments"}
@@ -302,17 +339,32 @@ let RepLPA = (props) => {
}
hint={"sdsd"}
fileList={
props.props.props.form[
(props.formObj.hasOwnProperty(
"representationForm"
].values.filesList || []
) &&
props.formObj[
"representationForm"
].hasOwnProperty(
"values"
) &&
props.formObj[
"representationForm"
].values.hasOwnProperty(
"filesList"
) &&
props.props.props.form[
"representationForm"
].values.filesList) ||
[]
}
setFilesForRepresentation={[]}
containerID={
props.props.props.accountDetails
.containerID
}
filenamePrefix={props}
filenamePrefix={props.formObj}
/>
{/* // )} */}
</div>
</fieldset>
</>
@@ -434,7 +486,7 @@ let RepLPA = (props) => {
className="govuk-button"
data-module="govuk-button"
>
{t("common:continue-button")}
wwwww {t("common:continue-button")}
</button>
{/* {router.query.state != "edit" && (
<a
@@ -471,8 +523,9 @@ let RepLPA = (props) => {
className="govuk-button progress-save "
onClick={() => {
let valuesObj =
props.props.form[props.form]
.values || {};
props.props.props.form[
props.form
].values || {};
console.log(
"valuesobj:",