- saving progress;

This commit is contained in:
Vitalii Kiiko
2024-12-16 15:13:41 +01:00
parent 9789f5a07a
commit ea2b46ddfe
5 changed files with 102 additions and 64 deletions

View File

@@ -13,9 +13,12 @@ import { Button } from 'primereact/button';
const RepeaterFields = ({
sourceId,
sourceName,
updateFn = () => {},
defaultValue = []
}) => {
updateFn = () => {
},
defaultValue = [],
updateCallbackFn = () => {
}
}) => {
const [items, setItems] = useState([]);
const [chosen, setChosen] = useState('');
const [formInitialData, setFormInitialData] = useState({});
@@ -27,7 +30,8 @@ const RepeaterFields = ({
register,
trigger,
reset,
watch
watch,
getValues
} = useForm({
defaultValues: useMemo(() => {
return formInitialData;
@@ -51,8 +55,7 @@ const RepeaterFields = ({
const newItem = {
fieldId: uid,
nameValue: '',
fileValue: [],
valid: true
fileValue: []
}
setItems([...items, newItem]);
setChosen(uid);
@@ -93,7 +96,7 @@ const RepeaterFields = ({
...o,
fileValue: watchFile
} : o;
})
});
setItems([...updatedItems]);
}, [watchFile]);
@@ -105,7 +108,6 @@ const RepeaterFields = ({
setItems(defaultValue);
}, [])
console.log('items', items, chosen);
return (
<div className="fieldsRepeater">
<form className="appForm" onSubmit={handleSubmit(onSubmit)}>
@@ -157,7 +159,7 @@ const RepeaterFields = ({
className="fieldsRepeater__addNew"
outlined
type="button"
/*disabled={!isEmpty(chosen.fileId) && (isEmpty(chosen.name) || isEmpty(chosen.file))}*/
disabled={!isEmpty(chosen.fileId) && (isEmpty(watchName) || isEmpty(watchFile))}
onClick={addNew}
label={__('Aggiungi nuovo file', 'gepafin')}
/>