chekc box to download questionnaire
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
import { JSONPath as jsonpath } from "jsonpath-plus";
|
||||
import useTranslation from "next-translate/useTranslation";
|
||||
import { useRouter } from "next/router";
|
||||
import { useState } from "react";
|
||||
import { useDropzone } from "react-dropzone";
|
||||
import { useEffect, useState } from "react";
|
||||
import { connect } from "react-redux";
|
||||
import { formValueSelector, reduxForm } from "redux-form";
|
||||
import { reduxForm } from "redux-form";
|
||||
|
||||
import { useSession } from "next-auth/react";
|
||||
import { generateRepPDF, sendEmail, uploadRepFiles } from "../../../actions";
|
||||
@@ -33,9 +32,7 @@ import RepresentationProgress_s78 from "./representationProgress/representationP
|
||||
|
||||
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);
|
||||
|
||||
@@ -97,7 +94,7 @@ let MakeRepresentation = (props) => {
|
||||
let questionnaireCount = updateQuestionnaireCount();
|
||||
|
||||
const isLPA =
|
||||
accountDetails[
|
||||
accountDetails?.[
|
||||
"pinswg_typeofinvolvement@OData.Community.Display.V1.FormattedValue"
|
||||
] == "LPA"
|
||||
? true
|
||||
@@ -164,7 +161,39 @@ let MakeRepresentation = (props) => {
|
||||
return values;
|
||||
};
|
||||
|
||||
isLPA && setRepresentationCapacity("LPA");
|
||||
useEffect(() => {
|
||||
if (isLPA && !currentView?.representationCapacity) {
|
||||
setRepresentationCapacity("LPA");
|
||||
}
|
||||
}, [isLPA, currentView?.representationCapacity, setRepresentationCapacity]);
|
||||
|
||||
const normalizeCapacity = (rawCapacity) => {
|
||||
const normalized = (rawCapacity || "")
|
||||
.toString()
|
||||
.toLowerCase()
|
||||
.replace(/(\band|[\s\-\+\(\)\,\&])/g, "");
|
||||
|
||||
const capacityMap = {
|
||||
appellant: "appellant",
|
||||
apelydd: "appellant",
|
||||
agent: "agent",
|
||||
asiant: "agent",
|
||||
interestedparty: "interestedparty",
|
||||
lpa: "lpa",
|
||||
landowner: "landowner",
|
||||
[t("myrepresentations:capacity-options-arr-appellant")
|
||||
.toLowerCase()
|
||||
.replace(/(\band|[\s\-\+\(\)\,\&])/g, "")]: "appellant",
|
||||
[t("myrepresentations:capacity-options-arr-agent")
|
||||
.toLowerCase()
|
||||
.replace(/(\band|[\s\-\+\(\)\,\&])/g, "")]: "agent",
|
||||
[t("myrepresentations:capacity-options-arr-interested")
|
||||
.toLowerCase()
|
||||
.replace(/(\band|[\s\-\+\(\)\,\&])/g, "")]: "interestedparty"
|
||||
};
|
||||
|
||||
return capacityMap[normalized] || normalized || "false";
|
||||
};
|
||||
|
||||
const getCasePath = () => {
|
||||
switch (currentType) {
|
||||
@@ -257,6 +286,9 @@ let MakeRepresentation = (props) => {
|
||||
})[0];
|
||||
}
|
||||
|
||||
const safeDetailsObj = detailsObj || {};
|
||||
const safeResultsObj = resultsObj || {};
|
||||
|
||||
const buildRepsArr = (detailsObj) => {
|
||||
const buildArr = [];
|
||||
const todaysDate = new Date();
|
||||
@@ -440,15 +472,10 @@ let MakeRepresentation = (props) => {
|
||||
);
|
||||
}
|
||||
|
||||
const capacity = getNormalizedCapacity();
|
||||
const capacity = normalizeCapacity(getNormalizedCapacity());
|
||||
|
||||
switch (capacity) {
|
||||
case "appellant":
|
||||
case "apelydd":
|
||||
case "apelydd":
|
||||
case t(
|
||||
"myrepresentations:capacity-options-arr-appellant"
|
||||
).toLowerCase(): {
|
||||
case "appellant": {
|
||||
const Component =
|
||||
appealType === 846040002
|
||||
? ConsultationAppellant
|
||||
@@ -463,7 +490,6 @@ let MakeRepresentation = (props) => {
|
||||
);
|
||||
}
|
||||
|
||||
case "lpa":
|
||||
case "lpa": {
|
||||
return (
|
||||
<RepLPA
|
||||
@@ -480,12 +506,7 @@ let MakeRepresentation = (props) => {
|
||||
);
|
||||
}
|
||||
|
||||
case "agent":
|
||||
case "asiant":
|
||||
case "asiant":
|
||||
case t(
|
||||
"myrepresentations:capacity-options-arr-agent"
|
||||
).toLowerCase(): {
|
||||
case "agent": {
|
||||
const Component =
|
||||
appealType === 846040002 ? ConsultationAgent : RepAgent;
|
||||
return (
|
||||
@@ -498,10 +519,7 @@ let MakeRepresentation = (props) => {
|
||||
);
|
||||
}
|
||||
|
||||
case "interestedparty":
|
||||
case t(
|
||||
"myrepresentations:capacity-options-arr-interested"
|
||||
).toLowerCase(): {
|
||||
case "interestedparty": {
|
||||
const Component =
|
||||
appealType === 846040002
|
||||
? ConsultationInterestedPartyPerson
|
||||
@@ -642,7 +660,7 @@ let MakeRepresentation = (props) => {
|
||||
pinswg_siteaddressline2,
|
||||
pinswg_siteaddresstown,
|
||||
pinswg_siteaddresspostcode
|
||||
} = detailsObj;
|
||||
} = safeDetailsObj;
|
||||
return [
|
||||
pinswg_siteaddressline1,
|
||||
pinswg_siteaddressline2,
|
||||
@@ -671,26 +689,28 @@ let MakeRepresentation = (props) => {
|
||||
caseReferenceObj.repDetails.incidentid,
|
||||
caseRef: currentRef,
|
||||
casereference: currentRef,
|
||||
pinswg_questionnaireduedate: detailsObj.pinswg_questionnaireduedate,
|
||||
pinswg_questionnaireduedate:
|
||||
safeDetailsObj.pinswg_questionnaireduedate,
|
||||
pinswg_statementduedate:
|
||||
detailsObj.pinswg_statementduedate ||
|
||||
detailsObj.pinswg_endofrepresentationperiod,
|
||||
safeDetailsObj.pinswg_statementduedate ||
|
||||
safeDetailsObj.pinswg_endofrepresentationperiod,
|
||||
pinswg_statementsduedate:
|
||||
detailsObj.pinswg_statementsduedate ||
|
||||
detailsObj.pinswg_endofrepresentationperiod,
|
||||
safeDetailsObj.pinswg_statementsduedate ||
|
||||
safeDetailsObj.pinswg_endofrepresentationperiod,
|
||||
pinswg_finalcommentsduedate:
|
||||
detailsObj.pinswg_finalcommentsduedate ||
|
||||
detailsObj.pinswg_endofrepresentationperiod,
|
||||
safeDetailsObj.pinswg_finalcommentsduedate ||
|
||||
safeDetailsObj.pinswg_endofrepresentationperiod,
|
||||
pinswg_name: currentRef,
|
||||
firstname: accountDetails.firstname,
|
||||
lastname: accountDetails.lastname,
|
||||
emailAddress: accountDetails.emailaddress1,
|
||||
siteAddress: getSiteAddress(),
|
||||
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_siteaddressline1: safeDetailsObj.pinswg_siteaddressline1,
|
||||
pinswg_siteaddressline2: safeDetailsObj.pinswg_siteaddressline2,
|
||||
pinswg_siteaddresstown: safeDetailsObj.pinswg_siteaddresstown,
|
||||
pinswg_siteaddresspostcode:
|
||||
safeDetailsObj.pinswg_siteaddresspostcode,
|
||||
pinswg_lpareference: safeResultsObj?.pinswg_lpareference,
|
||||
representationCapacity: getRepresentationCapacity(),
|
||||
locale: router.locale
|
||||
};
|
||||
@@ -698,19 +718,19 @@ let MakeRepresentation = (props) => {
|
||||
const formattedValues = {
|
||||
...values,
|
||||
...baseBody,
|
||||
_pinswg_appellant_value: detailsObj._pinswg_appellant_value,
|
||||
_pinswg_appellant_value: safeDetailsObj._pinswg_appellant_value,
|
||||
"_pinswg_appellant_value@OData.Community.Display.V1.FormattedValue":
|
||||
detailsObj[
|
||||
safeDetailsObj[
|
||||
"_pinswg_appellant_value@OData.Community.Display.V1.FormattedValue"
|
||||
],
|
||||
_pinswg_localplanningauthority_value:
|
||||
detailsObj._pinswg_localplanningauthority_value ||
|
||||
detailsObj._pinswg_associatedlpa_value,
|
||||
safeDetailsObj._pinswg_localplanningauthority_value ||
|
||||
safeDetailsObj._pinswg_associatedlpa_value,
|
||||
"_pinswg_localplanningauthority_value@OData.Community.Display.V1.FormattedValue":
|
||||
detailsObj[
|
||||
safeDetailsObj[
|
||||
"_pinswg_localplanningauthority_value@OData.Community.Display.V1.FormattedValue"
|
||||
] ||
|
||||
detailsObj[
|
||||
safeDetailsObj[
|
||||
"_pinswg_associatedlpa_value@OData.Community.Display.V1.FormattedValue"
|
||||
]
|
||||
};
|
||||
@@ -769,7 +789,9 @@ let MakeRepresentation = (props) => {
|
||||
uploadRepresentationFiles(filesWithLinks);
|
||||
};
|
||||
|
||||
const isSubmitted = currentView.representationSubmit === "true";
|
||||
const isSubmitted =
|
||||
currentView.representationSubmit === true ||
|
||||
currentView.representationSubmit === "true";
|
||||
|
||||
if (isSubmitted) {
|
||||
sendEmailIfNeeded();
|
||||
@@ -787,6 +809,10 @@ let MakeRepresentation = (props) => {
|
||||
const onHandleSubmit = (values) => {
|
||||
values = setRepFileName(values);
|
||||
|
||||
if (!caseReferenceObj?.currentReference) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Determine case data source
|
||||
const getCaseDetailsSource = () => {
|
||||
if (router.query?.state === "edit") {
|
||||
@@ -905,9 +931,7 @@ let MakeRepresentation = (props) => {
|
||||
if (hasNoCapacity) {
|
||||
const capacity = isLPA
|
||||
? "LPA"
|
||||
: values.representationCapacity
|
||||
.replace(/(\band|[\s\-\+\(\)\,\&])/g, "")
|
||||
.toLowerCase();
|
||||
: normalizeCapacity(values.representationCapacity);
|
||||
setRepresentationCapacity(capacity);
|
||||
} else {
|
||||
if (repType === "Questionnaire") {
|
||||
@@ -1038,9 +1062,9 @@ let MakeRepresentation = (props) => {
|
||||
{t("myrepresentations:statements-due-label")}:{" "}
|
||||
<span className="govuk-body-s">
|
||||
{formatDates(
|
||||
detailsObj.pinswg_statementduedate ||
|
||||
detailsObj.pinswg_statementsduedate ||
|
||||
detailsObj.pinswg_endofrepresentationperiod
|
||||
safeDetailsObj.pinswg_statementduedate ||
|
||||
safeDetailsObj.pinswg_statementsduedate ||
|
||||
safeDetailsObj.pinswg_endofrepresentationperiod
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
@@ -1052,7 +1076,7 @@ let MakeRepresentation = (props) => {
|
||||
<div className="govuk-body-s">
|
||||
{t("myrepresentations:marine-impact-report")}:{" "}
|
||||
<span className="govuk-body-s">
|
||||
{formatDates(detailsObj.pinswg_consultationclose)}
|
||||
{formatDates(safeDetailsObj.pinswg_consultationclose)}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
@@ -1062,7 +1086,7 @@ let MakeRepresentation = (props) => {
|
||||
<div className="govuk-body-s">
|
||||
{t("myrepresentations:consultation-close-label")}:{" "}
|
||||
<span className="govuk-body-s">
|
||||
{formatDates(detailsObj.pinswg_consultationclose)}
|
||||
{formatDates(safeDetailsObj.pinswg_consultationclose)}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
@@ -1075,7 +1099,7 @@ let MakeRepresentation = (props) => {
|
||||
<div className="govuk-body-s">
|
||||
{t("myrepresentations:final-comments-due-label")}:{" "}
|
||||
<span className="govuk-body-s">
|
||||
{formatDates(detailsObj.pinswg_finalcommentsduedate)}
|
||||
{formatDates(safeDetailsObj.pinswg_finalcommentsduedate)}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
@@ -1207,8 +1231,6 @@ const mapDispatchToProps = (dispatch) => {
|
||||
};
|
||||
};
|
||||
|
||||
const selector = formValueSelector("representationForm");
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
|
||||
Reference in New Issue
Block a user