- added FLOW_ID env variable;
- implemented two types of evaluation flow; - refactored component related to communication messages; - fixed displaying elements based on evaluation status; - fixed some styles;
This commit is contained in:
@@ -1,35 +1,30 @@
|
||||
import React, { useState, useEffect, useRef, useMemo } from 'react';
|
||||
import { __, sprintf } from '@wordpress/i18n';
|
||||
import { useNavigate, useParams } from 'react-router-dom';
|
||||
import { is, isEmpty, isNil } from 'ramda';
|
||||
import { wrap } from 'object-path-immutable';
|
||||
import { is, isEmpty } from 'ramda';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { klona } from 'klona';
|
||||
|
||||
// store
|
||||
import { storeSet, useStore } from '../../store';
|
||||
|
||||
// api
|
||||
import AmendmentsService from '../../service/amendments-service';
|
||||
import CommunicationService from '../../service/communication-service';
|
||||
import ApplicationService from '../../service/application-service';
|
||||
|
||||
// tools
|
||||
import set404FromErrorResponse from '../../helpers/set404FromErrorResponse';
|
||||
import getBandoLabel from '../../helpers/getBandoLabel';
|
||||
import getDateFromISOstring from '../../helpers/getDateFromISOstring';
|
||||
import renderHtmlContent from '../../helpers/renderHtmlContent';
|
||||
import uniqid from '../../helpers/uniqid';
|
||||
|
||||
// components
|
||||
import { Button } from 'primereact/button';
|
||||
import BlockingOverlay from '../../components/BlockingOverlay';
|
||||
import { Toast } from 'primereact/toast';
|
||||
import { classNames } from 'primereact/utils';
|
||||
import { Dialog } from 'primereact/dialog';
|
||||
import { InputText } from 'primereact/inputtext';
|
||||
import { InputTextarea } from 'primereact/inputtextarea';
|
||||
import ApplicationService from '../../service/application-service';
|
||||
import FormField from '../../components/FormField';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { klona } from 'klona';
|
||||
import SoccorsoComunications from '../SoccorsoEditPreInstructor/components/SoccorsoComunications';
|
||||
|
||||
const DomandaBeneficiario = () => {
|
||||
const isAsyncRequest = useStore().main.isAsyncRequest();
|
||||
@@ -37,10 +32,6 @@ const DomandaBeneficiario = () => {
|
||||
const navigate = useNavigate();
|
||||
const [data, setData] = useState({});
|
||||
const [dataAppl, setDataAppl] = useState({});
|
||||
const [comms, setComms] = useState([]);
|
||||
const [isVisibleNewCommDialog, setIsVisibleNewCommDialog] = useState(false);
|
||||
const [newCommData, setNewCommData] = useState({});
|
||||
const [isLoadingCommunication, setIsLoadingCommunication] = useState(false);
|
||||
const [isVisibleEmailDialog, setIsVisibleEmailDialog] = useState(false);
|
||||
const toast = useRef(null);
|
||||
const [formInitialData, setFormInitialData] = useState({});
|
||||
@@ -83,7 +74,6 @@ const DomandaBeneficiario = () => {
|
||||
return acc;
|
||||
}, {});
|
||||
setFormInitialData(formDataInitial);
|
||||
CommunicationService.getCommsByAmendmentId(amendmentObj.id, getCommsCallback, errGetCommsCallback);
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
} else {
|
||||
ApplicationService.getApplication(id, getApplCallback, errGetCallback)
|
||||
@@ -110,25 +100,6 @@ const DomandaBeneficiario = () => {
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
|
||||
const getCommsCallback = (data) => {
|
||||
if (data.status === 'SUCCESS') {
|
||||
setComms(data.data.commentsList.map(o => getFormattedCommsData(o)));
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
|
||||
const errGetCommsCallback = (data) => {
|
||||
if (toast.current && data.message) {
|
||||
toast.current.show({
|
||||
severity: 'error',
|
||||
summary: '',
|
||||
detail: data.message
|
||||
});
|
||||
}
|
||||
set404FromErrorResponse(data);
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
|
||||
const getFormattedData = (data) => {
|
||||
data.submissionDate = is(String, data.submissionDate) ? new Date(data.submissionDate) : (data.submissionDate ? data.submissionDate : '');
|
||||
data.startDate = is(String, data.startDate) ? new Date(data.startDate) : (data.startDate ? data.startDate : '');
|
||||
@@ -136,81 +107,6 @@ const DomandaBeneficiario = () => {
|
||||
return data;
|
||||
};
|
||||
|
||||
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 headerNewComDialog = () => {
|
||||
return <span>{__('Aggiungi comunicazione', 'gepafin')}</span>
|
||||
}
|
||||
|
||||
const hideNewComDialog = () => {
|
||||
setIsVisibleNewCommDialog(false);
|
||||
setNewCommData({
|
||||
title: '',
|
||||
comment: ''
|
||||
});
|
||||
}
|
||||
|
||||
const footerNewComDialog = () => {
|
||||
return <div>
|
||||
<Button type="button" label={__('Anulla', 'gepafin')} onClick={hideNewComDialog} outlined/>
|
||||
<Button
|
||||
type="button"
|
||||
disabled={isLoadingCommunication || isEmpty(newCommData.title) || isEmpty(newCommData.comment)}
|
||||
label={__('Invia', 'gepafin')} onClick={createCommunication}/>
|
||||
</div>
|
||||
}
|
||||
|
||||
const openNewCommDialog = () => {
|
||||
setIsVisibleNewCommDialog(true);
|
||||
setNewCommData({
|
||||
title: '',
|
||||
comment: ''
|
||||
});
|
||||
}
|
||||
|
||||
const updateNewCommData = (value, path) => {
|
||||
const newData = wrap(newCommData).set(path.split('.'), value).value();
|
||||
setNewCommData(newData);
|
||||
}
|
||||
|
||||
const createCommunication = () => {
|
||||
setIsLoadingCommunication(true);
|
||||
CommunicationService.createCommunication(data.id, newCommData, createCommunicationCallback, errCreateCommunicationCallback);
|
||||
}
|
||||
|
||||
const createCommunicationCallback = (data) => {
|
||||
if (data.status === 'SUCCESS') {
|
||||
if (toast.current) {
|
||||
toast.current.show({
|
||||
severity: 'success',
|
||||
summary: '',
|
||||
detail: data.message
|
||||
});
|
||||
}
|
||||
setComms([...comms, getFormattedCommsData(data.data)])
|
||||
setIsVisibleNewCommDialog(false);
|
||||
}
|
||||
setIsLoadingCommunication(false);
|
||||
}
|
||||
|
||||
const errCreateCommunicationCallback = (data) => {
|
||||
if (toast.current && data.message) {
|
||||
toast.current.show({
|
||||
severity: 'error',
|
||||
summary: '',
|
||||
detail: data.message
|
||||
});
|
||||
}
|
||||
set404FromErrorResponse(data);
|
||||
setIsLoadingCommunication(false);
|
||||
}
|
||||
|
||||
const onSubmit = () => {
|
||||
};
|
||||
|
||||
@@ -354,7 +250,7 @@ const DomandaBeneficiario = () => {
|
||||
<h2>{__('Dettagli Richiesta', 'gepafin')}</h2>
|
||||
<h3>{__('Note e spiegazioni', 'gepafin')}</h3>
|
||||
<div className="appPageSection__withBorder grey ql-editor"
|
||||
style={{ minHeight: '200px' }}>
|
||||
style={{ minHeight: '100px' }}>
|
||||
{renderHtmlContent(data.note)}
|
||||
</div>
|
||||
</div> : null}
|
||||
@@ -365,9 +261,6 @@ const DomandaBeneficiario = () => {
|
||||
<form className="appForm" onSubmit={handleSubmit(onSubmit)}>
|
||||
{data.formFields
|
||||
? data.formFields.map((o, i) => {
|
||||
/*const thisField = head(test.updatedFormFields.filter(j => j.fieldId === o.fieldId));
|
||||
const value = pathOr({}, ['fieldValue'], thisField);
|
||||
console.log('value', value, o.fieldId);*/
|
||||
return <FormField
|
||||
key={o.fieldId}
|
||||
disabled={data.status === 'CLOSE'}
|
||||
@@ -400,38 +293,7 @@ const DomandaBeneficiario = () => {
|
||||
{data.id
|
||||
? <div className="appPageSection">
|
||||
<h2>{__('Comunicazioni', 'gepafin')}</h2>
|
||||
<table className="myTable">
|
||||
<thead className="myThead">
|
||||
<tr>
|
||||
<th style={{ width: 250 }}>{__('Data', 'gepafin')}</th>
|
||||
<th>{__('Comunicazione', 'gepafin')}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="myTbody">
|
||||
{!isNil(comms) && !isEmpty(comms)
|
||||
? comms.map((o, i) => <tr key={o.id}>
|
||||
<td valign="top">
|
||||
{getDateFromISOstring(o.commentedDate)}
|
||||
</td>
|
||||
<td>
|
||||
<h3>{o.title}</h3>
|
||||
<p>{o.comment}</p>
|
||||
</td>
|
||||
</tr>)
|
||||
: <tr>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
</tr>}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<Button
|
||||
style={{ marginTop: 30 }}
|
||||
onClick={openNewCommDialog}
|
||||
disabled={data.status === 'CLOSE'}
|
||||
type="button"
|
||||
label={__('Aggiungi Comunicazione', 'gepafin')}
|
||||
icon="pi pi-plus" iconPos="right"/>
|
||||
<SoccorsoComunications amendmentId={data.id} soccorsoStatus={data.status}/>
|
||||
</div> : null}
|
||||
|
||||
{data.id
|
||||
@@ -459,40 +321,8 @@ const DomandaBeneficiario = () => {
|
||||
icon="pi pi-times" iconPos="right"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<Dialog
|
||||
visible={isVisibleNewCommDialog}
|
||||
modal
|
||||
header={headerNewComDialog}
|
||||
footer={footerNewComDialog}
|
||||
style={{ maxWidth: '600px', width: '100%' }}
|
||||
onHide={hideNewComDialog}>
|
||||
<div className="appForm__field">
|
||||
<label
|
||||
className={classNames({ 'p-error': isEmpty(newCommData.title) })}>
|
||||
{__('Titolo', 'gepafin')}*
|
||||
</label>
|
||||
<InputText value={newCommData.title}
|
||||
disabled={data.status === 'CLOSE'}
|
||||
invalid={isEmpty(newCommData.title)}
|
||||
onChange={(e) => updateNewCommData(e.target.value, 'title')}/>
|
||||
|
||||
<label
|
||||
className={classNames({ 'p-error': isEmpty(newCommData.comment) })}>
|
||||
{__('Contenuto', 'gepafin')}*
|
||||
</label>
|
||||
<InputTextarea
|
||||
value={newCommData.comment}
|
||||
disabled={data.status === 'CLOSE'}
|
||||
rows={5} cols={30}
|
||||
invalid={isEmpty(newCommData.comment)}
|
||||
onChange={(e) => updateNewCommData(e.target.value, 'comment')}/>
|
||||
</div>
|
||||
</Dialog>
|
||||
|
||||
<Dialog
|
||||
header={__('Invia documenti via PEC', 'gepafin')}
|
||||
visible={isVisibleEmailDialog}
|
||||
|
||||
Reference in New Issue
Block a user