From bf18be2b174a83e4b8a7774117fdae93db7af5c7 Mon Sep 17 00:00:00 2001 From: Vitalii Kiiko Date: Fri, 13 Mar 2026 18:31:47 +0100 Subject: [PATCH] - updated; --- src/pages/DomandaEditPreInstructor/index.js | 2 +- src/pages/ProfileCompany/index.js | 4 +- src/pages/SoccorsoEditPreInstructor/index.js | 359 ++++++++++++++++++- src/service/amendments-service.js | 8 + 4 files changed, 360 insertions(+), 13 deletions(-) diff --git a/src/pages/DomandaEditPreInstructor/index.js b/src/pages/DomandaEditPreInstructor/index.js index 008bca7..7b44651 100644 --- a/src/pages/DomandaEditPreInstructor/index.js +++ b/src/pages/DomandaEditPreInstructor/index.js @@ -1302,7 +1302,7 @@ const DomandaEditPreInstructor = () => { storeSet('setAsyncRequest'); ApplicationEvaluationService.getEvaluationVersionByApplId(entityId, getVersion, errGetVersion); AmendmentsService.getSoccorsoByApplId(entityId, getAmendmentsCallback, errGetAmendmentsCallback, [ - ['statuses', ['AWAITING', 'RESPONSE_RECEIVED']] + ['statuses', ['AWAITING', 'RESPONSE_RECEIVED', 'DRAFT']] ]); }, [id]); diff --git a/src/pages/ProfileCompany/index.js b/src/pages/ProfileCompany/index.js index eecd0c1..eeea9ff 100644 --- a/src/pages/ProfileCompany/index.js +++ b/src/pages/ProfileCompany/index.js @@ -66,7 +66,7 @@ const ProfileCompany = () => { }); const isLegalRepresentant = watch('isLegalRepresentant') - const setEmptyValues = () => { + /*const setEmptyValues = () => { const formData = { cap: '', pec: '', @@ -77,7 +77,7 @@ const ProfileCompany = () => { companyName: '' } Object.keys(formData).map(k => setValue(k, formData[k])); - } + }*/ const onSubmit = (formData) => { infoMsgs.current.clear(); diff --git a/src/pages/SoccorsoEditPreInstructor/index.js b/src/pages/SoccorsoEditPreInstructor/index.js index 702e2b6..4b02a83 100644 --- a/src/pages/SoccorsoEditPreInstructor/index.js +++ b/src/pages/SoccorsoEditPreInstructor/index.js @@ -27,10 +27,15 @@ import { Dialog } from 'primereact/dialog'; import FormField from '../../components/FormField'; import { Editor } from 'primereact/editor'; import { InputNumber } from 'primereact/inputnumber'; +import { Checkbox } from 'primereact/checkbox'; +import { InputSwitch } from 'primereact/inputswitch'; +import { FileUpload } from 'primereact/fileupload'; +import { Skeleton } from 'primereact/skeleton'; import SoccorsoComunications from './components/SoccorsoComunications'; import SoccorsoResendEmails from './components/SoccorsoResendEmails'; -import { amendmentRequestedDocs } from '../../configData'; +import { amendmentRequestedDocs, defaultMaxFileSize, mimeTypes } from '../../configData'; +import getFormatedFileSizeText from '../../helpers/getFormatedFileSizeText'; const SoccorsoEditPreInstructor = () => { const isAsyncRequest = useStoreValue('isAsyncRequest'); @@ -45,6 +50,9 @@ const SoccorsoEditPreInstructor = () => { const [internalNote, setInternalNote] = useState(''); const toast = useRef(null); const [formInitialData, setFormInitialData] = useState({}); + const [draftFormData, setDraftFormData] = useState({}); + const draftFilesRef = useRef(null); + const [isVisibleDeleteDraftDialog, setIsVisibleDeleteDraftDialog] = useState(false); const emailSendResponse = pathOr([], ['emailSendResponse'], data); const { control, @@ -67,17 +75,27 @@ const SoccorsoEditPreInstructor = () => { const getCallback = (data) => { if (data.status === 'SUCCESS') { setData(getFormattedData(data.data)); - let formDataInitial = data.data.applicationFormFields.reduce((acc, cur) => { - if (cur.fieldValue) { - acc[cur.fieldId] = cur.fieldValue; + if (data.data.status === 'DRAFT') { + setDraftFormData({ + formFields: data.data.formFields || [], + responseDays: data.data.responseDays || 10, + note: data.data.note || '', + isSendNotification: data.data.isSendNotification ?? true, + isSendEmail: data.data.isSendEmail ?? true, + }); + } else { + let formDataInitial = (data.data.applicationFormFields || []).reduce((acc, cur) => { + if (cur.fieldValue) { + acc[cur.fieldId] = cur.fieldValue; + } + return acc; + }, {}); + formDataInitial = { + ...formDataInitial, + amendmentDocuments: data.data.amendmentDocuments } - return acc; - }, {}); - formDataInitial = { - ...formDataInitial, - amendmentDocuments: data.data.amendmentDocuments + setFormInitialData(formDataInitial); } - setFormInitialData(formDataInitial); } storeSet('unsetAsyncRequest'); } @@ -125,6 +143,99 @@ const SoccorsoEditPreInstructor = () => { setData(newData); } + const updateDraftValue = (value, path, maxValue) => { + let finalValue = value; + if (maxValue) { + finalValue = value > maxValue ? maxValue : value; + } + const newData = wrap(draftFormData).set(path.split('.'), finalValue).value(); + setDraftFormData(newData); + } + + const doSendDraft = () => { + storeSet('setAsyncRequest'); + const payload = { + note: draftFormData.note, + responseDays: draftFormData.responseDays, + isSendNotification: draftFormData.isSendNotification, + isSendEmail: draftFormData.isSendEmail, + formFields: draftFormData.formFields, + }; + const formDataToSend = new FormData(); + const jsonBlob = new Blob([JSON.stringify(payload)], { type: 'application/json' }); + formDataToSend.append('applicationAmendmentRequest', jsonBlob); + if (draftFormData.files && draftFormData.files.length > 0) { + draftFormData.files.forEach(file => formDataToSend.append('files', file)); + } + AmendmentsService.updateDraftSoccorso(amendmentId, formDataToSend, updateDraftCallback, errUpdateDraftCallback); + }; + + const updateDraftCallback = (resp) => { + if (resp.status === 'SUCCESS') { + AmendmentsService.updateStatusSoccorso(amendmentId, sendStatusCallback, errSendStatusCallback); + } else { + storeSet('unsetAsyncRequest'); + } + }; + + const sendStatusCallback = (resp) => { + if (resp.status === 'SUCCESS') { + storeSet('setAsyncRequest'); + AmendmentsService.getSoccorsoById(getCallback, errGetCallback, [['id', parseInt(amendmentId)]]); + } else { + storeSet('unsetAsyncRequest'); + } + }; + + const errUpdateDraftCallback = (resp) => { + if (toast.current && resp.message) { + toast.current.show({ + severity: 'error', + summary: '', + detail: resp.message + }); + } + set404FromErrorResponse(resp); + storeSet('unsetAsyncRequest'); + }; + + const errSendStatusCallback = (resp) => { + if (toast.current && resp.message) { + toast.current.show({ + severity: 'error', + summary: '', + detail: resp.message + }); + } + set404FromErrorResponse(resp); + storeSet('unsetAsyncRequest'); + }; + + const doDeleteDraft = () => { + storeSet('setAsyncRequest'); + AmendmentsService.deleteSoccorso(amendmentId, deleteCallback, errDeleteCallback); + }; + + const deleteCallback = (resp) => { + if (resp.status === 'SUCCESS') { + goToEvaluationPage(); + } else { + storeSet('unsetAsyncRequest'); + } + }; + + const errDeleteCallback = (resp) => { + if (toast.current && resp.message) { + toast.current.show({ + severity: 'error', + summary: '', + detail: resp.message + }); + } + set404FromErrorResponse(resp); + storeSet('unsetAsyncRequest'); + }; + const onSubmit = () => { }; @@ -376,6 +487,13 @@ const SoccorsoEditPreInstructor = () => { AmendmentsService.getSoccorsoById(getCallback, errGetCallback, [['id', soccorsoEntityId]]); }, [amendmentId]); + useEffect(() => { + if (draftFilesRef.current && data.status === 'DRAFT') { + const existingFiles = data.amendmentInitialDocuments || data.amendmentInitialDocument || []; + draftFilesRef.current.setUploadedFiles(is(Array, existingFiles) ? existingFiles : []); + } + }, [data]); + return (
@@ -398,6 +516,203 @@ const SoccorsoEditPreInstructor = () => {
+ {!isAsyncRequest && !isEmpty(data) && data.status === 'DRAFT' + ? <> +
+

+ {__('ID domanda', 'gepafin')} + {data.applicationId} +

+

+ {__('Bando', 'gepafin')} + {data.callName} +

+

+ {__('Referente Aziendale', 'gepafin')} + {data.beneficiaryName} +

+
+ +
+
+
+

{__('Pec/Email', 'gepafin')}

+
+ updateDraftValue(e.htmlValue, 'note')} + style={{ height: 80 * 3, width: '100%' }} + /> +
+ +
+
+ + o.code).join(',')} + maxFileSize={defaultMaxFileSize} + auto={false} + customUpload={true} + onSelect={(e) => { + updateDraftValue(e.files, 'files'); + }} + onRemove={() => { + const updatedFiles = draftFilesRef.current.getFiles(); + updateDraftValue(updatedFiles, 'files'); + }} + headerTemplate={(options) => { + const { chooseButton } = options; + return ( +
+ {chooseButton} +
+ ); + }} + chooseOptions={{ + label: __('Aggiungi i file', 'gepafin'), + icon: 'pi pi-plus' + }} + itemTemplate={(file, props) => { + if (file.id) { + return ( + + ); + } + return ( +
+
+
+ {file.name} +
+ {getFormatedFileSizeText(file.size)} +
+
+
+
+ ); + }} + emptyTemplate={

{__('Trascina i file qua')}

} + /> +
+
+ +

{__('Tempo per la Risposta (giorni)', 'gepafin')}

+
+ updateDraftValue(e.value, 'responseDays', 9999)}/> +
+ +

{__('Notifica', 'gepafin')}

+
+
+ updateDraftValue(e.value, 'isSendEmail')}/> + +
+
+ updateDraftValue(e.value, 'isSendNotification')}/> + +
+
+
+ {draftFormData.formFields && !isEmpty(draftFormData.formFields) + ?
+

{__('Documenti da Integrare', 'gepafin')}

+
+
+ {draftFormData.formFields.map((o, i) =>
+ updateDraftValue( + e.checked, + `formFields.${i}.selected` + )} + checked={o.selected}/> + +
)} +
+
+
+ : null} +
+
+ +
+ + {__('Attenzione', 'gepafin')} + {__('L\'invio della richiesta di integrazione sospenderà il termine di valutazione della domanda.', 'gepafin')} +
+ +
+ {__('Azioni', 'gepafin')} +
+ +
+
+
+
+ + : !isAsyncRequest && !isEmpty(data) + ? <>

{__('ID domanda', 'gepafin')} @@ -573,6 +888,17 @@ const SoccorsoEditPreInstructor = () => { setDataEmailsSoccorso={updateEmailSendResponses}/>

+ + : <> + + + + + + + + + }
@@ -619,6 +945,19 @@ const SoccorsoEditPreInstructor = () => {
+ + {__('Elimina bozza', 'gepafin')}} + footer={
+
} + style={{ maxWidth: '500px', width: '100%' }} + onHide={() => setIsVisibleDeleteDraftDialog(false)}> +

{__('Sei sicuro di voler eliminare questa bozza? L\'operazione non può essere annullata.', 'gepafin')}

+
) diff --git a/src/service/amendments-service.js b/src/service/amendments-service.js index 0c35bbd..fb35b91 100644 --- a/src/service/amendments-service.js +++ b/src/service/amendments-service.js @@ -32,6 +32,14 @@ export default class AmendmentsService { NetworkService.put(`${API_BASE_URL}/amendments/${id}`, body, callback, errCallback, queryParams); }; + static updateDraftSoccorso = (id, body, callback, errCallback, queryParams) => { + NetworkService.putMultiPart(`${API_BASE_URL}/amendments/${id}`, body, callback, errCallback, queryParams); + }; + + static deleteSoccorso = (id, callback, errCallback) => { + NetworkService.delete(`${API_BASE_URL}/amendments/${id}`, {}, callback, errCallback); + }; + static updateStatusSoccorso = (id, callback, errCallback, queryParams) => { NetworkService.put(`${API_BASE_URL}/amendments/${id}/status`, {}, callback, errCallback, queryParams); };