- added proper fields for amendment note and documents;
- rewritten logic for repeater field;
This commit is contained in:
@@ -36,6 +36,7 @@ const SoccorsoEditPreInstructor = () => {
|
||||
const { id, amendmentId } = useParams();
|
||||
const navigate = useNavigate();
|
||||
const [data, setData] = useState({});
|
||||
const [isVisibleCloseAmendDialog, setIsVisibleCloseAmendDialog] = useState(false);
|
||||
const [isVisibleExtendTimeDialog, setIsVisibleExtendTimeDialog] = useState(false);
|
||||
const [extendedTime, setExtendedTime] = useState(3);
|
||||
const [isLoadingExtendingTime, setIsLoadingExtendingTime] = useState(false);
|
||||
@@ -63,12 +64,16 @@ const SoccorsoEditPreInstructor = () => {
|
||||
const getCallback = (data) => {
|
||||
if (data.status === 'SUCCESS') {
|
||||
setData(getFormattedData(data.data));
|
||||
const formDataInitial = data.data.applicationFormFields.reduce((acc, cur) => {
|
||||
let formDataInitial = data.data.applicationFormFields.reduce((acc, cur) => {
|
||||
if (cur.fieldValue) {
|
||||
acc[cur.fieldId] = cur.fieldValue;
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
formDataInitial = {
|
||||
...formDataInitial,
|
||||
amendmentDocuments: data.amendmentDocuments
|
||||
}
|
||||
setFormInitialData(formDataInitial);
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
@@ -124,6 +129,7 @@ const SoccorsoEditPreInstructor = () => {
|
||||
trigger();
|
||||
let formValues = klona(getValues());
|
||||
const newFormValues = Object.keys(formValues)
|
||||
.filter(v => v !== 'amendmentDocuments')
|
||||
.reduce((acc, cur) => {
|
||||
let fieldVal = formValues[cur];
|
||||
|
||||
@@ -136,16 +142,7 @@ 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 newAmendDocs = formValues.amendmentDocuments.map(o => o.id).join(',');
|
||||
|
||||
const submitData = {
|
||||
applicationFormFields: newFormValues,
|
||||
@@ -188,8 +185,29 @@ const SoccorsoEditPreInstructor = () => {
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
|
||||
const openCloseAmendmentDialog = () => {
|
||||
setIsVisibleCloseAmendDialog(true);
|
||||
}
|
||||
|
||||
const headerCloseAmendDialog = () => {
|
||||
return <span>{__('Chiudi Soccorso Istruttorio', 'gepafin')}</span>
|
||||
}
|
||||
|
||||
const hideCloseAmendDialog = () => {
|
||||
setIsVisibleCloseAmendDialog(false);
|
||||
}
|
||||
|
||||
const footerCloseAmendDialog = () => {
|
||||
return <div>
|
||||
<Button type="button" label={__('Anulla', 'gepafin')} onClick={hideCloseAmendDialog} outlined/>
|
||||
<Button
|
||||
type="button"
|
||||
disabled={isAsyncRequest || isEmpty(data.internalNotes)}
|
||||
label={__('Invia', 'gepafin')} onClick={doCloseAmendment}/>
|
||||
</div>
|
||||
}
|
||||
|
||||
const doCloseAmendment = () => {
|
||||
doUpdateAmendment();
|
||||
const submitData = {
|
||||
internalNote: data.internalNote
|
||||
}
|
||||
@@ -311,7 +329,6 @@ const SoccorsoEditPreInstructor = () => {
|
||||
|
||||
useEffect(() => {
|
||||
if (formInitialData) {
|
||||
//reset();
|
||||
Object.keys(formInitialData).map(k => setValue(k, formInitialData[k]));
|
||||
trigger();
|
||||
}
|
||||
@@ -324,7 +341,6 @@ const SoccorsoEditPreInstructor = () => {
|
||||
AmendmentsService.getSoccorsoById(getCallback, errGetCallback, [['id', soccorsoEntityId]]);
|
||||
}, [amendmentId]);
|
||||
|
||||
console.log('data', data.amendmentDocuments);
|
||||
return (
|
||||
<div className="appPage">
|
||||
<div className="appPage__pageHeader">
|
||||
@@ -432,31 +448,28 @@ const SoccorsoEditPreInstructor = () => {
|
||||
|
||||
<div className="appPageSection">
|
||||
<h2>{__('Documenti aggiuntivi', 'gepafin')}</h2>
|
||||
{data.id
|
||||
? <RepeaterFields
|
||||
defaultValue={data.amendmentDocuments ?? []}
|
||||
updateFn={(data) => updateNewAmendmentData(
|
||||
data,
|
||||
['amendmentDocuments']
|
||||
)}
|
||||
sourceId={amendmentId}
|
||||
sourceName="AMENDMENT"/> : null}
|
||||
</div>
|
||||
|
||||
<div className="appForm__field">
|
||||
<label>{__('Motivazioni / Note Interne', 'gepafin')}</label>
|
||||
<div style={{ position: 'relative' }}>
|
||||
<BlockingOverlay shouldDisplay={data.status === 'CLOSE'}/>
|
||||
<Editor
|
||||
value={data.internalNote}
|
||||
readOnly={data.status === 'CLOSE'}
|
||||
placeholder={__('Digita qui il messagio', 'gepafin')}
|
||||
headerTemplate={header}
|
||||
onTextChange={(e) => updateNewAmendmentData(
|
||||
e.htmlValue,
|
||||
['internalNote']
|
||||
)}
|
||||
style={{ height: 80 * 3, width: '100%' }}
|
||||
<div className="appPageSection columns">
|
||||
{data.amendmentNotes
|
||||
? <>
|
||||
<h3>{__('Notes', 'gepafin')}</h3>
|
||||
<div className="ql-editor" style={{ marginBottom: '30px', width: '100%' }}>
|
||||
{renderHtmlContent(data.amendmentNotes)}
|
||||
</div>
|
||||
</> : null}
|
||||
<FormField
|
||||
type="fileupload"
|
||||
setDataFn={setValue}
|
||||
saveFormCallback={doUpdateAmendment}
|
||||
fieldName="amendmentDocuments"
|
||||
label={__('I file', 'gepafin')}
|
||||
control={control}
|
||||
register={register}
|
||||
errors={errors}
|
||||
defaultValue={formInitialData.amendmentDocuments ? formInitialData.amendmentDocuments : []}
|
||||
accept={[]}
|
||||
source="amendment"
|
||||
sourceId={amendmentId}
|
||||
multiple={true}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -469,6 +482,12 @@ const SoccorsoEditPreInstructor = () => {
|
||||
|
||||
<div className="appPageSection">
|
||||
<div className="appPageSection__actions">
|
||||
<Button
|
||||
type="button"
|
||||
disabled={isAsyncRequest}
|
||||
onClick={doUpdateAmendment}
|
||||
label={__('Salva', 'gepafin')}
|
||||
icon="pi pi-save" iconPos="right"/>
|
||||
<Button
|
||||
type="button"
|
||||
onClick={sendReminder}
|
||||
@@ -493,7 +512,7 @@ const SoccorsoEditPreInstructor = () => {
|
||||
icon="pi pi-save" iconPos="right"/>*/}
|
||||
<Button
|
||||
type="button"
|
||||
onClick={doCloseAmendment}
|
||||
onClick={openCloseAmendmentDialog}
|
||||
disabled={isAsyncRequest || data.status === 'CLOSE'}
|
||||
label={__('Chiudi Soccorso Istruttorio', 'gepafin')}
|
||||
icon="pi pi-times" iconPos="right"/>
|
||||
@@ -522,6 +541,32 @@ const SoccorsoEditPreInstructor = () => {
|
||||
onChange={(e) => setExtendedTime(e.value)}/>
|
||||
</div>
|
||||
</Dialog>
|
||||
|
||||
<Dialog
|
||||
visible={isVisibleCloseAmendDialog}
|
||||
modal
|
||||
header={headerCloseAmendDialog}
|
||||
footer={footerCloseAmendDialog}
|
||||
style={{ maxWidth: '600px', width: '100%' }}
|
||||
onHide={hideCloseAmendDialog}>
|
||||
<div className="appForm__field">
|
||||
<label>{__('Motivazioni', 'gepafin')}</label>
|
||||
<div style={{ position: 'relative' }}>
|
||||
<BlockingOverlay shouldDisplay={data.status === 'CLOSE'}/>
|
||||
<Editor
|
||||
value={data.internalNote}
|
||||
readOnly={data.status === 'CLOSE'}
|
||||
placeholder={__('Digita qui il messagio', 'gepafin')}
|
||||
headerTemplate={header}
|
||||
onTextChange={(e) => updateNewAmendmentData(
|
||||
e.htmlValue,
|
||||
['internalNote']
|
||||
)}
|
||||
style={{ height: 80 * 3, width: '100%' }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog>
|
||||
</div>
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user