diff --git a/src/components/FileuploadDelega/index.js b/src/components/FileuploadDelega/index.js index 28c1253..6042a03 100644 --- a/src/components/FileuploadDelega/index.js +++ b/src/components/FileuploadDelega/index.js @@ -2,11 +2,11 @@ import React, { useEffect, useState, useRef } from 'react'; import { __ } from '@wordpress/i18n'; import { isEmpty } from 'ramda'; -import FileUploadService from '../../service/file-upload-service'; - import { FileUpload } from 'primereact/fileupload'; import { Tag } from 'primereact/tag'; import { Button } from 'primereact/button'; + +// api import CompanyService from '../../service/company-service'; const FileuploadDelega = ({ @@ -21,7 +21,7 @@ const FileuploadDelega = ({ companyId = 0, disabled = false }) => { - const [stateFieldData, setStateFieldData] = useState({}); + const [stateFieldData, setStateFieldData] = useState([]); const [acceptFormats, setAcceptFormats] = useState(''); const inputRef = useRef(); @@ -35,9 +35,7 @@ const FileuploadDelega = ({ const callback = (data) => { if (data.status === 'SUCCESS') { - setStateFieldData(data.data); - const files = inputRef.current.getFiles(); - inputRef.current.setUploadedFiles(files); + setStateFieldData([data.data]); inputRef.current.setFiles([]); } } @@ -47,11 +45,12 @@ const FileuploadDelega = ({ } const itemTemplate = (file) => { + let fileName = file.fileName ? file.fileName : file.name; return (
- {file.fileName} + {fileName}
@@ -90,6 +89,7 @@ const FileuploadDelega = ({ setStateFieldData(prevState => { const newFiles = prevState.filter(o => o.id !== id); inputRef.current.setUploadedFiles(newFiles); + console.log('dCallback - newFiles', newFiles) return newFiles; }); } @@ -104,6 +104,13 @@ const FileuploadDelega = ({ } const onBeforeSelect = (e) => { + const files = inputRef.current.getFiles(); + const uploadedfiles = inputRef.current.getUploadedFiles(); + + if (!multiple && (uploadedfiles.length > 0 || files.length > 0)) { + return false; + } + if (e.originalEvent.target.files) { return !isEmpty(e.originalEvent.target.files) ? validateFileInputType(e.originalEvent.target.files) @@ -127,10 +134,7 @@ const FileuploadDelega = ({ useEffect(() => { if (inputRef.current) { - const properValue = multiple - ? defaultValue - : !isEmpty(defaultValue) ? [defaultValue] : []; - inputRef.current.setUploadedFiles(properValue); + inputRef.current.setUploadedFiles(defaultValue); } }, [defaultValue]); @@ -141,10 +145,9 @@ const FileuploadDelega = ({ useEffect(() => { if (inputRef.current) { - inputRef.current.setUploadedFiles(multiple ? stateFieldData : [stateFieldData]); + inputRef.current.setUploadedFiles(stateFieldData); } - - setDataFn(fieldName, multiple ? [...stateFieldData] : stateFieldData, { shouldValidate: true }); + setDataFn(fieldName, stateFieldData, { shouldValidate: true }); }, [stateFieldData]) return ( diff --git a/src/pages/ProfileCompany/index.js b/src/pages/ProfileCompany/index.js index ad16c87..d70611c 100644 --- a/src/pages/ProfileCompany/index.js +++ b/src/pages/ProfileCompany/index.js @@ -31,7 +31,7 @@ const ProfileCompany = () => { const infoMsgs = useRef(null); const [formInitialData, setFormInitialData] = useState({}); const [delegaData, setDelegaData] = useState({}); - const [delega, setDelega] = useState({}); + const [delega, setDelega] = useState([]); const { delegaFirstName = '', delegaLastName = '', delegaCodiceFiscale = '' } = delegaData; const toast = useRef(null); @@ -158,13 +158,13 @@ const ProfileCompany = () => { const getDellegaCallback = (data) => { if (data.data) { - setDelega(data.data); + setDelega([data.data]); } storeSet.main.unsetAsyncRequest(); } const errDellegaCallback = () => { - setDelega({}); + setDelega([]); storeSet.main.unsetAsyncRequest(); } @@ -473,7 +473,7 @@ const ProfileCompany = () => { />
-
+ {/*
+
*/} +
:
}