- added uploading files for evaluation;
- added uploading files for amendment for instructor; (need more tests)
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import React, { useMemo, useState, useEffect } from 'react';
|
||||
import { klona } from 'klona';
|
||||
import React, { useMemo, useState, useEffect, useCallback } from 'react';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { isEmpty } from 'ramda';
|
||||
import { isEmpty, head } from 'ramda';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
|
||||
// tools
|
||||
@@ -11,7 +10,12 @@ import uniqid from '../../../../helpers/uniqid';
|
||||
import FormField from '../../../../components/FormField';
|
||||
import { Button } from 'primereact/button';
|
||||
|
||||
const RepeaterFields = ({ sourceId, sourceName }) => {
|
||||
const RepeaterFields = ({
|
||||
sourceId,
|
||||
sourceName,
|
||||
updateFn = () => {},
|
||||
defaultValue = []
|
||||
}) => {
|
||||
const [items, setItems] = useState([]);
|
||||
const [chosen, setChosen] = useState('');
|
||||
const [formInitialData, setFormInitialData] = useState({});
|
||||
@@ -22,7 +26,7 @@ const RepeaterFields = ({ sourceId, sourceName }) => {
|
||||
setValue,
|
||||
register,
|
||||
trigger,
|
||||
getValues,
|
||||
reset,
|
||||
watch
|
||||
} = useForm({
|
||||
defaultValues: useMemo(() => {
|
||||
@@ -35,32 +39,49 @@ const RepeaterFields = ({ sourceId, sourceName }) => {
|
||||
const onSubmit = () => {
|
||||
};
|
||||
|
||||
const doUpdateAmendment = () => {
|
||||
const doUpdateAfterFileUploaded = () => {
|
||||
trigger();
|
||||
let formValues = klona(getValues());
|
||||
console.log('formValues', formValues);
|
||||
}
|
||||
|
||||
const addNew = () => {
|
||||
const addNew = useCallback(() => {
|
||||
setValue('nameValue', '');
|
||||
setValue('fileValue', {});
|
||||
setValue('fileValue', []);
|
||||
trigger();
|
||||
const uid = uniqid('f');
|
||||
const newItem = {
|
||||
fieldId: uid,
|
||||
name: '',
|
||||
file: {},
|
||||
nameValue: '',
|
||||
fileValue: [],
|
||||
valid: true
|
||||
}
|
||||
setItems([...items, newItem]);
|
||||
setChosen(uid);
|
||||
trigger();
|
||||
}
|
||||
}, [items]);
|
||||
|
||||
const setNewChosen = useCallback((id) => {
|
||||
const chosenObj = head(items.filter(o => id === o.fieldId));
|
||||
setChosen(chosen === id ? '' : id);
|
||||
reset();
|
||||
if (chosenObj) {
|
||||
setValue('nameValue', chosenObj.nameValue);
|
||||
setValue('fileValue', chosenObj.fileValue);
|
||||
}
|
||||
}, [items]);
|
||||
|
||||
const removeItem = useCallback((id) => {
|
||||
setItems([...items.filter(o => id !== o.fieldId)]);
|
||||
if (chosen === id) {
|
||||
setChosen('');
|
||||
reset();
|
||||
}
|
||||
}, [items, chosen]);
|
||||
|
||||
useEffect(() => {
|
||||
const updatedItems = items.map((o) => {
|
||||
return o.fieldId === chosen ? {
|
||||
...o,
|
||||
name: watchName
|
||||
nameValue: watchName
|
||||
} : o;
|
||||
})
|
||||
setItems([...updatedItems]);
|
||||
@@ -70,29 +91,35 @@ const RepeaterFields = ({ sourceId, sourceName }) => {
|
||||
const updatedItems = items.map((o) => {
|
||||
return o.fieldId === chosen ? {
|
||||
...o,
|
||||
file: watchFile
|
||||
fileValue: watchFile
|
||||
} : o;
|
||||
})
|
||||
setItems([...updatedItems]);
|
||||
}, [watchFile]);
|
||||
|
||||
useEffect(() => {
|
||||
console.log('items', items);
|
||||
updateFn(items);
|
||||
}, [items]);
|
||||
|
||||
//console.log('items', items, chosen);
|
||||
useEffect(() => {
|
||||
setItems(defaultValue);
|
||||
}, [])
|
||||
|
||||
console.log('items', items, chosen);
|
||||
return (
|
||||
<div className="fieldsRepeater">
|
||||
<form className="appForm" onSubmit={handleSubmit(onSubmit)}>
|
||||
{items
|
||||
? items.map(o => <div key={o.fieldId} className="fieldsRepeater__panel p-panel p-component">
|
||||
<div className="fieldsRepeater__heading p-panel p-panel-header">
|
||||
<span>{o.name}</span>
|
||||
<Button icon="pi pi-times" severity="danger"
|
||||
<span onClick={() => setNewChosen(o.fieldId)}>{o.nameValue}</span>
|
||||
<Button icon="pi pi-times"
|
||||
outlined
|
||||
severity="danger"
|
||||
className="actionBtn"
|
||||
type="button"
|
||||
aria-label={__('Cancella', 'gepafin')}
|
||||
onClick={() => console.log(o)}/>
|
||||
onClick={() => removeItem(o.fieldId)}/>
|
||||
</div>
|
||||
{chosen === o.fieldId
|
||||
? <div className="fieldsRepeater__fields p-panel-content">
|
||||
@@ -102,23 +129,25 @@ const RepeaterFields = ({ sourceId, sourceName }) => {
|
||||
label={__('Titolo del file', 'gepafin')}
|
||||
control={control}
|
||||
errors={errors}
|
||||
defaultValue={formInitialData['nameValue']}
|
||||
defaultValue={o.nameValue}
|
||||
config={{ required: __('È obbligatorio', 'gepafin') }}
|
||||
/>
|
||||
<FormField
|
||||
type="fileupload"
|
||||
disabled={isEmpty(o.nameValue)}
|
||||
setDataFn={setValue}
|
||||
saveFormCallback={doUpdateAmendment}
|
||||
saveFormCallback={doUpdateAfterFileUploaded}
|
||||
fieldName="fileValue"
|
||||
label={__('File', 'gepafin')}
|
||||
control={control}
|
||||
register={register}
|
||||
errors={errors}
|
||||
defaultValue={formInitialData['fileValue'] ? formInitialData['fileValue'] : []}
|
||||
defaultValue={o.fileValue ? o.fileValue : []}
|
||||
accept={[]}
|
||||
source={sourceName}
|
||||
sourceId={sourceId}
|
||||
multiple={false}
|
||||
config={{ required: __('È obbligatorio', 'gepafin') }}
|
||||
/>
|
||||
</div> : null}
|
||||
</div>
|
||||
@@ -126,10 +155,11 @@ const RepeaterFields = ({ sourceId, sourceName }) => {
|
||||
</form>
|
||||
<Button
|
||||
className="fieldsRepeater__addNew"
|
||||
outlined
|
||||
type="button"
|
||||
/*disabled={!isEmpty(chosen.fileId) && (isEmpty(chosen.name) || isEmpty(chosen.file))}*/
|
||||
onClick={addNew}
|
||||
label={__('Aggiungi nuovo', 'gepafin')}
|
||||
label={__('Aggiungi nuovo file', 'gepafin')}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -158,6 +158,12 @@ const DomandaEditPreInstructor = () => {
|
||||
criteria: klona(data.criteria),
|
||||
checklist: klona(data.checklist),
|
||||
files: klona(data.files),
|
||||
evaluationDocument: klona(data.evaluationDocument.map(o => ({
|
||||
...o,
|
||||
fileValue: o.fileValue[0] ? o.fileValue[0].id : ''
|
||||
})
|
||||
)),
|
||||
amendmentDetails: klona(data.amendmentDetails),
|
||||
note: data.note
|
||||
}
|
||||
|
||||
@@ -540,7 +546,14 @@ const DomandaEditPreInstructor = () => {
|
||||
|
||||
<div className="appPageSection">
|
||||
<h2>{__('Documenti aggiuntivi', 'gepafin')}</h2>
|
||||
<RepeaterFields sourceId={id} sourceName="evaluation"/>
|
||||
<RepeaterFields
|
||||
defaultValue={data.evaluationDocument ?? []}
|
||||
updateFn={(data) => updateEvaluationValue(
|
||||
data,
|
||||
['evaluationDocument']
|
||||
)}
|
||||
sourceId={data.assignedApplicationId}
|
||||
sourceName="evaluation"/>
|
||||
</div>
|
||||
|
||||
<div className="appPageSection">
|
||||
|
||||
@@ -193,7 +193,7 @@ const SoccorsoAddPreInstructor = () => {
|
||||
<div className="appPageSection">
|
||||
<div className="appPageSection columns">
|
||||
<div>
|
||||
<h3>{__('Note', 'gepafin')}</h3>
|
||||
<h3>{__('Pec/Email', 'gepafin')}</h3>
|
||||
<div style={{marginBottom: '30px'}}>
|
||||
<Editor
|
||||
value={formData.note}
|
||||
|
||||
@@ -113,7 +113,7 @@ const SoccorsoEditPreInstructor = () => {
|
||||
const header = renderHeader();
|
||||
|
||||
const updateNewAmendmentData = (value, path) => {
|
||||
const newData = wrap(data).set(path.split('.'), value).value();
|
||||
const newData = wrap(data).set(path, value).value();
|
||||
setData(newData);
|
||||
}
|
||||
|
||||
@@ -136,10 +136,22 @@ const SoccorsoEditPreInstructor = () => {
|
||||
});
|
||||
return acc;
|
||||
}, []);
|
||||
const newAmendDocs = data.amendmentDocuments
|
||||
.reduce((acc, cur) => {
|
||||
const newObj = {
|
||||
...klona(cur),
|
||||
fileValue: cur.fileValue[0] ? cur.fileValue[0].id : ''
|
||||
}
|
||||
|
||||
acc.push(newObj);
|
||||
return acc;
|
||||
}, []);
|
||||
|
||||
const submitData = {
|
||||
applicationFormFields: newFormValues
|
||||
applicationFormFields: newFormValues,
|
||||
amendmentDocuments: newAmendDocs
|
||||
}
|
||||
|
||||
storeSet.main.setAsyncRequest();
|
||||
AmendmentsService.updateSoccorso(amendmentId, submitData, updateAmendmentCallback, errUpdateAmendmentCallback);
|
||||
}
|
||||
@@ -177,6 +189,7 @@ const SoccorsoEditPreInstructor = () => {
|
||||
}
|
||||
|
||||
const doCloseAmendment = () => {
|
||||
doUpdateAmendment();
|
||||
const submitData = {
|
||||
internalNote: data.internalNote
|
||||
}
|
||||
@@ -194,7 +207,7 @@ const SoccorsoEditPreInstructor = () => {
|
||||
});
|
||||
}
|
||||
if (data.data.status) {
|
||||
updateNewAmendmentData(data.data.status, 'status')
|
||||
updateNewAmendmentData(data.data.status, ['status'])
|
||||
}
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
@@ -311,6 +324,10 @@ const SoccorsoEditPreInstructor = () => {
|
||||
AmendmentsService.getSoccorsoById(getCallback, errGetCallback, [['id', soccorsoEntityId]]);
|
||||
}, [amendmentId]);
|
||||
|
||||
useEffect(() => {
|
||||
console.log(data);
|
||||
}, [data]);
|
||||
|
||||
return (
|
||||
<div className="appPage">
|
||||
<div className="appPage__pageHeader">
|
||||
@@ -389,17 +406,12 @@ const SoccorsoEditPreInstructor = () => {
|
||||
<SoccorsoComunications amendmentId={amendmentId} soccorsoStatus={data.status}/>
|
||||
</div>
|
||||
|
||||
<div className="appPageSection">
|
||||
<h2>{__('Documenti ricevuti', 'gepafin')}</h2>
|
||||
<RepeaterFields sourceId={id} sourceName="evaluation"/>
|
||||
</div>
|
||||
{data.formFields && !isEmpty(data.formFields)
|
||||
? <div className="appPageSection">
|
||||
<h2>{__('Documenti Ricevuti', 'gepafin')}</h2>
|
||||
|
||||
<div className="appPageSection">
|
||||
<h2>{__('Documenti Ricevuti', 'gepafin')}</h2>
|
||||
|
||||
<form className="appForm" onSubmit={handleSubmit(onSubmit)}>
|
||||
{data.formFields
|
||||
? data.formFields.map((o, i) => {
|
||||
<form className="appForm" onSubmit={handleSubmit(onSubmit)}>
|
||||
{data.formFields.map((o, i) => {
|
||||
return <FormField
|
||||
key={o.fieldId}
|
||||
disabled={data.status === 'CLOSE'}
|
||||
@@ -417,8 +429,20 @@ const SoccorsoEditPreInstructor = () => {
|
||||
sourceId={data.applicationId}
|
||||
multiple={true}
|
||||
/>
|
||||
}) : null}
|
||||
</form>
|
||||
})}
|
||||
</form>
|
||||
</div> : null}
|
||||
|
||||
<div className="appPageSection">
|
||||
<h2>{__('Documenti aggiuntivi', 'gepafin')}</h2>
|
||||
<RepeaterFields
|
||||
defaultValue={data.amendmentDocuments ?? []}
|
||||
updateFn={(data) => updateNewAmendmentData(
|
||||
data,
|
||||
['amendmentDocuments']
|
||||
)}
|
||||
sourceId={amendmentId}
|
||||
sourceName="AMENDMENT"/>
|
||||
</div>
|
||||
|
||||
<div className="appForm__field">
|
||||
@@ -432,7 +456,7 @@ const SoccorsoEditPreInstructor = () => {
|
||||
headerTemplate={header}
|
||||
onTextChange={(e) => updateNewAmendmentData(
|
||||
e.htmlValue,
|
||||
'internalNote'
|
||||
['internalNote']
|
||||
)}
|
||||
style={{ height: 80 * 3, width: '100%' }}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user