hooks fixes and ordering of events
This commit is contained in:
@@ -2,7 +2,7 @@ import { JSONPath as jsonpath } from "jsonpath-plus";
|
||||
import _ from "lodash";
|
||||
import useTranslation from "next-translate/useTranslation";
|
||||
import { useRouter } from "next/router";
|
||||
import { useState } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useDropzone } from "react-dropzone";
|
||||
import { connect } from "react-redux";
|
||||
import { formValueSelector, reduxForm } from "redux-form";
|
||||
@@ -34,6 +34,9 @@ let MakeRepresentation = (props) => {
|
||||
|
||||
const [clearRepForm, setClearRepForm] = useState(false);
|
||||
const [savingStatus, setSavingStatus] = useState(false);
|
||||
const [showQuestionnaireSection, setShowQuestionnaireSection] = useState(1);
|
||||
//const [questionnaireCount, setQuestionnaireCount] = useState(0);
|
||||
|
||||
const { data: session } = useSession();
|
||||
|
||||
const router = useRouter();
|
||||
@@ -60,9 +63,33 @@ let MakeRepresentation = (props) => {
|
||||
let setCaseQueryObj = props[currentType] || {};
|
||||
var casesObj = {};
|
||||
|
||||
const [showQuestionnaireSection, setShowQuestionnaireSection] = useState(1);
|
||||
const [questionnaireCount, setQuestionnaireCount] = useState(0);
|
||||
const updateQuestionnaireCount = () => {
|
||||
{
|
||||
switch (currentView.caseReference.appealType) {
|
||||
case 846040000:
|
||||
case 846040001:
|
||||
case 846040006:
|
||||
case 846040025:
|
||||
case 846040004:
|
||||
case 846040018:
|
||||
case 846040003:
|
||||
case 846040009:
|
||||
case 846040008:
|
||||
return 7;
|
||||
break;
|
||||
case 846040005:
|
||||
case 846040006:
|
||||
case 846040007:
|
||||
return 9;
|
||||
break;
|
||||
default:
|
||||
return 7;
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let questionnaireCount = updateQuestionnaireCount();
|
||||
const setRepFileName = (values) => {
|
||||
//console.log("---------------\n", values);
|
||||
if (
|
||||
@@ -347,12 +374,13 @@ let MakeRepresentation = (props) => {
|
||||
const whichControl = () => {
|
||||
if (isLPA && _.isEmpty(currentView.representationCapacity)) {
|
||||
return (
|
||||
//setRepresentationCapacity("lpa"),
|
||||
<RepLPACapacitySelection
|
||||
formObj={formObj}
|
||||
capacityOptionsArr={capacityOptionsArr}
|
||||
currentType={currentType}
|
||||
casesObj={casesObj}
|
||||
setRepresentationCapacity={"LPA"}
|
||||
setRepresentationCapacity={setRepresentationCapacity}
|
||||
setRepresentationSubmit={setRepresentationSubmit}
|
||||
onHandleSubmit={onHandleSubmit}
|
||||
currentView={currentView}
|
||||
@@ -408,6 +436,12 @@ let MakeRepresentation = (props) => {
|
||||
break;
|
||||
case "lpa":
|
||||
//setRepresentationCapacity("appellant");
|
||||
//setRepresentationCapacity("lpa");
|
||||
// useEffect(() => {
|
||||
// setRepresentationCapacity("lpa");
|
||||
// }, []);
|
||||
|
||||
// console.log(currentView.caseReference.appealType);
|
||||
return (
|
||||
<RepLPA
|
||||
formObj={formObj}
|
||||
@@ -426,7 +460,7 @@ let MakeRepresentation = (props) => {
|
||||
setShowQuestionnaireSection
|
||||
}
|
||||
showQuestionnaireSection={showQuestionnaireSection}
|
||||
setQuestionnaireCount={setQuestionnaireCount}
|
||||
//setQuestionnaireCount={setQuestionnaireCount}
|
||||
questionnaireCount={questionnaireCount}
|
||||
setRepFileName={setRepFileName}
|
||||
updateRepresentation={updateRepresentation}
|
||||
@@ -548,7 +582,7 @@ let MakeRepresentation = (props) => {
|
||||
setShowQuestionnaireSection={
|
||||
setShowQuestionnaireSection
|
||||
}
|
||||
setQuestionnaireCount={setQuestionnaireCount}
|
||||
// setQuestionnaireCount={setQuestionnaireCount}
|
||||
questionnaireCount={questionnaireCount}
|
||||
/>
|
||||
);
|
||||
@@ -566,7 +600,7 @@ let MakeRepresentation = (props) => {
|
||||
setShowQuestionnaireSection={
|
||||
setShowQuestionnaireSection
|
||||
}
|
||||
setQuestionnaireCount={setQuestionnaireCount}
|
||||
//setQuestionnaireCount={setQuestionnaireCount}
|
||||
questionnaireCount={questionnaireCount}
|
||||
/>
|
||||
);
|
||||
@@ -578,6 +612,53 @@ let MakeRepresentation = (props) => {
|
||||
}
|
||||
};
|
||||
|
||||
const sortFileObj = (filelistObj) => {
|
||||
let blobList = filelistObj;
|
||||
|
||||
function removeObjectsWithUndefinedKey(arr, key) {
|
||||
return arr.filter((obj) => obj[key] !== undefined);
|
||||
}
|
||||
|
||||
function removeEmptyObjects(arr) {
|
||||
return arr.filter((obj) => Object.keys(obj).length > 0);
|
||||
}
|
||||
|
||||
blobList = removeEmptyObjects(blobList);
|
||||
blobList = removeObjectsWithUndefinedKey(blobList, "name");
|
||||
|
||||
let buildAppealFilesArray = [];
|
||||
|
||||
let filesUploadObj = field.input.value;
|
||||
|
||||
for (let key in filesUploadObj) {
|
||||
typeof filesUploadObj[key].name != "undefined" &&
|
||||
buildAppealFilesArray.push({
|
||||
"name": filesUploadObj[key].name,
|
||||
"size": filesUploadObj[key].size,
|
||||
});
|
||||
}
|
||||
|
||||
buildAppealFilesArray = buildAppealFilesArray.concat(blobList);
|
||||
|
||||
function removeDuplicates(arr) {
|
||||
const seen = new Set();
|
||||
return arr.filter((obj) => {
|
||||
const serializedObj = JSON.stringify(obj);
|
||||
if (seen.has(serializedObj)) {
|
||||
return false; // Skip this object (duplicate)
|
||||
}
|
||||
seen.add(serializedObj); // Add the serialized object to the "seen" set
|
||||
return true; // Keep this object
|
||||
});
|
||||
}
|
||||
|
||||
buildAppealFilesArray = removeDuplicates(buildAppealFilesArray);
|
||||
|
||||
blobList = buildAppealFilesArray;
|
||||
|
||||
return blobList;
|
||||
};
|
||||
|
||||
const updateRepresentation = async (
|
||||
values,
|
||||
sendSavedEmail,
|
||||
@@ -727,17 +808,18 @@ let MakeRepresentation = (props) => {
|
||||
? router.locale + "/myportal"
|
||||
: "/myportal"
|
||||
))
|
||||
: values.hasOwnProperty("representationDocuments") &&
|
||||
(values.representationDocuments.map((Blob) =>
|
||||
buildFileArray.push({
|
||||
"name": Blob.name,
|
||||
"size": Blob.size,
|
||||
})
|
||||
),
|
||||
Object.assign(values, {
|
||||
"filesList": buildFileArray,
|
||||
})),
|
||||
uploadRepresentationFiles(values),
|
||||
: //values.hasOwnProperty("representationDocuments") &&
|
||||
// sortFileObj()
|
||||
// (values.representationDocuments.map((Blob) =>
|
||||
// buildFileArray.push({
|
||||
// "name": Blob.name,
|
||||
// "size": Blob.size,
|
||||
// })
|
||||
// ),
|
||||
// Object.assign(values, {
|
||||
// "filesList": buildFileArray,
|
||||
// })),
|
||||
uploadRepresentationFiles(values),
|
||||
generateRepPDF(
|
||||
values,
|
||||
props.props.accountDetails.containerID,
|
||||
@@ -929,18 +1011,19 @@ 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");
|
||||
}
|
||||
// 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
|
||||
|
||||
Reference in New Issue
Block a user