import useTranslation from "next-translate/useTranslation"; import { useRouter } from "next/router"; import { connect } from "react-redux"; import { Field, change, reduxForm } from "redux-form"; import { useEffect, useState } from "react"; import { bytesToSize, getThumbnailIconByExtension } from "../../utils"; import { FileUploadField, RenderCondtionalRadioList, RenderRichMultiline, shouldDisableButton } from "./representationElements"; import RepresentationActionButtons from "./elements/RepresentationActionButtons"; import RepresentationTypeSelectorBlock from "./elements/RepresentationTypeSelectorBlock"; import { useDropzone } from "react-dropzone"; import { setRepresentationCapacity, setRepresentationSubmit, setFilesForRepresentations } from "../../../store/currentView/action"; const RepAgent = (props) => { let { t } = useTranslation(); const router = useRouter(); const { locale } = router; const { formObj, appellantApplicantRepresentationArr, setRepresentationCapacity, setRepresentationSubmit, currentView, setRepFileName, updateRepresentation, setSavingStatus, savingStatus, setFilesForRepresentations, onRepresentationTypeChange, onTypeSelectionConfirmed } = props; const { acceptedFiles, getRootProps, getInputProps } = useDropzone(); const persistedRepresentationType = currentView?.caseReference?.repDetails?.representationType; const [typeSelectionConfirmed, setTypeSelectionConfirmed] = useState( !!persistedRepresentationType ); useEffect(() => { if (persistedRepresentationType) { setTypeSelectionConfirmed(true); } }, [persistedRepresentationType]); if (JSON.stringify(formObj) != "{}") { setRepFileName(formObj.representationForm.values); let filterFilesList = props.currentView.caseReference.hasOwnProperty( "repDetails" ) ? props.currentView.caseReference.repDetails.hasOwnProperty( "filesList" ) ? props.currentView.caseReference.repDetails.filesList.filter( function (el) { return el != null; } ) : [] : []; const files = acceptedFiles.map((file) => (
  • {file.path} - {file.size} bytes
  • )); const required = (value) => (value ? undefined : "Required"); const selectedRepresentationType = formObj?.representationForm?.values?.representationType || props.representationType; const isTypeConfirmed = !!selectedRepresentationType && typeSelectionConfirmed; const selectedRepresentationTypeDisplay = router.locale == "cy" ? selectedRepresentationType == "Questionnaire" ? "Holiadur" : selectedRepresentationType == "Statement" ? "Datganiad" : selectedRepresentationType == "Final comments" ? "Sylwadau terfynol" : selectedRepresentationType : selectedRepresentationType; const handleSaveExit = () => { let valuesObj = props.props.props.form[props.form].values || {}; delete valuesObj["_pinswg_appellant_value"]; updateRepresentation(valuesObj, false, true); }; return ( <> {isTypeConfirmed && ( <>

    {t("myrepresentations:enter-comment-label")}

    {/*
    {t( "myrepresentations:comments-set-out-label" )} :
    */}

    {t( "myrepresentations:publish-policy-label" )}{" "} {t( "myrepresentations:publish-policy-link-label" )} {" "} {t( "myrepresentations:publish-policy-label-two" )}

    0 // ? props.currentView // .caseReference // .repDetails // .filesList // : [] // : [] } setFilesForRepresentations={ setFilesForRepresentations } containerID={ props.props.props.accountDetails .containerID } filenamePrefix={props.formObj} props={props.props.props} setCurrentReference={ props.setCurrentReference } />
    {" "}
    )} {isTypeConfirmed && ( )} ); } }; const mapDispatchToProps = (dispatch) => ({ updateField: (form, field, newValue) => dispatch(change(form, field, newValue)), setFilesForRepresentations: (fileList) => { dispatch(setFilesForRepresentations(fileList)); } }); export default connect( null, mapDispatchToProps )( reduxForm({ form: "representationForm", enableReinitialize: true, destroyOnUnmount: false })(RepAgent) );