- updated delega form logic;
This commit is contained in:
@@ -2,11 +2,11 @@ import React, { useEffect, useState, useRef } from 'react';
|
|||||||
import { __ } from '@wordpress/i18n';
|
import { __ } from '@wordpress/i18n';
|
||||||
import { isEmpty } from 'ramda';
|
import { isEmpty } from 'ramda';
|
||||||
|
|
||||||
import FileUploadService from '../../service/file-upload-service';
|
|
||||||
|
|
||||||
import { FileUpload } from 'primereact/fileupload';
|
import { FileUpload } from 'primereact/fileupload';
|
||||||
import { Tag } from 'primereact/tag';
|
import { Tag } from 'primereact/tag';
|
||||||
import { Button } from 'primereact/button';
|
import { Button } from 'primereact/button';
|
||||||
|
|
||||||
|
// api
|
||||||
import CompanyService from '../../service/company-service';
|
import CompanyService from '../../service/company-service';
|
||||||
|
|
||||||
const FileuploadDelega = ({
|
const FileuploadDelega = ({
|
||||||
@@ -21,7 +21,7 @@ const FileuploadDelega = ({
|
|||||||
companyId = 0,
|
companyId = 0,
|
||||||
disabled = false
|
disabled = false
|
||||||
}) => {
|
}) => {
|
||||||
const [stateFieldData, setStateFieldData] = useState({});
|
const [stateFieldData, setStateFieldData] = useState([]);
|
||||||
const [acceptFormats, setAcceptFormats] = useState('');
|
const [acceptFormats, setAcceptFormats] = useState('');
|
||||||
const inputRef = useRef();
|
const inputRef = useRef();
|
||||||
|
|
||||||
@@ -35,9 +35,7 @@ const FileuploadDelega = ({
|
|||||||
|
|
||||||
const callback = (data) => {
|
const callback = (data) => {
|
||||||
if (data.status === 'SUCCESS') {
|
if (data.status === 'SUCCESS') {
|
||||||
setStateFieldData(data.data);
|
setStateFieldData([data.data]);
|
||||||
const files = inputRef.current.getFiles();
|
|
||||||
inputRef.current.setUploadedFiles(files);
|
|
||||||
inputRef.current.setFiles([]);
|
inputRef.current.setFiles([]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -47,11 +45,12 @@ const FileuploadDelega = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const itemTemplate = (file) => {
|
const itemTemplate = (file) => {
|
||||||
|
let fileName = file.fileName ? file.fileName : file.name;
|
||||||
return (
|
return (
|
||||||
<div className="appForm__fileUploadItem">
|
<div className="appForm__fileUploadItem">
|
||||||
<div>
|
<div>
|
||||||
<span className="appForm__fileUploadItemName">
|
<span className="appForm__fileUploadItemName">
|
||||||
{file.fileName}
|
{fileName}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
@@ -90,6 +89,7 @@ const FileuploadDelega = ({
|
|||||||
setStateFieldData(prevState => {
|
setStateFieldData(prevState => {
|
||||||
const newFiles = prevState.filter(o => o.id !== id);
|
const newFiles = prevState.filter(o => o.id !== id);
|
||||||
inputRef.current.setUploadedFiles(newFiles);
|
inputRef.current.setUploadedFiles(newFiles);
|
||||||
|
console.log('dCallback - newFiles', newFiles)
|
||||||
return newFiles;
|
return newFiles;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -104,6 +104,13 @@ const FileuploadDelega = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const onBeforeSelect = (e) => {
|
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) {
|
if (e.originalEvent.target.files) {
|
||||||
return !isEmpty(e.originalEvent.target.files)
|
return !isEmpty(e.originalEvent.target.files)
|
||||||
? validateFileInputType(e.originalEvent.target.files)
|
? validateFileInputType(e.originalEvent.target.files)
|
||||||
@@ -127,10 +134,7 @@ const FileuploadDelega = ({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (inputRef.current) {
|
if (inputRef.current) {
|
||||||
const properValue = multiple
|
inputRef.current.setUploadedFiles(defaultValue);
|
||||||
? defaultValue
|
|
||||||
: !isEmpty(defaultValue) ? [defaultValue] : [];
|
|
||||||
inputRef.current.setUploadedFiles(properValue);
|
|
||||||
}
|
}
|
||||||
}, [defaultValue]);
|
}, [defaultValue]);
|
||||||
|
|
||||||
@@ -141,10 +145,9 @@ const FileuploadDelega = ({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (inputRef.current) {
|
if (inputRef.current) {
|
||||||
inputRef.current.setUploadedFiles(multiple ? stateFieldData : [stateFieldData]);
|
inputRef.current.setUploadedFiles(stateFieldData);
|
||||||
}
|
}
|
||||||
|
setDataFn(fieldName, stateFieldData, { shouldValidate: true });
|
||||||
setDataFn(fieldName, multiple ? [...stateFieldData] : stateFieldData, { shouldValidate: true });
|
|
||||||
}, [stateFieldData])
|
}, [stateFieldData])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ const ProfileCompany = () => {
|
|||||||
const infoMsgs = useRef(null);
|
const infoMsgs = useRef(null);
|
||||||
const [formInitialData, setFormInitialData] = useState({});
|
const [formInitialData, setFormInitialData] = useState({});
|
||||||
const [delegaData, setDelegaData] = useState({});
|
const [delegaData, setDelegaData] = useState({});
|
||||||
const [delega, setDelega] = useState({});
|
const [delega, setDelega] = useState([]);
|
||||||
const { delegaFirstName = '', delegaLastName = '', delegaCodiceFiscale = '' } = delegaData;
|
const { delegaFirstName = '', delegaLastName = '', delegaCodiceFiscale = '' } = delegaData;
|
||||||
const toast = useRef(null);
|
const toast = useRef(null);
|
||||||
|
|
||||||
@@ -158,13 +158,13 @@ const ProfileCompany = () => {
|
|||||||
|
|
||||||
const getDellegaCallback = (data) => {
|
const getDellegaCallback = (data) => {
|
||||||
if (data.data) {
|
if (data.data) {
|
||||||
setDelega(data.data);
|
setDelega([data.data]);
|
||||||
}
|
}
|
||||||
storeSet.main.unsetAsyncRequest();
|
storeSet.main.unsetAsyncRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
const errDellegaCallback = () => {
|
const errDellegaCallback = () => {
|
||||||
setDelega({});
|
setDelega([]);
|
||||||
storeSet.main.unsetAsyncRequest();
|
storeSet.main.unsetAsyncRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -473,7 +473,7 @@ const ProfileCompany = () => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="appForm__delegaFormActions">
|
{/*<div className="appForm__delegaFormActions">
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
disabled={true}
|
disabled={true}
|
||||||
@@ -488,7 +488,8 @@ const ProfileCompany = () => {
|
|||||||
onClick={() => {
|
onClick={() => {
|
||||||
}}
|
}}
|
||||||
label={__('Sostituisci delega', 'gepafin')} icon="pi pi-sync" iconPos="right"/>
|
label={__('Sostituisci delega', 'gepafin')} icon="pi pi-sync" iconPos="right"/>
|
||||||
</div>
|
</div>*/}
|
||||||
|
|
||||||
</div> : <div className="appPage__spacer"></div>}
|
</div> : <div className="appPage__spacer"></div>}
|
||||||
|
|
||||||
<div className="appPageSection__hr">
|
<div className="appPageSection__hr">
|
||||||
|
|||||||
Reference in New Issue
Block a user