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, RenderRichMultiline, shouldDisableButton } from "./representationElements"; import RepresentationTypeSelectorBlock from "./elements/RepresentationTypeSelectorBlock"; import { useDropzone } from "react-dropzone"; import { setRepresentationCapacity, setRepresentationSubmit, setFilesForRepresentations } from "../../../store/currentView/action"; const ConsultationAppellant = (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]); console.log(JSON.stringify(formObj) == "{}" ? "empty" : "value"); 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; } ) : [] : []; filterFilesList = filterFilesList.filter( (value, index, self) => index === self.findIndex((t) => t.name === value.name) ); 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; return ( <> {isTypeConfirmed && (

{selectedRepresentationType == "Consultation Response" ? t("myrepresentations:enter-comment-label") : t( "myrepresentations:consultation-comment-label" )}

{selectedRepresentationType == "Consultation Response" && (
{formObj.representationForm.values .appealType == "846040004" ? (

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

) : (

{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 && (
{/* {router.query.state != "edit" && ( { setRepresentationCapacity(); props.updateField( "representationType", "" ); }} className="govuk-link" > {t("common:back-link")} )} */} {savingStatus ? ( {router.locale == "cy" ? "Nôl data" : "Saving data"} { ) : ( )}
)} ); } }; //const mapStateToProps = (state, props) => {}; const mapDispatchToProps = (dispatch) => { return { 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 })(ConsultationAppellant) );