import { JSONPath as jsonpath } from "jsonpath-plus"; import axios from "axios"; import _ from "lodash"; import useTranslation from "next-translate/useTranslation"; import Link from "next/link"; import { useRouter } from "next/router"; import React, { useEffect, useMemo, useState } from "react"; import "react-datepicker/dist/react-datepicker.css"; import Dropzone from "react-dropzone"; import { Field, FieldArray, change } from "redux-form"; import { deleteBlob, getFilesFromBlobHashed, uploadSingleFile, getFilesFromBlobproxy } from "../../actions/services/documentService"; import fieldLookup from "../../data/crmfieldlookuptranslations.json"; import pickListLookup from "../../data/picklistLookups.json"; import { bytesToSize, getThumbnailIconByExtension } from "../utils"; import { setFileCount } from "../../store/appealType/action"; import "react-quill-new/dist/quill.snow.css"; import { useStore as store, useSelector } from "react-redux"; import { useDispatch } from "react-redux"; import { validateField } from "./validationUtils"; // Import the validation function import { getDocumentTypePrefix, getThumbnailIconByMimeType, validateUploadFilename } from "./helpers/fileUploadHelpers"; import { getFieldTranslation } from "./helpers/translationHelpers"; import { RenderRichMultiline } from "./fields/renderRichMultiline"; import { RenderTextfield } from "./fields/renderTextfield"; import { RenderMultiline } from "./fields/renderMultiline"; import { RenderDatePicker } from "./fields/renderDatePicker"; import { RenderYesNo } from "./fields/renderYesNo"; import { RenderRadio } from "./fields/renderRadio"; import { RenderCheckBox } from "./fields/renderCheckBox"; import { RenderPickList } from "./fields/renderPickList"; import { RenderDecimalField } from "./fields/renderDecimalField"; import { RenderSubFields } from "./fields/renderSubFields"; export function Textfield(props) { const { name, label, validation, ticketnumber, form, formProps, parentField, parentFieldShowOnValue, maxFieldLength, hint } = props; const required = (value) => { let errors; // Check for the required field if (!value) { errors = t("newappeal:is-required-label"); } else { // Check for emojis using a regular expression const emojiRegex = /[\u{1F600}-\u{1F64F}\u{1F300}-\u{1F5FF}\u{1F680}-\u{1F6FF}\u{1F700}-\u{1F77F}\u{1F780}-\u{1F7FF}\u{1F800}-\u{1F8FF}\u{1F900}-\u{1F9FF}\u{1FA00}-\u{1FA6F}\u{1FA70}-\u{1FAFF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}\u{2300}-\u{23FF}\u{2B50}\u{1F004}-\u{1F0CF}\u{1F0A0}-\u{1F0A5}\u{1F170}-\u{1F251}]/gu; if (emojiRegex.test(value)) { errors = "Emojis are not allowed"; } } return errors; }; const postcode = (value) => value && !/^([A-Z][A-HJ-Y]?[0-9][A-Z0-9]? ?[0-9][A-Z]{2}|GIR ?0A{2})$/i.test( value ) ? t("newappeal:invalid-postcode-label") : undefined; let { t } = useTranslation(); if (name == "pinswg_name") { return ( <>

{t("newappeal:new-appeal-introduction-paragraph")}

{t("newappeal:new-appeal-introduction-paragraph-two")}

{t( "newappeal:new-appeal-introduction-warning-paragraph" )}

); } else { var showIfHasParentShowValue = (parentField != false && !_.isEmpty(formProps[form]) && _.has(formProps[form].values, parentField) && formProps[form].values[parentField]) == parentFieldShowOnValue; // console.log(parentField, showIfHasParentShowValue); // console.log(parentField, formProps, form); //console.log("validation props:", validation); const requiredMessage = t("newappeal:is-required-label"); const emojiNotAllowedMessage = t("newappeal:emojis-not-allowed-label"); const invalidPostcodeMessage = t("newappeal:invalid-postcode-label"); return (
{parentField != false ? ( showIfHasParentShowValue && ( validateField( value, validation, requiredMessage, emojiNotAllowedMessage, invalidPostcodeMessage ) } // Use the external validate function label={props.label} maxFieldLength={props.maxFieldLength} /> ) ) : ( validateField( value, validation, requiredMessage, emojiNotAllowedMessage, invalidPostcodeMessage ) } // Use the external validate function label={props.label} errorMsg={t("newappeal:is-required-label")} maxFieldLength={props.maxFieldLength} /> )}
); } } export function MultiLinefield(props) { const { name, label, form, formProps, parentField, parentFieldShowOnValue, validation, maxFieldLength, hint } = props; const required = (value) => { let errors; // Check for the required field if (!value) { errors = t("newappeal:is-required-label"); } else { // Check for emojis using a regular expression const emojiRegex = /[\u{1F600}-\u{1F64F}\u{1F300}-\u{1F5FF}\u{1F680}-\u{1F6FF}\u{1F700}-\u{1F77F}\u{1F780}-\u{1F7FF}\u{1F800}-\u{1F8FF}\u{1F900}-\u{1F9FF}\u{1FA00}-\u{1FA6F}\u{1FA70}-\u{1FAFF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}\u{2300}-\u{23FF}\u{2B50}\u{1F004}-\u{1F0CF}\u{1F0A0}-\u{1F0A5}\u{1F170}-\u{1F251}]/gu; if (emojiRegex.test(value)) { errors = t("newappeal:emojis-not-allowed-label"); } } return errors; }; var showIfHasParentShowValue = parentField != false && !_.isEmpty(formProps[form]) && _.has(formProps[form].values, parentField) && parentFieldShowOnValue.indexOf( formProps[form].values[parentField].toString() ) > -1; (showIfHasParentShowValue == parentField) != false && showIfHasParentShowValue; //console.log(showIfHasParentShowValue, formProps[form].values[parentField]); let { t } = useTranslation(); const translatedLabel = FieldsTranslations(props.label); const requiredMessage = t("newappeal:is-required-label"); const emojiNotAllowedMessage = t("newappeal:emojis-not-allowed-label"); const invalidPostcodeMessage = t("newappeal:invalid-postcode-label"); return ( <> {parentField != false ? ( showIfHasParentShowValue && (
{props.hasOwnProperty("hint") && props.hint != false && t(props.hint)}{" "}
{t("newappeal:new-appeal-multiline-pid")}
validateField( value, validation, requiredMessage, emojiNotAllowedMessage, invalidPostcodeMessage ) } // Use the external validate function maxFieldLength={props.maxFieldLength} />
) ) : (
{props.hasOwnProperty("hint") && props.hint != false && t(props.hint)}{" "}
{t("newappeal:new-appeal-multiline-pid")}
validateField( value, validation, requiredMessage, emojiNotAllowedMessage, invalidPostcodeMessage ) } // Use the external validate function maxFieldLength={props.maxFieldLength} />
)} ); } export function RichMultiLinefield(props) { const { name, label, form, formProps, parentField, parentFieldShowOnValue, validation, maxFieldLength } = props; const required = (value) => value ? undefined : t("newappeal:is-required-label"); var showIfHasParentShowValue = parentField != false && !_.isEmpty(formProps[form]) && _.has(formProps[form].values, parentField) && parentFieldShowOnValue.indexOf( formProps[form].values[parentField].toString() ) > -1; (showIfHasParentShowValue == parentField) != false && showIfHasParentShowValue; //console.log(showIfHasParentShowValue, formProps[form].values[parentField]); let { t } = useTranslation(); const requiredMessage = t("newappeal:is-required-label"); const emojiNotAllowedMessage = t("newappeal:emojis-not-allowed-label"); const invalidPostcodeMessage = t("newappeal:invalid-postcode-label"); return ( <> {parentField != false ? ( showIfHasParentShowValue && (
{props.hasOwnProperty("hint") && props.hint != false && t(props.hint)}{" "}
{t("newappeal:new-appeal-multiline-pid")}
validateField( value, validation, requiredMessage, emojiNotAllowedMessage, invalidPostcodeMessage ) } // Use the external validate function maxFieldLength={props.maxFieldLength} />
) ) : (
{props.hasOwnProperty("hint") && props.hint != false && t(props.hint)}{" "}
{t("newappeal:new-appeal-multiline-pid")}
validateField( value, validation, requiredMessage, emojiNotAllowedMessage, invalidPostcodeMessage ) } // Use the external validate function maxFieldLength={props.maxFieldLength} />
)} ); } export function DateFieldPicker(props) { const { name, label, parentField, form, formProps, parentFieldShowOnValue, validation } = props; let dateStart = props.dateStart; let dateEnd = props.dateEnd; let { t } = useTranslation(); const required = (value) => (value ? undefined : "Required"); var showIfHasParentShowValue = (parentField != false && !_.isEmpty(formProps[form]) && _.has(formProps[form].values, parentField) && formProps[form].values[parentField]) == parentFieldShowOnValue; const requiredMessage = t("newappeal:is-required-label"); const emojiNotAllowedMessage = t("newappeal:emojis-not-allowed-label"); const invalidPostcodeMessage = t("newappeal:invalid-postcode-label"); // a and b are javascript Date objects function dateDiffInDays(a, b) { const _MS_PER_DAY = 1000 * 60 * 60 * 24; // Discard the time and time-zone information. const utc1 = Date.UTC(a.getFullYear(), a.getMonth(), a.getDate()); const utc2 = Date.UTC(b.getFullYear(), b.getMonth(), b.getDate()); return Math.floor((utc2 - utc1) / _MS_PER_DAY); } dateStart = showIfHasParentShowValue && name == "pinswg_dateoflpadecision" ? "-" + (dateDiffInDays( new Date(formProps[form].values["pinswg_dateofapplication"]), new Date() ) - 1) + "d" : dateStart; return (
{parentField != false ? ( showIfHasParentShowValue && ( validateField( value, validation, requiredMessage, emojiNotAllowedMessage, invalidPostcodeMessage ) } // Use the external validate function errorMsg={t("newappeal:select-a-date-label")} dateStart={dateStart} dateEnd={dateEnd} hint={props.hint} /> ) ) : ( validateField( value, validation, requiredMessage, emojiNotAllowedMessage, invalidPostcodeMessage ) } // Use the external validate function errorMsg={t("newappeal:select-a-date-label")} dateStart={dateStart} dateEnd={dateEnd} hint={props.hint} /> )}
); } export function DateField(props) { const { name, label } = props; return (
); } export function YesNofield(props) { const router = useRouter(); let { t } = useTranslation(); const { name, label, inline, form, formProps, validation, parentFieldShowOnValue, parentField } = props; const yesNo = router.locale == "cy" ? ["Ydw", "Na"] : ["Yes", "No"]; const required = (value) => (value ? undefined : "Required"); var showIfHasParentShowValue = parentField != false && !_.isEmpty(formProps[form]) && _.has(formProps[form].values, parentField) && parentFieldShowOnValue.indexOf( formProps[form].values[parentField].toString() ) > -1; (showIfHasParentShowValue == parentField) != false && showIfHasParentShowValue; return ( <> {parentField != false ? ( showIfHasParentShowValue && ( ) ) : ( )} ); } export function Radiofield(props) { const { name, label, datafieldname, form, formProps, parentFieldShowOnValue, parentField, validation } = props; const router = useRouter(); const required = (value) => (value ? undefined : "Required"); // console.log(props.options); let { t } = useTranslation(); const fieldOptions = props.options .slice(1, props.options.length - 1) .split(","); //parentFieldShowOnValue var showIfHasParentShowValue = parentField != false && !_.isEmpty(formProps[form]) && _.has(formProps[form].values, parentField) && parentFieldShowOnValue.indexOf( formProps[form].values[parentField].toString() ) > -1; (showIfHasParentShowValue == parentField) != false && showIfHasParentShowValue; const requiredMessage = t("newappeal:is-required-label"); const emojiNotAllowedMessage = t("newappeal:emojis-not-allowed-label"); const invalidPostcodeMessage = t("newappeal:invalid-postcode-label"); return ( <> {parentField != false ? ( showIfHasParentShowValue && ( validateField( value, validation, requiredMessage, emojiNotAllowedMessage, invalidPostcodeMessage ) } // Use the external validate function requiredDocumentLabel={props.requiredDocumentLabel} requiredDocumentValue={props.requiredDocumentValue} setDocumentsList={props.setDocumentsList} documentList={props.documentList} /> ) ) : ( validateField( value, validation, requiredMessage, emojiNotAllowedMessage, invalidPostcodeMessage ) } // Use the external validate function requiredDocumentLabel={props.requiredDocumentLabel} requiredDocumentValue={props.requiredDocumentValue} setDocumentsList={props.setDocumentsList} documentList={props.documentList} /> )} ); } export function CheckBoxfield(props) { const router = useRouter(); console.log(props); const required = (value) => (value ? undefined : "Required"); const fieldOptions = router.locale == "cy" ? ["Ydw", "Na", "2323"] : ["Yes", "No", "23232"]; return ( ); } export function PickList(props) { const { name, label, datafieldname, hint } = props; let { t } = useTranslation(); const required = (value) => { return value || value == 0 ? undefined : t("newappeal:is-required-label"); }; return ( ); } export function NumericField(props) { const { name, label, validation, form, formProps, parentFieldShowOnValue, parentField, maxFieldLength } = props; let { t } = useTranslation(); const required = (value) => { return value || value == 0 ? undefined : t("newappeal:is-required-label"); }; const isNumber = (value) => { const regex = /^\d+$/; return regex.test(value) ? undefined : t("newappeal:invalid-number-label"); }; const maxLength = (max) => (value) => value && value.length > max ? `Must be ${max} characters or less` : undefined; //parentFieldShowOnValue var showIfHasParentShowValue = parentField != false && !_.isEmpty(formProps[form]) && _.has(formProps[form].values, parentField) && parentFieldShowOnValue.indexOf( formProps[form].values[parentField].toString() ) > -1; (showIfHasParentShowValue == parentField) != false && showIfHasParentShowValue; //console.log("parentField:", parentField, showIfHasParentShowValue); const requiredMessage = t("newappeal:is-required-label"); const emojiNotAllowedMessage = t("newappeal:emojis-not-allowed-label"); const invalidPostcodeMessage = t("newappeal:invalid-postcode-label"); return ( <> {parentField != false ? ( showIfHasParentShowValue && (
validateField( value, validation, requiredMessage, emojiNotAllowedMessage, invalidPostcodeMessage ) } // Use the external validate function component={RenderTextfield} label={label} maxFieldLength={props.maxFieldLength} />
) ) : (
parseInt(value)} // maxFieldLength={props.maxFieldLength} name={props.name} id={props.name} type="text" className="govuk-input govuk-input--width-10" aria-describedby={name} //pattern="^\d*\.?\d+$" pattern="[0-9]*" validate={[ required, isNumber, maxLength(props.maxFieldLength) ]} component={RenderTextfield} label={props.label} maxFieldLength={props.maxFieldLength} />
)} ); } export function DecimalField(props) { const { name, label, validation, form, formProps, parentFieldShowOnValue, parentField, maxFieldLength } = props; let { t } = useTranslation(); const required = (value) => value ? undefined : t("newappeal:is-required-label"); const isNumber = (value) => { const regex = /^\d*\.?\d{0,1}$/; return regex.test(value) ? undefined : t("newappeal:invalid-number-label"); }; const maxLength = (max) => (value) => value && value.length > max ? `Must be ${max} characters or less` : undefined; //parentFieldShowOnValue var showIfHasParentShowValue = parentField != false && !_.isEmpty(formProps[form]) && _.has(formProps[form].values, parentField) && parentFieldShowOnValue.indexOf( formProps[form].values[parentField].toString() ) > -1; (showIfHasParentShowValue == parentField) != false && showIfHasParentShowValue; //console.log("parentField:", parentField, showIfHasParentShowValue); const normalizeDecimal = (value) => { return value ? parseFloat(value) : value; }; const validateDecimal = (value) => { if (!value) return t("newappeal:is-required-label"); // Regex to match whole numbers or decimal numbers (up to 7 characters including decimal) const regex = /^\d{1,6}(\.\d{1,2})?$/; // Up to 6 digits before the decimal, 2 after // Check if the value matches the regex pattern if (!regex.test(value)) { return t("newappeal:invalid-decimal-label"); } return undefined; }; const requiredMessage = t("newappeal:is-required-label"); const emojiNotAllowedMessage = t("newappeal:emojis-not-allowed-label"); const invalidPostcodeMessage = t("newappeal:invalid-postcode-label"); return ( <> {parentField != false ? ( showIfHasParentShowValue && (
validateField( value, validation, requiredMessage, emojiNotAllowedMessage, invalidPostcodeMessage ) } // Use the external validate function component={RenderTextfield} label={props.label} maxFieldLength={props.maxFieldLength} />
) ) : (
)} ); } const RenderCaseID = {}; export function ReadOnlyfield(props) { const { name, label, value } = props; //console.log(props.value.refno); return ( <>
); } export const FieldsTranslations = (label) => { const router = useRouter(); const { locale } = router; const { appealtypes } = router.query; return getFieldTranslation({ label, locale, appealtypes, fieldLookup }); }; export function FileUploadField(props) { const uploadCount = typeof props.uploadCount === "number" ? props.uploadCount : 0; const setFileCount = typeof props.setFileCount === "function" ? props.setFileCount : () => {}; return ( <>

{FieldsTranslations(props.label)}{" "}

); } const baseStyle = { display: "flex", flexDirection: "column", alignItems: "center", padding: "20px", borderWidth: 2, borderRadius: 2, borderColor: "#eeeeee", borderStyle: "dashed", backgroundColor: "#fafafa", color: "#bdbdbd", transition: "border .3s ease-in-out" }; const activeStyle = { borderColor: "#2196f3" }; const acceptStyle = { borderColor: "#00e676" }; const rejectStyle = { borderColor: "#ff1744" }; const RenderFileUpload = (field) => { let files = field.input.value; let { t } = useTranslation(); const style = useMemo( () => ({ ...baseStyle // ...(isDragActive ? activeStyle : {}), // ...(isDragAccept ? acceptStyle : {}), // ...(isDragReject ? rejectStyle : {}), }), [] // [isDragActive, isDragReject, isDragAccept] ); const [filesList, setFilesList] = useState([]); const thumbs = filesList.map((file) => (
{file.name} -{" "} {file.name} ({file.size / 1024}kb)
)); const filelistObj = field.fileList || {}; const blobList = jsonpath({ path: "$..[?(@ && @.documentType=='" + field.documentTypeCode + "')]", json: filelistObj, eval: true }); //const blobList = filelistObj; const deleteThisBlob = async ( containerName, blobName, deleteblobhash, getblobshash, casefolderID ) => { //console.log(containerName, blobName, deleteblobhash); deleteBlob(containerName, blobName, deleteblobhash, casefolderID) .then((data) => data) .then(() => { getFilesFromBlobHashed( containerName, getblobshash, casefolderID ).then((newfilelist) => field.setFilesForAppeal(newfilelist)); }); }; const removeFile = (file) => { const newFilesArr = files.filter((user) => user.name != file.name); files == newFilesArr; field.input.onChange(newFilesArr); }; function removeEmptyObjects(arr) { return arr.filter((obj) => Object.keys(obj).length > 0); } const [errorMessage, setErrorMessage] = useState(null); const [rejectedFiles, setRejectedFiles] = useState([]); // Store rejected files const [completedUploadFiles, setCompletedUploadFiles] = useState(false); const [uploadCountMessage, setUploadCountMessage] = useState(""); const [totalUploadFiles, setTotalUploadFiles] = useState(0); const handleDropRejected = (fileRejections) => { const errors = fileRejections .map(({ file, errors }) => { return errors.map((error) => { if (error.code === "file-too-large") { return `${file.name} ${t( "newappeal:new-appeal-fileupload-file-error-filesize-label" )}`; } if (error.code === "file-invalid-type") { return `${file.name} ${t( "newappeal:new-appeal-fileupload-file-error-invalid-type-label" )}`; } if (error.code === "filename-invalid-chars") { return ( error.message || `${file.name} ${t( "newappeal:new-appeal-fileupload-file-error-invalid-filename-label" )}` ); } return `${file.name} ${t( "newappeal:new-appeal-fileupload-file-error-invalid-label" )}`; }); }) .flat(); // Flatten the errors array setRejectedFiles(errors); // Store the error messages for rejected files }; // Handle accepted files (clear error message when files are accepted) const handleDropAccepted = () => { setErrorMessage(null); // Clear any previous error messages when files are accepted setRejectedFiles([]); // Clear any previously rejected file errorsss }; return ( <> validateUploadFilename(file, t)} onDrop={(acceptedFiles, fileRejections, e) => { // build + display rejected messages (ALWAYS, even if some accepted) if (fileRejections?.length) { handleDropRejected(fileRejections); } else { // only clear rejections when nothing was rejected on this drop setRejectedFiles([]); setErrorMessage(null); } // if nothing accepted, stop (prevents showing only "uploading" when all invalid) if (!acceptedFiles || acceptedFiles.length === 0) { setCompletedUploadFiles(true); // optional: depends on your UX setUploadCountMessage(0); setTotalUploadFiles(0); return; } // continue with your existing upload logic for accepted files setCompletedUploadFiles(false); const renamedAcceptedFiles = acceptedFiles.map( (file) => new File( [file], `${getDocumentTypePrefix(field.documentTypeCode)}_-_${ file.name }`, { type: file.type } ) ); field.input.onChange(renamedAcceptedFiles); if (typeof field.setFileCount === "function") { field.setFileCount( (field.uploadCount || 0) + renamedAcceptedFiles.length ); } setUploadCountMessage(0); setTotalUploadFiles(renamedAcceptedFiles.length); uploadSingleFile( renamedAcceptedFiles, field.containerID, field.ticketnumber, { onChunkComplete: ({ cumulativeUploaded }) => { setUploadCountMessage(cumulativeUploaded); } } ) .then((data) => { let buildAppealFilesArray = []; let values = field.form.appealForm.values; let filesUploadObj = renamedAcceptedFiles; for (let key in filesUploadObj) { typeof filesUploadObj[key].name !== "undefined" && buildAppealFilesArray.push({ name: filesUploadObj[key].name, size: filesUploadObj[key].size }); } function removeDuplicates(arr, key) { const seen = new Set(); return arr.filter((item) => { const value = item[key]; if (seen.has(value)) return false; seen.add(value); return true; }); } buildAppealFilesArray = values.hasOwnProperty( "filesList" ) ? buildAppealFilesArray.concat(values.filesList) : buildAppealFilesArray; buildAppealFilesArray = removeDuplicates( buildAppealFilesArray, "name" ); Object.assign(values, { filesList: buildAppealFilesArray }); // keep your existing server-side invalid handling if (data.invalidFiles?.length > 0) { setRejectedFiles((prev) => [ ...prev, ...data.invalidFiles ]); setUploadCountMessage( renamedAcceptedFiles.length - data.invalidFiles.length ); } return getFilesFromBlobproxy( field.containerID, field.ticketnumber ); }) .then((data) => { field.setFilesForAppeal(data); setCompletedUploadFiles(true); }); }} > {({ getRootProps, getInputProps }) => ( <>
{" "}
{t( "newappeal:new-appeal-fileupload-drop-label" )}{" "} (Max 50 MB)
( {t( "newappeal:new-appeal-fileupload-file-list-label" )} )
{/* */}
)}
{rejectedFiles.length > 0 && (
    {rejectedFiles.map((error, index) => (
  • {error}
  • ))}
)} {totalUploadFiles > 0 && completedUploadFiles == false && (
{t("home:uploading-files-label", { number: totalUploadFiles > 0 ? `${uploadCountMessage} of ${totalUploadFiles}` : uploadCountMessage })}
)} {completedUploadFiles > 0 && uploadCountMessage >= 0 && (
{t("home:completed-uploading-files-label", { number: uploadCountMessage })}
)} {field.meta.touched && field.meta.error && ( {field.meta.error} )} {files && Array.isArray(files) && ( <> {/* {(files = removeEmptyObjects(files))} */} {!completedUploadFiles && files.map( (file, i) => typeof file.name != "undefined" && (
{" "} {/* removeFile(file)} > − */} {file.name} {file.name} ( {bytesToSize(file.size)})
{completedUploadFiles ? (

Upload complete

) : (

{t( "home:uploading-files-progress-label" )}{" "}

)}
) )} )} {blobList.length > 0 && (

{t("newappeal:previously-added-files")}

)} {blobList.map( (blob, i) => blob.documentType == field.documentTypeCode && (
{ setUploadCountMessage( uploadCountMessage - 1 ); deleteThisBlob( field.containerID, blob.name, blob.hasheddeletepath, blob.hashgetblobs, field.ticketnumber ); }} title={t("home:remove-this-file-label")} > −
{blob.name} {blob.name} ({bytesToSize(blob.contentLength)})
) )}{" "} ); }; export const FieldArrayForm = (props) => { const { name, form, formProps, parentFieldShowOnValue, parentField, maxSubField } = props; const dispatch = useDispatch(); // Get dispatch using useDispatch hook var showIfHasParentShowValue = parentField != false && !_.isEmpty(formProps[form]) && _.has(formProps[form].values, parentField) && parentFieldShowOnValue.indexOf( formProps[form].values[parentField].toString() ) > -1; useEffect(() => { if (!showIfHasParentShowValue) { dispatch(change("appealForm", name, null)); } }, [dispatch, name, showIfHasParentShowValue]); return ( <> {" "} {showIfHasParentShowValue && ( )} ); };