import _ from "lodash"; import useTranslation from "next-translate/useTranslation"; import { useRouter } from "next/router"; import { useState } from "react"; import { useDropzone } from "react-dropzone"; import { connect } from "react-redux"; import { generateRepPDF } from "../../../actions/services/documentService"; import RepComplete from "./representationComplete"; import RepLPAQuestionnaireCheck_enforcement from "./representationQuestionnairesCheck/representationLPAQuestionnaireCheck_enforcement"; import RepLPAQuestionnaireCheck_s78 from "./representationQuestionnairesCheck/representationLPAQuestionnaireCheck_s78"; import Link from "next/link"; import { bytesToSize, getThumbnailIconByExtension, formatDates, updateLinks, getDocLink } from "../../utils"; import { setCurrentReference, setCurrentView } from "../../../store/currentView/action"; const RepCompleteSubmit = (props) => { let { t } = useTranslation(); const [confirmSections, setConfirmSections] = useState(false); const [downloadQuestionnaire, setDownloadQuestionnaire] = useState(false); const [downloadInProgress, setDownloadInProgress] = useState(false); const router = useRouter(); const { locale } = router; const { formObj, appellantApplicantRepresentationArr, setRepresentationCapacity, setRepresentationSubmit, currentView, setSubmitBack, setRepresentationSubmitConfirmation, setRepresentationMessageSent, setRepresentationReset, setShowQuestionnaireSection, showQuestionnaireSection, questionnaireCount, finaliseAppealProcess, setCurrentReference, docsOffline } = props; let ShowDocLinks = getDocLink(docsOffline); const { acceptedFiles, getRootProps, getInputProps } = useDropzone(); const files = acceptedFiles.map((file) => (
  • {file.path} - {file.size} bytes
  • )); let repFormData = formObj.representationForm.values; repFormData = updateLinks(repFormData); //const repDate = new Date(); // let day = repDate.getDate(); // let month = repDate.getMonth() + 1; // let year = repDate.getFullYear(); // let repType = ""; // switch (repFormData.representationCapacity) { // case t("myrepresentations:capacity-options-arr-appellant"): // repType = "APP"; // break; // case t("myrepresentations:capacity-options-arr-agent"): // repType = "AGENT"; // break; // case t("myrepresentations:capacity-options-arr-interested"): // repType = "IP"; // break; // case "Land Owner": // repType = "LO"; // break; // case "lpa": // repType = "LPA"; // break; // default: // // code block // } // Object.assign(repFormData, { // "repfile_name": repFormData.hasOwnProperty("repfile_name") // ? repFormData.repfile_name // : year + // "-" + // month + // "-" + // day + // "-" + // repDate.getHours() + // repDate.getMinutes() + // repDate.getSeconds() + // "_" + // repType + // "_" + // props.props.props.accountDetails.accountDetails.lastname + // "_" + // props.props.props.accountDetails.accountDetails.firstname, // "pinswg_name": props.props.currentView.caseReference.currentReference, // "containerID": props.props.props.accountDetails.containerID, // "appealType": props.props.currentView.caseReference.appealType, // "incidentID": props.props.currentView.caseReference.incidentid, // "caseRef": props.props.currentView.caseReference.currentReference, // }); //console.log("///////// repFormData:", repFormData); const whichQuestionnaireCheck = () => { { switch (currentView.caseReference.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; } } }; let buildAppealFilesArray = []; let filesUploadObj = props.currentView.fileList; // formObj.representationForm.values.representationDocuments; for (let key in filesUploadObj) { typeof filesUploadObj[key].name != "undefined" && buildAppealFilesArray.push({ "name": filesUploadObj[key].name, "size": filesUploadObj[key].contentLength }); } // console.log( // buildAppealFilesArray, // formObj.representationForm.values.filesList // ); // buildAppealFilesArray = formObj.representationForm.values.hasOwnProperty( // "filesList" // ) // ? formObj.representationForm.values.filesList // : []; let arrUniq = [ ...new Map(buildAppealFilesArray.map((v) => [v.name, v])).values() ]; buildAppealFilesArray = buildAppealFilesArray.filter(function (el) { return el != null; }); // const arrUniq = buildAppealFilesArray.filter( // (obj1, i, arr) => arr.findIndex((obj2) => obj2.name === obj1.name) === i // ); //arrUniq = arrUniq.concat(filesUploadObj); function removeNullObjects(arr) { if (arr.length === 0) { return arr; } return arr.filter((obj) => obj !== null); } function removeEmptyObjects(arr) { if (arr.length === 0) { return arr; } return arr.filter( (obj) => obj && typeof obj === "object" && Object.keys(obj).length > 0 ); } arrUniq = removeNullObjects(arrUniq); arrUniq = removeEmptyObjects(arrUniq); Object.assign(formObj.representationForm.values, { "filesList": arrUniq }); let filterFiles = []; function showRepsEnded(endDate) { let date = new Date(); date = new Date(date.toDateString()); let end = new Date(endDate); end.setUTCHours(23); end.setUTCMinutes(59); end.setUTCSeconds(59); end.toISOString(); return end > date ? false : true; } const checkRepDatePassed = () => { if (repFormData.representationType == "Questionnaire") { return false; } else { if (repFormData.representationType == "Final comments") { return repFormData.hasOwnProperty( "pinswg_finalcommentsduedate" ) && showRepsEnded(repFormData.pinswg_finalcommentsduedate) ? true : false; } if (repFormData.representationType == "Statement") { return repFormData.hasOwnProperty("pinswg_statementduedate") && showRepsEnded(repFormData.pinswg_statementduedate) ? true : false; } } }; const triggerQuestionnaireDownload = async () => { if ( repFormData.representationType !== "Questionnaire" || !downloadQuestionnaire ) { return; } if (downloadInProgress) { return; } try { setDownloadInProgress(true); const containerID = props.accountDetails?.containerID || props.props?.accountDetails?.containerID || props.props?.props?.accountDetails?.containerID; const caseRef = currentView?.caseReference?.ticketnumber || repFormData?.caseRef || repFormData?.ticketnumber; if (!containerID || !caseRef) { console.error( "Questionnaire download skipped: missing containerID or case reference", { containerID, caseRef } ); return; } const pdfBlob = await generateRepPDF( repFormData, containerID, caseRef, { download: true } ); if (pdfBlob) { const blobUrl = window.URL.createObjectURL(pdfBlob); const anchor = document.createElement("a"); anchor.href = blobUrl; anchor.download = `${repFormData.repfile_name || "questionnaire"}.pdf`; document.body.appendChild(anchor); anchor.click(); anchor.remove(); window.URL.revokeObjectURL(blobUrl); } } catch (error) { console.error("Questionnaire download failed", error); } finally { setDownloadInProgress(false); } }; return ( <> {currentView.representationSubmitConfirmation == true ? ( ) : (

    {" "} {repFormData.appealType == 846040002 ? t( "myrepresentations:consultation-check-submit-heading" ) : t( "myrepresentations:rep-check-submit-heading" )}

    {repFormData.appealType == 846040002 ? t( "myrepresentations:consultation-check-your-rep-heading" ) : t( "myrepresentations:rep-check-your-rep-heading" )}

    {repFormData.appealType == 846040002 ? t( "case:consultation-representation-type" ) : t( "case:representation-representation-type" )}
    {router.locale == "cy" ? repFormData.representationType == "Questionnaire" ? "Holiadur" : repFormData.representationType == "Statement" ? "Datganiad" : repFormData.representationType == "Final comments" ? "Sylwadau terfynol" : repFormData.representationType : repFormData.representationType}
    {/* { setSubmitBack(); }} > {t("common:change-link-label")} {" "} {FieldsTranslations( rows[0].value )} */}
    {_.has( repFormData, "representationOnBehalfOf" ) && ( <> {repFormData.representationOnBehalfOf == "Yes" && ( )} )} {repFormData.representationType != "Questionnaire" && repFormData.appealType != 846040002 && ( )} {repFormData.representationType == "Questionnaire" ? whichQuestionnaireCheck() : ""}

    {t( "myrepresentations:rep-check-tandc-para-one" )}

    {t( "myrepresentations:rep-check-tandc-para-two" )}{" "} {t( "common:footer-privacy-notice-link-label" )} .

    {t( "myrepresentations:rep-check-tandc-para-three" )}

    {checkRepDatePassed() ? (
    Warning

    {t( "myrepresentations:rep-period-passed-heading" )}

    {t( "myrepresentations:rep-period-notice-label" )}

    ) : finaliseAppealProcess ? (

    {t( "myrepresentations:rep-finalising-heading" )}

    {t( "myrepresentations:rep-finalising-label" )}

    {t("myrepresentations:rep-wait-label")}

    ) : ShowDocLinks ? ( <> {" "}
    Notice {t( "myrepresentations:docsoffline-reps-label" )} {" "}
    {" "} {t( "myrepresentations:return-to-myportal-link" )} ) : ( <> {repFormData.representationType == "Questionnaire" && (
    { setDownloadQuestionnaire( e.target.checked ); }} />
    )}
    { setConfirmSections( !confirmSections ); }} />
    setSubmitBack()} className="govuk-link" > {t( "case:summary-back-button-label" )}
    )}
    )} ); }; 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, accountDetails: state.accountDetails //form: state.form, }; }; const mapDispatchToProps = (dispatch) => { return { setCurrentReference: (currentReference) => { dispatch(setCurrentReference(currentReference)); } }; }; export default connect(mapStateToProps, mapDispatchToProps)(RepCompleteSubmit);