diff --git a/src/assets/scss/components/appForm.scss b/src/assets/scss/components/appForm.scss index 9b8b5c8..bb2c482 100644 --- a/src/assets/scss/components/appForm.scss +++ b/src/assets/scss/components/appForm.scss @@ -2,6 +2,7 @@ display: flex; flex-direction: column; gap: 24px; + width: 100%; } .appForm__field { position: relative; diff --git a/src/assets/scss/components/layout.scss b/src/assets/scss/components/layout.scss index e94353e..714504e 100644 --- a/src/assets/scss/components/layout.scss +++ b/src/assets/scss/components/layout.scss @@ -22,6 +22,10 @@ body { h2, h3, p, label, .appPageSection__hr { color: var(--global-textColor); } + + textarea { + max-width: 100%; + } } #root, .wrapper { diff --git a/src/helpers/getBandoLabel.js b/src/helpers/getBandoLabel.js index 35a850e..43abcd3 100644 --- a/src/helpers/getBandoLabel.js +++ b/src/helpers/getBandoLabel.js @@ -17,6 +17,9 @@ const getBandoLabel = (status) => { case 'READY': return __('Pronto', 'gepafin'); + case 'SOCCORSO': + return __('Soccorso', 'gepafin'); + case 'DRAFT': return __('Bozza', 'gepafin'); @@ -38,6 +41,9 @@ const getBandoLabel = (status) => { case 'EXPIRED': return __('Scaduto', 'gepafin'); + case 'CLOSE': + return __('Chiuso', 'gepafin'); + default: return ''; } diff --git a/src/helpers/getBandoSeverity.js b/src/helpers/getBandoSeverity.js index d090c80..631cfe6 100644 --- a/src/helpers/getBandoSeverity.js +++ b/src/helpers/getBandoSeverity.js @@ -15,6 +15,9 @@ const getBandoSeverity = (status) => { case 'READY': return 'info'; + case 'SOCCORSO': + return 'warning'; + case 'DRAFT': return 'warning'; @@ -36,6 +39,9 @@ const getBandoSeverity = (status) => { case 'EXPIRED': return 'closed'; + case 'CLOSE': + return 'closed'; + default: return 'info'; } diff --git a/src/pages/BandoViewBeneficiario/index.js b/src/pages/BandoViewBeneficiario/index.js index 92d2ac2..c76735f 100644 --- a/src/pages/BandoViewBeneficiario/index.js +++ b/src/pages/BandoViewBeneficiario/index.js @@ -406,8 +406,7 @@ const BandoViewBeneficiario = () => { : null}
- {/*

{__('Download Documenti', 'gepafin')}

*/} -

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

+

{__('Download Documenti', 'gepafin')}

{/*
- {__('Azioni rapide', 'gepafin')} + {__('Azioni', 'gepafin')}
diff --git a/src/pages/SoccorsoEditPreInstructor/index.js b/src/pages/SoccorsoEditPreInstructor/index.js index d0835be..f048d4e 100644 --- a/src/pages/SoccorsoEditPreInstructor/index.js +++ b/src/pages/SoccorsoEditPreInstructor/index.js @@ -1,7 +1,7 @@ -import React, { useState, useEffect, useRef } from 'react'; +import React, { useState, useEffect, useRef, useMemo } from 'react'; import { __ } from '@wordpress/i18n'; import { useNavigate, useParams } from 'react-router-dom'; -import { is, isEmpty, isNil } from 'ramda'; +import { head, is, isEmpty, isNil, pathOr } from 'ramda'; import { wrap } from 'object-path-immutable'; // store @@ -26,6 +26,13 @@ import { classNames } from 'primereact/utils'; import { Dialog } from 'primereact/dialog'; import { InputText } from 'primereact/inputtext'; import { InputTextarea } from 'primereact/inputtextarea'; +import { klona } from 'klona'; +import { useForm } from 'react-hook-form'; +import FormField from '../../components/FormField'; +import uniqid from '../../helpers/uniqid'; +import { Editor } from 'primereact/editor'; +import { TZDate } from '@date-fns/tz'; +import { InputNumber } from 'primereact/inputnumber'; const SoccorsoEditPreInstructor = () => { const isAsyncRequest = useStore().main.isAsyncRequest(); @@ -36,10 +43,28 @@ const SoccorsoEditPreInstructor = () => { const [isVisibleNewCommDialog, setIsVisibleNewCommDialog] = useState(false); const [newCommData, setNewCommData] = useState({}); const [isLoadingCommunication, setIsLoadingCommunication] = useState(false); + const [isVisibleExtendTimeDialog, setIsVisibleExtendTimeDialog] = useState(false); + const [extendedTime, setExtendedTime] = useState(3); + const [isLoadingExtendingTime, setIsLoadingExtendingTime] = useState(false); const toast = useRef(null); + const [formInitialData, setFormInitialData] = useState({}); + const { + control, + handleSubmit, + formState: { errors, isValid }, + setValue, + register, + trigger, + getValues, + clearErrors + } = useForm({ + defaultValues: useMemo(() => { + return formInitialData; + }, [formInitialData]), mode: 'onChange' + }); const goToEvaluationPage = () => { - //navigate('/domande'); + navigate(`/domande/${id}`); } const getCallback = (data) => { @@ -64,7 +89,7 @@ const SoccorsoEditPreInstructor = () => { const getCommsCallback = (data) => { if (data.status === 'SUCCESS') { - setComms(data.data.commentsList); + setComms(data.data.commentsList.map(o => getFormattedCommsData(o))); } storeSet.main.unsetAsyncRequest(); } @@ -87,31 +112,19 @@ const SoccorsoEditPreInstructor = () => { return data; }; - const renderHeader = () => { - return ( - - - - - - - - - - - - - - ); + const getFormattedCommsData = (data) => { + data.id = isNil(data.id) ? uniqid('id') : data.id; + data.commentedDate = is(String, data.commentedDate) ? new Date(data.commentedDate) : (data.commentedDate ? data.commentedDate : ''); + data.createdDate = is(String, data.createdDate) ? new Date(data.createdDate) : (data.createdDate ? data.createdDate : ''); + data.updatedDate = is(String, data.updatedDate) ? new Date(data.updatedDate) : (data.updatedDate ? data.updatedDate : ''); + return data; }; - const header = renderHeader(); - - const headerEditDialog = () => { + const headerNewComDialog = () => { return {__('Aggiungi comunicazione', 'gepafin')} } - const hideEditDialog = () => { + const hideNewComDialog = () => { setIsVisibleNewCommDialog(false); setNewCommData({ title: '', @@ -119,9 +132,9 @@ const SoccorsoEditPreInstructor = () => { }); } - const footerEditDialog = () => { + const footerNewComDialog = () => { return
- + + + + + + + + + + + + ); + }; + + const header = renderHeader(); + + const updateNewAmendmentData = (value, path) => { + const newData = wrap(data).set(path.split('.'), value).value(); + setData(newData); + } + const createCommunication = () => { setIsLoadingCommunication(true); - CommunicationService.createCommunication(newCommData, createCommunicationCallback, errCreateCommunicationCallback, [ - ['amendmentId', amendmentId] - ]); + CommunicationService.createCommunication(amendmentId, newCommData, createCommunicationCallback, errCreateCommunicationCallback); } const createCommunicationCallback = (data) => { @@ -158,7 +194,8 @@ const SoccorsoEditPreInstructor = () => { detail: data.message }); } - console.log(data.data) + setComms([...comms, getFormattedCommsData(data.data)]) + setIsVisibleNewCommDialog(false); } setIsLoadingCommunication(false); } @@ -175,6 +212,150 @@ const SoccorsoEditPreInstructor = () => { setIsLoadingCommunication(false); } + const onSubmit = () => { + }; + + const doUpdateAmendment = () => { + trigger(); + let formValues = klona(getValues()); + const newFormValues = Object.keys(formValues) + .reduce((acc, cur) => { + let fieldVal = formValues[cur]; + + fieldVal = isEmpty(fieldVal) ? null : fieldVal; + fieldVal = is(Array, fieldVal) ? fieldVal.map(o => o.id).join(',') : null; + + acc.push({ + 'fieldId': cur, + 'fieldValue': fieldVal + }); + return acc; + }, []); + + const submitData = { + updatedFormFields: newFormValues, + //note: data.internalNote + } + + storeSet.main.setAsyncRequest(); + AmendmentsService.updateSoccorso(amendmentId, submitData, updateAmendmentCallback, errUpdateAmendmentCallback); + } + + const updateAmendmentCallback = (data) => { + if (data.status === 'SUCCESS') { + if (toast.current) { + toast.current.show({ + severity: 'success', + summary: '', + detail: data.message + }); + } + } + storeSet.main.unsetAsyncRequest(); + } + + const errUpdateAmendmentCallback = (data) => { + if (toast.current && data.message) { + toast.current.show({ + severity: 'error', + summary: '', + detail: data.message + }); + } + set404FromErrorResponse(data); + storeSet.main.unsetAsyncRequest(); + } + + const doCloseAmendment = () => { + const submitData = { + internalNote: data.internalNote + } + storeSet.main.setAsyncRequest(); + AmendmentsService.closeSoccorso(amendmentId, submitData, closeAmendmentCallback, errCloseAmendmentCallback); + } + + const closeAmendmentCallback = (data) => { + if (data.status === 'SUCCESS') { + if (toast.current) { + toast.current.show({ + severity: 'success', + summary: '', + detail: data.message + }); + } + if (data.data.status) { + updateNewAmendmentData(data.data.status, 'status') + } + } + storeSet.main.unsetAsyncRequest(); + } + + const errCloseAmendmentCallback = (data) => { + if (toast.current && data.message) { + toast.current.show({ + severity: 'error', + summary: '', + detail: data.message + }); + } + set404FromErrorResponse(data); + storeSet.main.unsetAsyncRequest(); + } + + const headerExtendRespDialog = () => { + return {__('Estendi scadenza', 'gepafin')} + } + + const hideExtendRespDialog = () => { + setIsVisibleExtendTimeDialog(false); + } + + const footerExtendRespDialog = () => { + return
+
+ } + + const openExtendResponseTimeDialog = () => { + setIsVisibleExtendTimeDialog(true); + setExtendedTime(3); + } + + const doExtendTimeResponse = () => { + setIsLoadingExtendingTime(true); + AmendmentsService.extendSoccorso(amendmentId, extendedTime, extendCallback, errExtendCallback); + } + + const extendCallback = (data) => { + if (data.status === 'SUCCESS') { + if (toast.current) { + toast.current.show({ + severity: 'success', + summary: '', + detail: data.message + }); + } + setIsVisibleExtendTimeDialog(false); + } + setIsLoadingExtendingTime(false); + } + + const errExtendCallback = (data) => { + if (toast.current && data.message) { + toast.current.show({ + severity: 'error', + summary: '', + detail: data.message + }); + } + set404FromErrorResponse(data); + setIsLoadingExtendingTime(false); + } + useEffect(() => { const parsedSoccorsoId = parseInt(amendmentId); const soccorsoEntityId = !isNaN(parsedSoccorsoId) ? parsedSoccorsoId : 0; @@ -228,7 +409,7 @@ const SoccorsoEditPreInstructor = () => {

{__('Stato', 'gepafin')} - {getBandoLabel(data.applicationStatus)} + {getBandoLabel(data.status)}

@@ -245,7 +426,8 @@ const SoccorsoEditPreInstructor = () => {

{__('Note e spiegazioni', 'gepafin')}

-
+
{renderHtmlContent(data.note)}
@@ -265,51 +447,121 @@ const SoccorsoEditPreInstructor = () => { {!isNil(comms) && !isEmpty(comms) ? comms.map((o, i) => - - - ) : null} - - - - - - + + {getDateFromISOstring(o.commentedDate)} + + +

{o.title}

+

{o.comment}

+ + ) + : + - + - + }
+
+

{__('Documenti Ricevuti', 'gepafin')}

+ +
+ {data.formFields.map((o, i) => { + const test = { + 'updatedFormFields': [ + { + 'fieldId': 'a5867bdceb', + 'fieldValue': '136' + }, + { + 'fieldId': 'ab0f00219b', + 'fieldValue': null + } + ] + } + const thisField = head(test.updatedFormFields.filter(j => j.fieldId === o.fieldId)); + const value = pathOr({}, ['fieldValue'], thisField); + console.log('value', value, o.fieldId); + return + })} + + +
+
- {__('Azioni rapide', 'gepafin')} + {__('Azioni', 'gepafin')}
+
+ +
+ updateNewAmendmentData( + e.htmlValue, + 'internalNote' + )} + style={{ height: 80 * 3, width: '100%' }} + /> +
+
+
: <> @@ -325,10 +577,10 @@ const SoccorsoEditPreInstructor = () => { + onHide={hideNewComDialog}>
- updateNewCommData(e.target.value, 'comment')}/> + updateNewCommData(e.target.value, 'comment')}/> +
+
+ + +
+ + setExtendedTime(e.value)}/>
diff --git a/src/service/amendments-service.js b/src/service/amendments-service.js index d7ed4c1..1cacf79 100644 --- a/src/service/amendments-service.js +++ b/src/service/amendments-service.js @@ -15,4 +15,20 @@ export default class AmendmentsService { static createSoccorso = (body, callback, errCallback, queryParams) => { NetworkService.post(`${API_BASE_URL}/amendments`, body, callback, errCallback, queryParams); }; + + static updateSoccorso = (id, body, callback, errCallback, queryParams) => { + NetworkService.put(`${API_BASE_URL}/amendments/${id}`, body, callback, errCallback, queryParams); + }; + + static extendSoccorso = (id, days, callback, errCallback, queryParams) => { + NetworkService.put(`${API_BASE_URL}/amendments/${id}/extendExpiration`, {}, callback, errCallback, [ + ['extendedDays', days] + ]); + }; + + static closeSoccorso = (id, body, callback, errCallback, queryParams) => { + NetworkService.put(`${API_BASE_URL}/amendments`, body, callback, errCallback, [ + ['id', id] + ]); + }; } diff --git a/src/service/communication-service.js b/src/service/communication-service.js index 758b7fd..2b39271 100644 --- a/src/service/communication-service.js +++ b/src/service/communication-service.js @@ -8,7 +8,7 @@ export default class CommunicationService { NetworkService.get(`${API_BASE_URL}/communication/${id}`, callback, errCallback, queryParams); }; - static createCommunication = (body, callback, errCallback, queryParams) => { - NetworkService.post(`${API_BASE_URL}/communication`, body, callback, errCallback, queryParams); + static createCommunication = (id, body, callback, errCallback, queryParams) => { + NetworkService.post(`${API_BASE_URL}/communication/${id}`, body, callback, errCallback, queryParams); }; }