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, { useMemo, useState } from "react"; import DatePicker from "react-datepicker"; 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"; import fieldLookup from "../../data/crmfieldlookuptranslations.json"; import pickListLookup from "../../data/picklistLookups.json"; import dynamic from "next/dynamic"; import { bytesToSize, getThumbnailIconByExtension } from "../utils"; import { setFileCount } from "../../store/appealType/action"; import { addDays, addMonths, addYears, parseISO, subDays, subMonths, subYears, } from "date-fns"; import "react-quill-new/dist/quill.snow.css"; const ReactQuill = dynamic(() => import("react-quill-new"), { ssr: false }); import { useStore as store, useSelector } from "react-redux"; import { useDispatch } from "react-redux"; import { validateField } from "./validationUtils"; // Import the validation function const RenderTextfield = ({ id, className, rows, datafieldname, name, label, input, errorMsg, meta: { touched, error }, ...custom }) => { return ( <>
{!custom.hasOwnProperty("showErrorBottom") ? touched && error && ( Error: {" "} {error} ) : ""} {custom.hasOwnProperty("showErrorBottom") ? touched && error && ( Error: {" "} {error} ) : ""}
); }; 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} /> )}
); } } const RenderMultiline = ({ id, className, rows, datafieldname, name, label, input, errorMsg, meta: { touched, error }, ...custom }) => { return ( <>
{/* */} {touched && error && ( Error:{" "} {touched && ((error && ( {errorMsg ? errorMsg : error} )) || (warning && {warning}))} )}
); }; 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 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 const RenderRichMultiline = ({ id, className, rows, datafieldname, name, label, input, meta: { touched, error }, ...custom }) => { const [editValue, setEditValue] = useState( input.value != null ? input.value : "" ); const changeEdit = (valStr) => { setEditValue(valStr); input.onChange(valStr); }; var modules = { toolbar: [ [{ "header": [1, 2, false] }], ["bold", "italic", "underline", "blockquote"], [{ "list": "ordered" }, { "list": "bullet" }], ["clean"], ], }; return ( <>
{error && ( Error:{" "} {error} )}
); }; 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} />
)} ); } const RenderDatePicker = ({ datafieldname, name, label, id, errorMsg, input: { onChange, value }, meta: { touched, error }, ...custom }) => { const router = useRouter(); let { t } = useTranslation(); var startDateArr = custom.dateStart != "0" ? custom.dateStart.split("") : custom.dateStart; var endDateArr = custom.dateEnd != "0" ? custom.dateEnd.split("") : custom.dateEnd; var minDate = startDateArr == 0 ? new Date() : startDateArr[0] == "-" ? startDateArr[2] == "y" ? subYears(new Date(), startDateArr[1]) : startDateArr[2] == "m" ? subMonths(new Date(), startDateArr[1]) : subDays(new Date(), startDateArr[1]) : startDateArr[2] == "y" ? addYears(new Date(), startDateArr[1]) : startDateArr[2] == "m" ? addMonths(new Date(), startDateArr[1]) : addDays(new Date(), startDateArr[1]); var maxDate = endDateArr == 0 ? new Date() : startDateArr[0] == "-" ? startDateArr[2] == "y" ? subYears(new Date(), startDateArr[1]) : startDateArr[2] == "m" ? subMonths(new Date(), startDateArr[1]) : subDays(new Date(), startDateArr[1]) : startDateArr[2] == "y" ? addYears(new Date(), startDateArr[1]) : startDateArr[2] == "m" ? addMonths(new Date(), startDateArr[1]) : addDays(new Date(), startDateArr[1]); return ( <>
{custom.hasOwnProperty("hint") && (
{t(custom.hint)}
)}
{!custom.hasOwnProperty("showErrorBottom") ? touched && error && ( Error: {" "} {errorMsg} ) : ""} {/* {value}
{moment(value).format("DD/MM/YY")}
*/} {custom.hasOwnProperty("showErrorBottom") ? touched && error && ( Error: {" "} {error} ) : ""}
); }; export function DateFieldPicker(props) { const { name, label, parentField, form, formProps, parentFieldShowOnValue, validation, dateStart, dateEnd, } = props; 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"); 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 (
); } const RenderYesNo = ({ datafieldname, name, label, id, errorMsg, options, input: { onChange, value }, meta: { touched, error }, ...custom }) => { return ( <>
{touched && error && ( Error: {" "} {errorMsg} )}
{Object.keys(options).map((key, index) => (
{ let docListObj = custom.documentList; if ( custom.requiredDocumentValue == "Yes" || custom.requiredDocumentValue == "Ydw" || custom.requiredDocumentValue == "true" ) { e.target.value == "Ydw" || e.target.value == "Yes" || e.target.value == "true" ? (docListObj = Object.assign( docListObj, { ["documentCheckList_" + id]: custom.requiredDocumentLabel, } )) : delete docListObj[ "documentCheckList_" + id ]; custom.setDocumentsList(docListObj); } }} />
))}
); }; 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 && ( ) ) : ( )} ); } const RenderRadio = ({ datafieldname, name, label, id, errorMsg, options, input: { onChange, value }, meta: { touched, error }, ...custom }) => { let { t } = useTranslation(); return ( <>
{touched && error && ( Error: {" "} {errorMsg} )}
{" "} {custom.hint != false && (
{t(custom.hint)}
)} {Object.keys(options).map((key, index) => (
{ let docListObj = custom.documentList; if ( custom.requiredDocumentValue == "Yes" ) { e.target.value != "846040000" ? (docListObj = Object.assign( docListObj, { ["documentCheckList_" + id]: custom.requiredDocumentLabel, } )) : delete docListObj[ "documentCheckList_" + id ]; custom.setDocumentsList(docListObj); } }} />
))}
); }; 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} /> )} ); } const RenderCheckBox = ({ datafieldname, name, label, id, errorMsg, options, input: { onChange, value }, meta: { touched, error }, ...custom }) => { return ( <>
{touched && error && ( Error: {" "} {errorMsg} )}
{Object.keys(options).map((key, index) => (
))}
); }; 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 ( ); } const RenderPickList = ({ datafieldname, picklistData, id, name, label, input, errorMsg, meta: { touched, error }, }) => { let { t } = useTranslation(); var dropdownObj = jsonpath({ path: "$..value[?(@ && @.LogicalName=='" + datafieldname + "')]..Options", json: picklistData, eval: true, }); dropdownObj = dropdownObj[0]; const required = (value) => { return value || value == 0 ? undefined : t("newappeal:is-required-label"); }; return ( <>
{touched && error && ( Error:{" "} {error} )}
); }; 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 RenderDecimalField = ({ name, id, label, datafieldname, className, input, errorMsg, meta: { touched, error }, ...custom }) => { //
// // // {touched && error && {error}} //
; return ( <>
{touched && error && ( Error:{" "} {error} )}
); }; 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; let formObj = jsonpath({ path: "$['" + appealtypes + "']", json: fieldLookup, eval: true, }); let labelTrans = router.locale == "cy" ? jsonpath({ path: '$..[?(@ && @.value=="' + label + '")].value_cy', json: formObj, eval: true, })[0] : label; //labelTrans = labelTrans.length > 1 ? labelTrans[0] : labelTrans; return labelTrans; }; const PickListTranslations = (optionValue) => { const router = useRouter(); const { locale } = router; const { appealtypes } = router.query; //console.log(optionValue); let optionTrans = router.locale == "cy" ? jsonpath({ path: '$..[?(@ && @.value=="' + optionValue + '")].value_cy', json: pickListLookup, eval: true, }) : optionValue; //console.log(optionTrans, optionValue); return optionTrans; }; export function FileUploadField(props) { 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 getThumbnailIcon = (fileObj, fileType) => { switch (fileType) { case "text/html": return "/assets/images/documenttypes/html.png"; break; case "text/plain": return "/assets/images/documenttypes/txt.png"; break; case "application/msword": return "/assets/images/documenttypes/doc.png"; break; case "application/pdf": return "/assets/images/documenttypes/pdf.png"; break; case "application/vnd.openxmlformats-officedocument.wordprocessingml.document": return "/assets/images/documenttypes/docx.png"; break; case "text/csv": return "/assets/images/documenttypes/csv.png"; break; case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": return "/assets/images/documenttypes/xlsx.png"; break; case "application/zip": return "/assets/images/documenttypes/zip.png"; break; case "image/jpeg": return "/assets/images/documenttypes/jpg.png"; case "image/png": return "/assets/images/documenttypes/png.png"; //return URL.createObjectURL(fileObj); break; default: return "/assets/images/documenttypes/default.png"; break; } }; const getDocumentType = (docCode) => { const repDate = new Date(); let day = repDate.getDate(); let month = repDate.getMonth() + 1; let year = repDate.getFullYear(); const pdfFileNameDateStamp = year + "-" + ("0" + month).slice(-2) + "-" + ("0" + day).slice(-2); switch (docCode) { case "000000": return pdfFileNameDateStamp + "_-_Statement_of_Case"; case "000001": return pdfFileNameDateStamp + "_-_Application_Form"; break; case "000002": return pdfFileNameDateStamp + "_-_Site_Ownership_Certificate"; break; case "000003": return pdfFileNameDateStamp + "_-_Decision_Notice"; break; case "000004": return pdfFileNameDateStamp + "_-_Site_Location_Plan"; break; case "000005": return pdfFileNameDateStamp + "_-_Plans_Drawing_Documents"; break; case "000006": return ( pdfFileNameDateStamp + "_-_Additional_Plans_Drawings_Documents" ); break; case "000007": return pdfFileNameDateStamp + "_-_Design_and_Access_Statement"; break; case "000008": return pdfFileNameDateStamp + "_-_NSB_LPA_Additional_Documents"; break; case "000009": return pdfFileNameDateStamp + "_-_LPA_Correspondence"; break; case "000010": return pdfFileNameDateStamp + "_-_LPA_Original_Permission"; break; case "000011": return pdfFileNameDateStamp + "_-_LPA's_Registration_Letter"; break; case "000012": return pdfFileNameDateStamp + "_-_Environmental_Statement"; break; case "000013": return pdfFileNameDateStamp + "_-_Cost_of_Application"; break; case "000014": return pdfFileNameDateStamp + "_-_Other_Relevant_Material"; break; case "000015": return ( pdfFileNameDateStamp + "_-_S106_Agreement_or_Unilateral_Undertaking" ); break; default: return pdfFileNameDateStamp + "_-_000000_-_"; } }; 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 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" )}`; } 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 ( <> { setCompletedUploadFiles(false); const renamedAcceptedFiles = filesToUpload.map( (file) => new File( [file], `${getDocumentType(field.documentTypeCode)}_-_${ file.name }`, { type: file.type, } ) ); field.input.onChange(renamedAcceptedFiles); field.setFileCount( field.uploadCount + renamedAcceptedFiles.length ); setUploadCountMessage(renamedAcceptedFiles.length); uploadSingleFile( renamedAcceptedFiles, field.containerID, field.ticketnumber ).then((data) => { console.log(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, }); } //console.log(buildAppealFilesArray); function removeDuplicates(arr, key) { const seen = new Set(); return arr.filter((item) => { const value = item[key]; if (seen.has(value)) { return false; // Duplicate found } else { seen.add(value); // Add value to the set return true; // Keep the item } }); } buildAppealFilesArray = values.hasOwnProperty( "filesList" ) ? buildAppealFilesArray.concat(values.filesList) : buildAppealFilesArray; buildAppealFilesArray = removeDuplicates( buildAppealFilesArray, "name" ); Object.assign(values, { "filesList": buildAppealFilesArray, }); data.invalidFiles.length > 0 && (setRejectedFiles(data.invalidFiles), setUploadCountMessage( renamedAcceptedFiles.length - data.invalidFiles.length )); getFilesFromBlobproxy( field.containerID, field.ticketnumber ).then((data) => { field.input.value == null; field.setFilesForAppeal(data); setCompletedUploadFiles(true); }); }); }} onDropRejected={handleDropRejected} onDropAccepted={handleDropAccepted} > {({ getRootProps, getInputProps }) => ( <>
{" "}
{t( "newappeal:new-appeal-fileupload-drop-label" )}{" "} (Max 50 MB)
( {t( "newappeal:new-appeal-fileupload-file-list-label" )} )
{/* */}
)}
{rejectedFiles.length > 0 && completedUploadFiles == true && (
    {rejectedFiles.map((error, index) => (
  • {error}
  • ))}
)} {uploadCountMessage > 0 && completedUploadFiles == false && (
{t("home:uploading-files-label", { number: 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)})
) )}{" "} ); }; const renderField = ({ input, label, type, meta: { touched, error } }) => (
{touched && error && {error}}
); const RenderSubFields = ({ fields, meta: { touched, error }, ...custom }) => { let { t } = useTranslation(); let subTitle = fields.name.split("pinswg_")[1]; const checkValue = (value) => { let errors; 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 required = (value) => value ? undefined : t("newappeal:is-required-label"); //fields.push({}); fields.length == 0 && fields.push({}); return (
    {fields.map((member, index) => (

    {subTitle == "owners" ? "Owner" : "Tenant"} #{index + 1}

    ))}
    {fields.length < custom.maxSubField && ( )}
); }; export const FieldArrayForm = (props) => { const { name, label, validation, form, formProps, parentFieldShowOnValue, parentField, maxFieldLength, 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; (showIfHasParentShowValue == parentField) != false && showIfHasParentShowValue; !showIfHasParentShowValue && dispatch(change("appealForm", name, null)); parentFieldShowOnValue; const { handleSubmit, pristine, reset, submitting } = props; return ( <> {" "} {showIfHasParentShowValue && ( )} ); };