This commit is contained in:
2022-12-16 11:36:01 +00:00
parent f6d934d951
commit 98aefdd867
36 changed files with 1258 additions and 371 deletions
+167 -20
View File
@@ -3,7 +3,7 @@ import { useState, useEffect } from "react";
import { useRouter } from "next/router";
import useTranslation from "next-translate/useTranslation";
import jsonpath from "jsonpath";
import _ from "lodash";
import _, { property } from "lodash";
import {
Field,
FieldArray,
@@ -28,6 +28,12 @@ import RepInterestedPartyPerson from "./representationInterestedPartyPerson";
import RepLandOwner from "./representationLandowner";
import RepCompleteSubmit from "./representationCompleteSubmit";
import { useSession, signIn, signOut } from "next-auth/react";
import {
updateCase,
patchCase,
uploadRepFiles,
sendEmail,
} from "../../../actions";
import {
RenderPickList,
@@ -76,6 +82,18 @@ let MakeRepresentation = (props) => {
casesObj = Object.assign({}, ...casesObj);
var detailsObj = {};
currentType == "searchResultsObj"
? (casesObj = jsonpath.query(
setCaseQueryObj,
'$..[?(@.title=="' + caseReference + '")]'
))
: (casesObj = jsonpath.query(
setCaseQueryObj,
'$..[?(@.reference=="' + caseReference + '")]'
));
const capacityOptionsArr = [
"Appellant",
"Agent",
@@ -129,6 +147,7 @@ let MakeRepresentation = (props) => {
currentView={currentView}
setSubmitBack={setSubmitBack}
props={props}
caseReference={caseReference}
/>
);
break;
@@ -214,31 +233,159 @@ let MakeRepresentation = (props) => {
}
};
const updateRepresentation = async (
values,
sendSavedEmail,
useSaveStatus
) => {
let incidentId = props.appealType.caseReference.incidentid;
let updateBody = values || {};
// "pinswg_name": "2022-11-29-IP-REP_BOND_1",
const repDate = new Date();
let day = repDate.getDate();
let month = repDate.getMonth() + 1;
let year = repDate.getFullYear();
const repType = "";
switch (values.representationCapacity) {
case "Appellant":
repType = "APPELLANT";
break;
case "Agent":
repType = "AGENT";
break;
case "Interested Party/Person":
repType = "IP";
break;
case "Land Owner":
repType = "LO";
break;
default:
// code block
}
Object.assign(updateBody, {
"pinswg_name":
year +
"-" +
month +
"-" +
day +
"-" +
repType +
"-REP" +
"_" +
props.props.accountDetails.accountDetails.lastname,
"containerID": props.props.accountDetails.containerID,
});
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];
}
});
//console.log(updateBody);
window.alert(`form is :\n\n${JSON.stringify(updateBody, null, 2)}`);
const reference = "PEDW-PARTIAL-REP";
const templateId = "021b0a7b-df00-41f1-b94e-c269bee98c75";
const emailAddress = props.props.accountDetails.loggedinUserEmail;
const personalisation = {
"caseReference": props.caseReference,
"emailAddress": props.props.accountDetails.loggedinUserEmail,
"returnLink": "",
"linkExpiry": 10 * 60,
};
props.currentView.representationSubmit == "true" &&
(sendSavedEmail == true &&
sendEmail(templateId, emailAddress, personalisation, reference),
useSaveStatus &&
router.replace(
router.locale != "en"
? router.locale + "/myportal"
: "/myportal"
));
};
const onHandleSubmit = (values) => {
// console.log(
// values,
// values.representationCapacity,
// currentView.representationCapacity
// );
currentView.representationSubmit != true
? // console.log(
// values,
// values.representationCapacity,
// currentView.representationCapacity
// );
// console.log(_.isEmpty(currentView.representationCapacity));
// console.log(
// values.representationCapacity
// .replace(/(\band|[\s\-\+\(\)\,\&])/g, "")
// .toLowerCase() == currentView.representationCapacity
// );
// console.log(_.isEmpty(currentView.representationCapacity));
// console.log(
// values.representationCapacity
// .replace(/(\band|[\s\-\+\(\)\,\&])/g, "")
// .toLowerCase() == currentView.representationCapacity
// );
_.isEmpty(currentView.representationCapacity)
? setRepresentationCapacity(
values.representationCapacity
.replace(/(\band|[\s\-\+\(\)\,\&])/g, "")
.toLowerCase()
)
: setRepresentationSubmit("true");
_.isEmpty(currentView.representationCapacity)
? setRepresentationCapacity(
values.representationCapacity
.replace(/(\band|[\s\-\+\(\)\,\&])/g, "")
.toLowerCase()
)
: setRepresentationSubmit(true)
: currentView.representationSubmit == true &&
(console.log("capacity", currentView.representationCapacity),
console.log("has errors:", props.invalid),
props.invalid == false &&
updateRepresentation(values, false, false),
uploadRepresentationFiles(values),
setRepresentationSubmitConfirmation(true));
window.alert(`You submitted:\n\n${JSON.stringify(values, null, 2)}`);
};
const uploadRepresentationFiles = (values) => {
// get filelists from values object
let fileListObj = _.filter(values, function (v, key) {
return _.includes(key, "representationDocuments");
});
console.log(fileListObj);
console.log(
"\n////////////////////////\n upload files:",
values.containerID
);
var dataObj = values;
for (let key in dataObj) {
_.includes(key, "representationDocuments") == true &&
delete dataObj[key];
}
uploadRepFiles(
dataObj,
fileListObj,
values.containerID,
props.caseReference
).then((data) => {
//console.log("hello", data);
return data;
});
};
const repForm = props.props.form;
// console.log(
@@ -312,7 +459,7 @@ const mapStateToProps = (state) => {
const mapDispatchToProps = (dispatch) => {
return {
setRepresentationCapacity: (representationCapacity) => {
dispatch(reset("representationForm"));
//dispatch(reset("representationForm"));
dispatch(setRepresentationCapacity(representationCapacity));
},
setRepresentationSubmit: (representationSubmit) => {