- saving progress;
This commit is contained in:
@@ -18,7 +18,7 @@ import set404FromErrorResponse from '../../../../helpers/set404FromErrorResponse
|
||||
import { storeSet } from '../../../../store';
|
||||
import { Toast } from 'primereact/toast';
|
||||
|
||||
const ArchiveDocument = ({ applicationId, ndg = '', fileId = 0 }) => {
|
||||
const ArchiveDocument = ({ applicationId, ndg = '', fileId = 0, docAttachmentId = null }) => {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [isVisibleDialog, setIsVisibleDialog] = useState(false);
|
||||
const [modalData, setModalData] = useState({});
|
||||
@@ -119,7 +119,7 @@ const ArchiveDocument = ({ applicationId, ndg = '', fileId = 0 }) => {
|
||||
setTypes(protocolType.map(o => ({ value: o.id, label: o.name })));
|
||||
}, []);
|
||||
|
||||
return (!isEmpty(ndg)
|
||||
return (!isEmpty(ndg) && !docAttachmentId
|
||||
? <>
|
||||
<Toast ref={toast}/>
|
||||
<Button icon="pi pi-file-export"
|
||||
|
||||
@@ -53,7 +53,7 @@ const ListOfFiles = ({ files, updateFn, shouldDisableFieldFn, name, ndg, applica
|
||||
}}>
|
||||
<span>{k.name}</span>
|
||||
<div className="appPageSection__iconActions">
|
||||
<ArchiveDocument ndg={ndg} applicationId={applicationId} fileId={k.id}/>
|
||||
<ArchiveDocument ndg={ndg} applicationId={applicationId} fileId={k.id} docAttachmentId={k.documentAttachmentId}/>
|
||||
<Button icon="pi pi-eye" rounded
|
||||
onClick={() => {
|
||||
window.open(k.filePath, '_blank').focus()
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
import React, { useMemo, useState, useEffect } from 'react';
|
||||
import { klona } from 'klona';
|
||||
import { useForm } from 'react-hook-form';
|
||||
|
||||
// tools
|
||||
import uniqid from '../../../../helpers/uniqid';
|
||||
|
||||
// components
|
||||
import FormField from '../../../../components/FormField';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { Button } from 'primereact/button';
|
||||
|
||||
const RepeaterFields = ({ sourceId, sourceName }) => {
|
||||
const [items, setItems] = useState([]);
|
||||
const [chosen, setChosen] = useState({});
|
||||
const [formInitialData, setFormInitialData] = useState({});
|
||||
const {
|
||||
control,
|
||||
handleSubmit,
|
||||
formState: { errors },
|
||||
setValue,
|
||||
register,
|
||||
trigger,
|
||||
getValues
|
||||
} = useForm({
|
||||
defaultValues: useMemo(() => {
|
||||
return formInitialData;
|
||||
}, [formInitialData]), mode: 'onChange'
|
||||
});
|
||||
|
||||
const onSubmit = () => {
|
||||
};
|
||||
|
||||
const doUpdateAmendment = () => {
|
||||
trigger();
|
||||
let formValues = klona(getValues());
|
||||
console.log('formValues', formValues);
|
||||
}
|
||||
|
||||
const addNew = () => {
|
||||
const uid = uniqid('f');
|
||||
const newItem = {
|
||||
fieldId: uid,
|
||||
name: '',
|
||||
file: {},
|
||||
}
|
||||
setItems([...items, newItem]);
|
||||
setChosen(newItem);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
}, [chosen])
|
||||
console.log('items', items);
|
||||
return (
|
||||
<div className="fieldsRepeater">
|
||||
<form className="appForm" onSubmit={handleSubmit(onSubmit)}>
|
||||
{items
|
||||
? items.map(o => <div key={o.fieldId}>
|
||||
<div className="fieldsRepeater__Heading">
|
||||
<span>{o.name}</span>
|
||||
</div>
|
||||
{chosen.fieldId === o.fieldId
|
||||
? <div className="fieldsRepeater__fields">
|
||||
<FormField
|
||||
type="textinput"
|
||||
fieldName="name"
|
||||
label={__('Titolo del file', 'gepafin')}
|
||||
control={control}
|
||||
errors={errors}
|
||||
defaultValue={formInitialData['name']}
|
||||
config={{ required: __('È obbligatorio', 'gepafin') }}
|
||||
/>
|
||||
<FormField
|
||||
type="fileupload"
|
||||
setDataFn={setValue}
|
||||
saveFormCallback={doUpdateAmendment}
|
||||
fieldName="file"
|
||||
label={__('File', 'gepafin')}
|
||||
control={control}
|
||||
register={register}
|
||||
errors={errors}
|
||||
defaultValue={formInitialData['file'] ? formInitialData['file'] : []}
|
||||
accept={[]}
|
||||
source={sourceName}
|
||||
sourceId={sourceId}
|
||||
multiple={false}
|
||||
/>
|
||||
</div> : null}
|
||||
</div>
|
||||
) : null}
|
||||
</form>
|
||||
<Button
|
||||
type="button"
|
||||
disabled={false}
|
||||
onClick={addNew}
|
||||
label={__('Aggiungi nuovo', 'gepafin')}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default RepeaterFields;
|
||||
Reference in New Issue
Block a user