- saving progress;

This commit is contained in:
Vitalii Kiiko
2024-09-02 17:15:43 +02:00
parent d634e425e5
commit c15360faf0
41 changed files with 1531 additions and 356 deletions

View File

@@ -34,7 +34,7 @@ const DatepickerRange = ({
<Calendar id={field.name}
value={field.value}
onChange={field.onChange}
dateFormat="dd/mm/yy"
mask="99/99/9999"
showIcon
minDate={minDate}

View File

@@ -21,9 +21,11 @@ const Fileupload = ({
doctype = 'images',
emptyText = __('Trascina qui il tuo file', 'gepafin'),
chooseLabel = __('Aggiungi immagine', 'gepafin'),
multiple = false
multiple = false,
callId = 0
}) => {
const [stateFieldData, setStateFieldData] = useState([]);
const [acceptFormats, setAcceptFormats] = useState('');
const inputRef = useRef();
const customBase64Uploader = (event) => {
@@ -31,14 +33,10 @@ const Fileupload = ({
for (const file of event.files) {
formData.append('file', file)
}
/*for (const pair of formData.entries()) {
console.log(pair[0], pair[1]);
}*/
FileUploadService.uploadFile(formData, callback, errorCallback, [['documentType', doctype.toUpperCase()]]);
FileUploadService.uploadFile(callId, formData, callback, errorCallback, [['documentType', doctype.toUpperCase()]]);
};
const callback = (data) => {
console.log('data', data);
if (data.status === 'SUCCESS') {
setStateFieldData(data.data);
const files = inputRef.current.getFiles();
@@ -86,7 +84,6 @@ const Fileupload = ({
setStateFieldData(prevState => {
const newFiles = prevState.filter(o => o.id !== id);
inputRef.current.setUploadedFiles(newFiles);
console.log('newFiles', newFiles);
return newFiles;
});
}
@@ -96,39 +93,61 @@ const Fileupload = ({
console.log('err', err);
}
const onBeforeDrop = (e) => {
return validateFileInputType(e.dataTransfer.files);
}
const validateFileInputType = ( files ) => {
const MIMEtype = new RegExp( acceptFormats );
return Array.prototype.every.call( files, function passesAcceptedFormat( file ){
return MIMEtype.test( file.type );
} );
}
useEffect(() => {
setStateFieldData(defaultValue);
register(fieldName, config)
}, []);
useEffect(() => {
// eslint-disable-next-line no-useless-escape
setAcceptFormats(accept.replace( /\*/g, '.\*' ).replace( /,/g, '|' ));
}, [accept]);
useEffect(() => {
inputRef.current.setUploadedFiles(stateFieldData);
setDataFn(fieldName, [...stateFieldData], { shouldValidate: true });
}, [stateFieldData])
return (
<>
<label htmlFor={fieldName} className={classNames({ 'p-error': errors[fieldName] })}>
{label}{config.required ? '*' : null}
</label>
<FileUpload
ref={inputRef}
id={fieldName}
name={fieldName}
url={'/document/uploadFile'}
multiple={multiple}
accept={accept}
maxFileSize={1000000}
emptyTemplate={<p>{emptyText}</p>}
chooseLabel={chooseLabel}
cancelLabel={__('Cancella', 'gepafin')}
uploadLabel={__('Carica', 'gepafin')}
className={classNames({ 'p-invalid': errors[fieldName] })}
itemTemplate={itemTemplate}
customUpload
uploadHandler={customBase64Uploader}/>
{infoText ? <small>{infoText}</small> : null}
</>)
callId && callId !== 0
? <>
<label htmlFor={fieldName} className={classNames({ 'p-error': errors[fieldName] })}>
{label}{config.required ? '*' : null}
{acceptFormats ? ' (' + acceptFormats.split('|').join(', ') + ')' : null}
</label>
<FileUpload
ref={inputRef}
id={fieldName}
name={fieldName}
url={'/document/uploadFile'}
multiple={multiple}
accept={accept}
maxFileSize={1000000}
emptyTemplate={<p>{emptyText}</p>}
chooseLabel={chooseLabel}
cancelLabel={__('Cancella', 'gepafin')}
uploadLabel={__('Carica', 'gepafin')}
className={classNames({ 'p-invalid': errors[fieldName] })}
itemTemplate={itemTemplate}
customUpload
onBeforeDrop={onBeforeDrop}
uploadHandler={customBase64Uploader}/>
{infoText ? <small>{infoText}</small> : null}
</>
: null
)
}
export default Fileupload;