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 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, } from "../../utils"; import { setCurrentReference, setCurrentView, } from "../../../store/currentView/action"; const RepCompleteSubmit = (props) => { let { t } = useTranslation(); const [confirmSections, setConfirmSections] = useState(false); const router = useRouter(); const { locale } = router; const { formObj, appellantApplicantRepresentationArr, setRepresentationCapacity, setRepresentationSubmit, currentView, setSubmitBack, setRepresentationSubmitConfirmation, setRepresentationMessageSent, setRepresentationReset, setShowQuestionnaireSection, showQuestionnaireSection, questionnaireCount, finaliseAppealProcess, setCurrentReference, } = props; 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()); const end = new Date(endDate); 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; } } }; return ( <> {currentView.representationSubmitConfirmation == true ? ( ) : (

    {" "} {t( "myrepresentations:rep-check-submit-heading" )}

    {t( "myrepresentations:rep-check-your-rep-heading" )}

    {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.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")}

    ) : ( <>
    { 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);