import { JSONPath as jsonpath } from "jsonpath-plus"; import _ from "lodash"; import useTranslation from "next-translate/useTranslation"; import { useRouter } from "next/router"; import { useEffect, useState } from "react"; import { useDropzone } from "react-dropzone"; import { connect } from "react-redux"; import { formValueSelector, reduxForm } from "redux-form"; import { signIn, useSession } from "next-auth/react"; import { generateRepPDF, sendEmail, uploadRepFiles } from "../../../actions"; import { formatDates, updateLinks } from "../../../components/utils"; import { setRepresentationCapacity, setRepresentationMessageSent, setRepresentationReset, setRepresentationSubmit, setRepresentationSubmitConfirmation, } from "../../../store/currentView/action"; import RepAgent from "./representationAgent"; import RepAppellant from "./representationAppellant"; import ConsultationAppellant from "./consultationAppellant"; import ConsultationAgent from "./consultationAgent"; import RepCapacitySelection from "./representationCapacitySelection"; import RepCompleteSubmit from "./representationCompleteSubmit"; import RepInterestedPartyPerson from "./representationInterestedPartyPerson"; import ConsultationInterestedPartyPerson from "./consultationInterestedPartyPerson"; import RepLPA from "./representationLPA"; import RepLPACapacitySelection from "./representationLPACapacitySelection"; import RepLandOwner from "./representationLandowner"; import RepresentationProgress_enforcement from "./representationProgress/representationProgress_enforcement"; import RepresentationProgress_s78 from "./representationProgress/representationProgress_s78"; let MakeRepresentation = (props) => { let { t } = useTranslation(); const { acceptedFiles, getRootProps, getInputProps } = useDropzone(); const [clearRepForm, setClearRepForm] = useState(false); const [savingStatus, setSavingStatus] = useState(false); const [finaliseAppealProcess, setFinaliseAppealProcess] = useState(false); //const [questionnaireCount, setQuestionnaireCount] = useState(0); const { data: session } = useSession(); const router = useRouter(); const { locale } = router; const { caseReference, myCases, myRepresentations, watchedCases, awaitingSubmission, searchResultsObj, representationSubmit, currentType, currentView, setRepresentationCapacity, setRepresentationSubmit, setSubmitBack, handleSubmit, setRepresentationSubmitConfirmation, setRepresentationMessageSent, setShowQuestionnaireSection, showQuestionnaireSection, initialValues, setCurrentReference, } = props; const formObj = props.props.form; let setCaseQueryObj = props[currentType] || {}; var casesObj = {}; const appealType = currentView.caseReference.appealType; const accountDetails = props.props.accountDetails.accountDetails; const caseReferenceObj = props.props.currentView.caseReference; const updateQuestionnaireCount = () => { { switch (appealType) { case 846040000: case 846040001: 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 isLPA = accountDetails[ "pinswg_typeofinvolvement@OData.Community.Display.V1.FormattedValue" ] == "LPA" ? true : false; // const isNRW = accountDetails.emailaddress1.includes( // "@cyfoethnaturiolcymru.gov.uk" // ) // ? true // : false; const isNRW = accountDetails.emailaddress1.includes("@rdbtech.co.uk") ? true : false; const setRepFileName = (values) => { //console.log("---------------\n", values); if ( values.hasOwnProperty("representationCapacity") && values.hasOwnProperty("representationType") ) { let repType = ""; let repCap = ""; const repDate = new Date(); let day = ("0" + repDate.getDate()).slice(-2); let month = ("0" + (repDate.getMonth() + 1)).slice(-2); let year = repDate.getFullYear(); switch (values.representationCapacity) { case t("myrepresentations:capacity-options-arr-appellant"): repCap = "APP"; break; case t("myrepresentations:capacity-options-arr-agent"): repCap = "APP"; //set as App even tho agent as is from an appeallant by proxy break; case t("myrepresentations:capacity-options-arr-interested"): repCap = "IP"; break; case "Land Owner": repCap = "LO"; break; case "lpa": case "LPA": repCap = "LPA"; case "NRW": repCap = "NRW"; break; default: // code block } switch (values.representationType) { case "Statement": repType = "Statement"; break; case "Statement of common ground": repType = "SCG"; break; case "Written statement": repType = "WS"; break; case "Written statement of evidence": repType = "WSE"; break; case "Questionnaire": repType = "Questionnaire"; break; case "Final comments": repType = "Comments"; break; case "Consultation Response": repType = "Consultation_Response"; break; case "Local Impact Report": repType = "Local_Impact_Report"; break; case "Marine Impact Report": repType = "Marine_Impact_Report"; break; case "Other": repType = "OTHER"; break; default: // code block } Object.assign(values, { "repfile_name": values.hasOwnProperty("repfile_name") ? values.repfile_name : year + "-" + month + "-" + day + "-" + ("0" + repDate.getHours()).slice(-2) + ":" + ("0" + repDate.getMinutes()).slice(-2) + ":" + ("0" + repDate.getSeconds()).slice(-2) + "_-_" + repCap + "_-_" + repType + "_-_" + (isLPA ? values.onBehalfOfLPA.replace( /[\s~`!@#$%^&*(){}\[\];:"'<,.>?\/\\|_+=-]/g, "" ) : values.lastname.replace( /[\s~`!@#$%^&*(){}\[\];:"'<,.>?\/\\|_+=-]/g, "" ) + "_" + values.firstname.replace( /[\s~`!@#$%^&*(){}\[\];:"'<,.>?\/\\|_+=-]/g, "" )), }); } return values; }; isLPA && setRepresentationCapacity("LPA"); currentType == "searchResultsObj" ? (casesObj = jsonpath({ path: '$..[?(@ && @.title=="' + caseReference + '")]', json: setCaseQueryObj, eval: true, })) : currentType == "watchedCases" ? (casesObj = jsonpath({ path: '$..[?(@ && @.ticketnumber=="' + caseReference + '")]', json: watchedCases, eval: true, })) : (casesObj = jsonpath({ path: '$..[?(@ && @.reference=="' + caseReference + '")]', json: setCaseQueryObj, eval: true, })); casesObj = Object.assign({}, ...casesObj); var detailsObj = {}; const capacityOptionsArr = [ t("myrepresentations:capacity-options-arr-appellant"), t("myrepresentations:capacity-options-arr-agent"), ]; appealType != 846040017 ? capacityOptionsArr.push( t("myrepresentations:capacity-options-arr-interested") ) : caseReferenceObj.specialistProcess != 846040000 && capacityOptionsArr.push( t("myrepresentations:capacity-options-arr-interested") ); let setCaseDetailsObj = router.query.hasOwnProperty("state") ? router.query.state == "edit" ? props.props.myRepresentations.myRepresentations : props.props.searchResultsObj.searchDetailsObj : props.currentType == "watchedCases" ? props.props.watchedCases.watchedCasesDetails : props.props.searchResultsObj.searchDetailsObj; let setCaseResultsObj = router.query.hasOwnProperty("state") ? router.query.state == "edit" ? props.props.myRepresentations.myRepresentations : props.props.searchResultsObj.searchResultsObj : props.currentType == "watchedCases" ? props.props.watchedCases.watchedCasesDetails : props.props.searchResultsObj.searchResultsObj; var detailsObj = {}; var resultsObj = {}; resultsObj = jsonpath({ path: '$..[?(@ && @.ticketnumber=="' + currentView.caseReference.currentReference + '")]', json: setCaseResultsObj, eval: true, }); resultsObj = resultsObj[0]; detailsObj = router.query.hasOwnProperty("state") ? router.query.state == "edit" ? jsonpath({ path: '$..[?(@ && @.repfile_name =="' + router.query.created + '")]', json: setCaseDetailsObj, eval: true, }) : jsonpath({ path: '$..[?(@ && @.pinswg_name =="' + currentView.caseReference.currentReference + '")]', json: setCaseDetailsObj, eval: true, }) : jsonpath({ path: '$..[?(@ && @.pinswg_name =="' + currentView.caseReference.currentReference + '")]', json: setCaseDetailsObj, eval: true, }); detailsObj = detailsObj[0]; const buildRepsArr = (detailsObj) => { let buildArr = []; // console.log(appealType, ""); let todaysDate = new Date(); const isDNS = appealType == 846040011; const isSIPS = appealType == 846040002; let startDate; let questionnaireDate; let finalCommentsDate; let statementDueDate; isDNS ? ((startDate = new Date( detailsObj.pinswg_applicationacceptedasvalid )), (questionnaireDate = new Date( new Date( detailsObj.pinswg_endofrepresentationperiod ).setHours(23, 59, 59, 999) )), (finalCommentsDate = new Date( new Date( detailsObj.pinswg_endofrepresentationperiod ).setHours(23, 59, 59, 999) )), (statementDueDate = new Date( new Date( detailsObj.pinswg_endofrepresentationperiod ).setHours(23, 59, 59, 999) ))) : ((startDate = new Date( detailsObj.pinswg_startdate || detailsObj.pinswg_startdates )), (questionnaireDate = new Date( new Date(detailsObj.pinswg_questionnaireduedate).setHours( 23, 59, 59, 999 ) )), (finalCommentsDate = new Date( new Date(detailsObj.pinswg_finalcommentsduedate).setHours( 23, 59, 59, 999 ) )), (statementDueDate = new Date( new Date( detailsObj.pinswg_statementduedate || detailsObj.pinswg_statementsduedate ).setHours(23, 59, 59, 999) ))); isLPA && appealType != 846040019 && appealType != 846040011 && appealType != 846040015 && appealType != 846040016 && todaysDate >= startDate && todaysDate <= finalCommentsDate && buildArr.push("Questionnaire"); isLPA && isDNS && appealType != 846040019 && todaysDate >= startDate && todaysDate <= finalCommentsDate && buildArr.push("Local Impact Report"); isLPA && isDNS && appealType != 846040019 && todaysDate >= startDate && todaysDate <= finalCommentsDate && buildArr.push("Statement"); !isDNS && appealType != 846040004 && todaysDate >= startDate && todaysDate <= statementDueDate && buildArr.push("Statement"); isDNS && !isLPA && todaysDate >= startDate && todaysDate <= statementDueDate && buildArr.push("Statement"); (appealType != 846040004 || (appealType == 846040015 && currentView.caseReference.specialistProcess != 846040001)) && todaysDate >= statementDueDate && todaysDate <= finalCommentsDate && buildArr.push("Final comments"); appealType == 846040004 && currentView.caseReference.specialistProcess != 846040001 && todaysDate >= statementDueDate && todaysDate <= finalCommentsDate && buildArr.push("Final comments"); //is LPA Advert part 3 no statement isLPA && appealType == 846040018 && currentView.caseReference.specialistProcess == 846040000 && buildArr.pop("Statements"); //console.log("is this a sip......", isSIPS, !isLPA); isSIPS && buildArr.push("Consultation Response"); isSIPS && buildArr.push("Local Impact Report"); isSIPS && isNRW && buildArr.push("Marine Impact Report"); return buildArr; }; const repCapacityType = () => { return _.isEmpty(formObj["representationForm"]) ? false : _.isEmpty(formObj["representationForm"].values) ? false : _.isEmpty( formObj["representationForm"].values.representationCapacity ) ? false : formObj["representationForm"].values.representationCapacity .replace(/(\band|[\s\-\+\(\)\,\&])/g, "") .toLowerCase(); }; const whichControl = () => { let SipsOrRep; if ( isLPA && _.isEmpty(currentView.representationCapacity) // || // (isLPA && // currentView.caseReference.hasOwnProperty("repDetails") && // !currentView.caseReference.repDetails.representationCapacity) ) { return ( //setRepresentationCapacity("LPA"), ); } else { switch ( ( currentView.representationCapacity || (currentView.caseReference.hasOwnProperty("repDetails") && currentView.caseReference.repDetails .representationCapacity) || "false" ).toLowerCase() ) { case false: ; break; case "appellant": case "apelydd": case "Apelydd": case t( "myrepresentations:capacity-options-arr-appellant" ).toLocaleLowerCase(): //setRepresentationCapacity("appellant"); SipsOrRep = appealType == 846040002 ? ConsultationAppellant : RepAppellant; return ( ); break; case "lpa": case "LPA": //setRepresentationCapacity("appellant"); //setRepresentationCapacity("LPA"); // useEffect(() => { // setRepresentationCapacity("LPA"); // }, []); console.log(appealType); return ( ); break; case "agent": case "Asiant": case "asiant": case t( "myrepresentations:capacity-options-arr-agent" ).toLowerCase(): //setRepresentationCapacity("agent"); SipsOrRep = appealType == 846040002 ? ConsultationAgent : RepAgent; return ( ); break; case "interestedparty": case t( "myrepresentations:capacity-options-arr-interested" ).toLowerCase(): // setRepresentationCapacity("interestedpartyperson"); SipsOrRep = appealType == 846040002 ? ConsultationInterestedPartyPerson : RepInterestedPartyPerson; return ( ); break; case "landowner": //setRepresentationCapacity("landowner"); return ( ); break; default: return ( ); } } }; const whichProgress = () => { { switch (appealType) { case 846040000: case 846040001: case 846040025: case 846040004: case 846040018: case 846040003: case 846040009: case 846040008: case 846040017: return ( ); break; case 846040005: case 846040006: case 846040007: return ( ); break; default: return <>; break; } } }; 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); } function removeEmptyObjects(arr) { return arr.filter((obj) => Object.keys(obj).length > 0); } blobList = removeNullObjects(blobList); 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, useSaveStatus ) => { let incidentId = props.appealType.caseReference.incidentid; let updateBody = values || {}; const buildFileArray = []; let newbuildArr = []; setSavingStatus(useSaveStatus); Object.assign(values, { "containerID": props.props.accountDetails.containerID, "appealType": appealType || caseReferenceObj.repDetails.appealType, "incidentID": caseReferenceObj.incidentid || caseReferenceObj.repDetails.incidentid, "caseRef": caseReferenceObj.currentReference, "casereference": caseReferenceObj.currentReference, "pinswg_questionnaireduedate": detailsObj.pinswg_questionnaireduedate, "pinswg_statementduedate": detailsObj.pinswg_statementduedate || detailsObj.pinswg_endofrepresentationperiod, "pinswg_statementsduedate": detailsObj.pinswg_statementsduedate || detailsObj.pinswg_endofrepresentationperiod, "pinswg_finalcommentsduedate": detailsObj.pinswg_finalcommentsduedate || detailsObj.pinswg_endofrepresentationperiod, "pinswg_name": caseReferenceObj.currentReference, "firstname": accountDetails.firstname, "lastname": accountDetails.lastname, "emailAddress": accountDetails.emailaddress1, "siteAddress": detailsObj.pinswg_siteaddressline1 + (detailsObj.pinswg_siteaddressline2 != null ? " " + detailsObj.pinswg_siteaddressline2 + " " : " ") + detailsObj.pinswg_siteaddresstown + " " + detailsObj.pinswg_siteaddresspostcode, "pinswg_siteaddressline1": detailsObj.pinswg_siteaddressline1, "pinswg_siteaddressline2": detailsObj.pinswg_siteaddressline2, "pinswg_siteaddresstown": detailsObj.pinswg_siteaddresstown, "pinswg_siteaddresspostcode": detailsObj.pinswg_siteaddresspostcode, "pinswg_lpareference": resultsObj?.pinswg_lpareference, "_pinswg_appellant_value": detailsObj["_pinswg_appellant_value"], "_pinswg_appellant_value@OData.Community.Display.V1.FormattedValue": detailsObj[ "_pinswg_appellant_value@OData.Community.Display.V1.FormattedValue" ], "_pinswg_localplanningauthority_value": detailsObj["_pinswg_localplanningauthority_value"] || detailsObj["_pinswg_associatedlpa_value"], "_pinswg_localplanningauthority_value@OData.Community.Display.V1.FormattedValue": detailsObj[ "_pinswg_localplanningauthority_value@OData.Community.Display.V1.FormattedValue" ] || detailsObj[ "_pinswg_associatedlpa_value@OData.Community.Display.V1.FormattedValue" ], "representationCapacity": router.query.hasOwnProperty("state") ? router.query.state == "edit" ? props.props.currentView.representationCapacity : values.representationCapacity : isLPA ? "LPA" : values.representationCapacity, "locale": router.locale, }); // "pinswg_name": "2022-11-29-IP-REP_BOND_1", updateBody = setRepFileName(values); Object.assign(updateBody, { "pinswg_name": caseReferenceObj.currentReference, "containerID": props.props.accountDetails.containerID, "appealType": appealType || caseReferenceObj.repDetails.appealType, "casereference": caseReferenceObj.currentReference, "incidentID": caseReferenceObj.incidentid || caseReferenceObj.repDetails.incidentid, "caseRef": caseReferenceObj.currentReference, }); 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]; } }); 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 + "/fymhorth" : "/myportal" )) : useSaveStatus ? (Object.assign(values, { "filesList": props.currentView.fileList, }), (values = updateLinks(values)), uploadRepresentationFiles(values), router.replace( router.locale != "en" ? "/" + router.locale + "/fymhorth" : "/myportal" )) : Object.assign(values, { "filesList": props.currentView.fileList, }), console.log("Rep Updated - ", props.caseReference), (values = updateLinks(values)), uploadRepresentationFiles(values); }; const onHandleSubmit = (values) => { values = setRepFileName(values); //console.log("onHandleSubmit form values - ", JSON.stringify(values)); const buildFileArray = []; //console.log("attached docs: - ", buildFileArray); let setCaseDetailsObj = router.query.hasOwnProperty("state") ? router.query.state == "edit" ? props.props.myRepresentations.myRepresentations : props.props.searchResultsObj.searchDetailsObj : props.currentType == "watchedCases" ? props.props.watchedCases.watchedCasesDetails : props.props.searchResultsObj.searchDetailsObj; router.query.hasOwnProperty("state") && router.query.state == "edit" && setRepresentationSubmit(false); var detailsObj = {}; detailsObj = jsonpath({ path: '$..[?(@ && @.pinswg_name=="' + caseReference + '")]', json: setCaseDetailsObj, eval: true, }); detailsObj = detailsObj[0]; // console.log( // "Has data from form:", // formObj.hasOwnProperty("representationForm") && // formObj.representationForm.hasOwnProperty("values") // ); formObj.hasOwnProperty("representationForm") && !router.query.hasOwnProperty("state") && formObj.representationForm.hasOwnProperty("values") && (Object.assign(values, formObj.representationForm.values), Object.assign(values, { "containerID": props.props.accountDetails.containerID, "appealType": appealType || caseReferenceObj.repDetails.appealType, "incidentID": caseReferenceObj.incidentid || caseReferenceObj.repDetails.incidentid, "caseRef": caseReferenceObj.currentReference, "casereference": caseReferenceObj.currentReference, "pinswg_questionnaireduedate": detailsObj.pinswg_questionnaireduedate, "pinswg_endofrepresentationperiod": detailsObj.pinswg_endofrepresentationperiod, "pinswg_applicationacceptedasvalid": detailsObj.pinswg_applicationacceptedasvalid, "pinswg_statementduedate": detailsObj.pinswg_statementduedate, "pinswg_statementsduedate": detailsObj.pinswg_statementsduedate, "pinswg_finalcommentsduedate": detailsObj.pinswg_finalcommentsduedate, "pinswg_name": caseReferenceObj.currentReference, "firstname": accountDetails.firstname, "lastname": accountDetails.lastname, "emailAddress": accountDetails.emailaddress1, "siteAddress": detailsObj.pinswg_siteaddressline1 + (detailsObj.pinswg_siteaddressline2 != null ? " " + detailsObj.pinswg_siteaddressline2 + " " : " ") + detailsObj.pinswg_siteaddresstown + " " + detailsObj.pinswg_siteaddresspostcode, "pinswg_siteaddressline1": detailsObj.pinswg_siteaddressline1, "pinswg_siteaddressline2": detailsObj.pinswg_siteaddressline2, "pinswg_siteaddresstown": detailsObj.pinswg_siteaddresstown, "pinswg_siteaddresspostcode": detailsObj.pinswg_siteaddresspostcode, "pinswg_lpareference": resultsObj?.pinswg_lpareference, "_pinswg_appellant_value": detailsObj["_pinswg_appellant_value"], "_pinswg_appellant_value@OData.Community.Display.V1.FormattedValue": detailsObj[ "_pinswg_appellant_value@OData.Community.Display.V1.FormattedValue" ], "_pinswg_localplanningauthority_value": detailsObj["_pinswg_localplanningauthority_value"] || detailsObj["_pinswg_associatedlpa_value"], "_pinswg_localplanningauthority_value@OData.Community.Display.V1.FormattedValue": detailsObj[ "_pinswg_localplanningauthority_value@OData.Community.Display.V1.FormattedValue" ] || detailsObj[ "_pinswg_associatedlpa_value@OData.Community.Display.V1.FormattedValue" ], "representationCapacity": router.query.hasOwnProperty("state") ? router.query.state == "edit" ? props.props.currentView.representationCapacity : values.representationCapacity : isLPA ? "LPA" : values.representationCapacity, "locale": router.locale, })); if (currentView.representationSubmit != true) { if (_.isEmpty(currentView.representationCapacity)) { if (isLPA) { setRepresentationCapacity("LPA"); } 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); } } window.scrollTo({ top: 0, behavior: "smooth" }); } else { if (currentView.representationSubmit == true) { console.log("capacity", currentView.representationCapacity); console.log("has errors:", props.invalid); Object.assign(values, { "locale": router.locale, "repComplete": currentView.caseReference.currentReference, }); 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) // ); setFinaliseAppealProcess(true); generateRepPDF( values, props.props.accountDetails.containerID, currentView.caseReference.currentReference ).then((data) => { console.log(data); data.status == "success" && ((values = updateLinks(values)), uploadRepresentationFiles(values), setRepresentationSubmit(true), setRepresentationSubmitConfirmation(true)); }); } else { console.log("not updated"); } } }; 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"); }); // console.log( // "\n////////////////////////\n upload files:", // values.containerID, // "\n////////////////////////\n fileListObj:", // fileListObj, // "\n////////////////////////\n" // ); var dataObj = values; (values = updateLinks(values)), uploadRepFiles( dataObj, [{}], values.containerID, props.caseReference + "/" + dataObj.repfile_name ).then((data) => { return data; }); }; const repForm = props.props.form; return (
{currentView.representationSubmit == true ? ( ) : ( <>

{appealType == 846040002 ? t( "myrepresentations:make-a-consultation-on-label" ) : t( "myrepresentations:make-a-representation-on-label" )}{" "} {currentView.caseReference.currentReference}{" "}

{whichControl()}
{" "}

{t( "myrepresentations:timetable-title" )}{" "}

{currentView.caseReference .appealType == 846040011 || currentView.caseReference .appealType == 846040002 ? t( "myrepresentations:local-impact-report" ) : t( "myrepresentations:questionnaire-due-label" )} : {" "} {detailsObj.hasOwnProperty( "pinswg_questionnaireduedate" ) || detailsObj.hasOwnProperty( "pinswg_endofrepresentationperiod" ) || detailsObj.hasOwnProperty( "pinswg_consultationclose" ) ? formatDates( detailsObj.pinswg_questionnaireduedate || detailsObj.pinswg_endofrepresentationperiod || detailsObj.pinswg_consultationclose ) : "N/A"}
{currentView.caseReference .appealType != 846040002 && (
{t( "myrepresentations:statements-due-label" )} : {" "} {formatDates( detailsObj.pinswg_statementduedate || detailsObj.pinswg_statementsduedate || detailsObj.pinswg_endofrepresentationperiod )}
)} {currentView.caseReference .appealType == 846040002 && isNRW && (
{t( "myrepresentations:marine-impact-report" )} : {" "} {formatDates( detailsObj.pinswg_consultationclose )}
)} {currentView.caseReference .appealType == 846040002 && (
{t( "myrepresentations:consultation-close-label" )} : {" "} {formatDates( detailsObj.pinswg_consultationclose )}
)} {currentView.caseReference .appealType != 846040011 || (currentView.caseReference .appealType != 846040002 && (
{t( "myrepresentations:final-comments-due-label" )} : {" "} {formatDates( detailsObj.pinswg_finalcommentsduedate )}
))}
{formObj.hasOwnProperty( "representationForm" ) && formObj[ "representationForm" ].hasOwnProperty("values") && formObj[ "representationForm" ].values.hasOwnProperty( "representationType" ) && formObj["representationForm"].values .representationType == "Questionnaire" && whichProgress()}
)}
); }; const mapStateToProps = (state) => { return { search: state.search, searchResultsObj: state.searchResultsObj, formData: state.formData, appealType: state.appealType, currentView: state.currentView, myRepresentations: state.myRepresentations, initialValues: state.currentView.caseReference.repDetails, //form: state.form, }; }; const mapDispatchToProps = (dispatch) => { return { setRepresentationCapacity: (representationCapacity) => { dispatch(setRepresentationCapacity(representationCapacity)); }, setRepresentationSubmit: (representationSubmit) => { dispatch(setRepresentationSubmit(representationSubmit)); }, setSubmitBack: () => { dispatch(setRepresentationSubmit(false)); }, setRepresentationSubmitConfirmation: () => { dispatch(setRepresentationSubmitConfirmation(true)); }, setRepresentationMessageSent: (messageSent) => { dispatch(setRepresentationMessageSent(messageSent)); }, setRepresentationReset: () => { dispatch(setRepresentationReset()); }, }; }; const selector = formValueSelector("representationForm"); export default connect( mapStateToProps, mapDispatchToProps )( reduxForm({ form: "representationForm", destroyOnUnmount: false, enableReinitialize: true, })(MakeRepresentation) );