- saving progress;
This commit is contained in:
@@ -1,20 +1,17 @@
|
|||||||
import React, { useState, useEffect, useRef } from 'react';
|
import React, { useState, useEffect, useRef } from 'react';
|
||||||
import { __ } from '@wordpress/i18n';
|
import { __ } from '@wordpress/i18n';
|
||||||
import { useNavigate, useParams } from 'react-router-dom';
|
import { useNavigate, useParams } from 'react-router-dom';
|
||||||
import { is, isEmpty } from 'ramda';
|
import { isEmpty } from 'ramda';
|
||||||
import { wrap } from 'object-path-immutable';
|
import { wrap } from 'object-path-immutable';
|
||||||
|
|
||||||
// store
|
// store
|
||||||
import { storeSet, useStore } from '../../store';
|
import { storeSet, useStore } from '../../store';
|
||||||
|
|
||||||
// api
|
// api
|
||||||
import ApplicationEvaluationService from '../../service/application-evaluation-service';
|
|
||||||
import AmendmentsService from '../../service/amendments-service';
|
import AmendmentsService from '../../service/amendments-service';
|
||||||
|
|
||||||
// tools
|
// tools
|
||||||
import set404FromErrorResponse from '../../helpers/set404FromErrorResponse';
|
import set404FromErrorResponse from '../../helpers/set404FromErrorResponse';
|
||||||
import getBandoLabel from '../../helpers/getBandoLabel';
|
|
||||||
import getDateFromISOstring from '../../helpers/getDateFromISOstring';
|
|
||||||
|
|
||||||
// components
|
// components
|
||||||
import { Skeleton } from 'primereact/skeleton';
|
import { Skeleton } from 'primereact/skeleton';
|
||||||
@@ -24,7 +21,6 @@ import { Editor } from 'primereact/editor';
|
|||||||
import { InputNumber } from 'primereact/inputnumber';
|
import { InputNumber } from 'primereact/inputnumber';
|
||||||
import BlockingOverlay from '../../components/BlockingOverlay';
|
import BlockingOverlay from '../../components/BlockingOverlay';
|
||||||
import { Toast } from 'primereact/toast';
|
import { Toast } from 'primereact/toast';
|
||||||
import HelpIcon from '../../icons/HelpIcon';
|
|
||||||
import { InputSwitch } from 'primereact/inputswitch';
|
import { InputSwitch } from 'primereact/inputswitch';
|
||||||
|
|
||||||
const SoccorsoEditPreInstructor = () => {
|
const SoccorsoEditPreInstructor = () => {
|
||||||
|
|||||||
@@ -1,41 +1,41 @@
|
|||||||
import React, { useState, useEffect, useRef } from 'react';
|
import React, { useState, useEffect, useRef } from 'react';
|
||||||
import { __, sprintf } from '@wordpress/i18n';
|
import { __ } from '@wordpress/i18n';
|
||||||
import { useNavigate, useParams } from 'react-router-dom';
|
import { useNavigate, useParams } from 'react-router-dom';
|
||||||
import { is, isEmpty, isNil, sum, pathOr } from 'ramda';
|
import { is, isEmpty, isNil } from 'ramda';
|
||||||
import { klona } from 'klona';
|
|
||||||
import { wrap } from 'object-path-immutable';
|
import { wrap } from 'object-path-immutable';
|
||||||
|
|
||||||
// store
|
// store
|
||||||
import { storeSet, useStore } from '../../store';
|
import { storeSet, useStore } from '../../store';
|
||||||
|
|
||||||
// api
|
// api
|
||||||
import ApplicationEvaluationService from '../../service/application-evaluation-service';
|
import AmendmentsService from '../../service/amendments-service';
|
||||||
|
import CommunicationService from '../../service/communication-service';
|
||||||
|
|
||||||
// tools
|
// tools
|
||||||
import set404FromErrorResponse from '../../helpers/set404FromErrorResponse';
|
import set404FromErrorResponse from '../../helpers/set404FromErrorResponse';
|
||||||
import getBandoLabel from '../../helpers/getBandoLabel';
|
import getBandoLabel from '../../helpers/getBandoLabel';
|
||||||
import getDateFromISOstring from '../../helpers/getDateFromISOstring';
|
import getDateFromISOstring from '../../helpers/getDateFromISOstring';
|
||||||
|
import renderHtmlContent from '../../helpers/renderHtmlContent';
|
||||||
|
|
||||||
// components
|
// components
|
||||||
import { Skeleton } from 'primereact/skeleton';
|
import { Skeleton } from 'primereact/skeleton';
|
||||||
import { Button } from 'primereact/button';
|
import { Button } from 'primereact/button';
|
||||||
import { Tag } from 'primereact/tag';
|
|
||||||
import { Checkbox } from 'primereact/checkbox';
|
|
||||||
import { Editor } from 'primereact/editor';
|
|
||||||
import { InputNumber } from 'primereact/inputnumber';
|
|
||||||
import BlockingOverlay from '../../components/BlockingOverlay';
|
import BlockingOverlay from '../../components/BlockingOverlay';
|
||||||
import { Toast } from 'primereact/toast';
|
import { Toast } from 'primereact/toast';
|
||||||
import HelpIcon from '../../icons/HelpIcon';
|
import { classNames } from 'primereact/utils';
|
||||||
import AmendmentsService from '../../service/amendments-service';
|
import { Dialog } from 'primereact/dialog';
|
||||||
import renderHtmlContent from '../../helpers/renderHtmlContent';
|
import { InputText } from 'primereact/inputtext';
|
||||||
import CommunicationService from '../../service/communication-service';
|
import { InputTextarea } from 'primereact/inputtextarea';
|
||||||
|
|
||||||
const SoccorsoEditPreInstructor = () => {
|
const SoccorsoEditPreInstructor = () => {
|
||||||
const isAsyncRequest = useStore().main.isAsyncRequest();
|
const isAsyncRequest = useStore().main.isAsyncRequest();
|
||||||
const { id, amendmendId } = useParams();
|
const { id, amendmentId } = useParams();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [data, setData] = useState({});
|
const [data, setData] = useState({});
|
||||||
const [comms, setComms] = useState([]);
|
const [comms, setComms] = useState([]);
|
||||||
|
const [isVisibleNewCommDialog, setIsVisibleNewCommDialog] = useState(false);
|
||||||
|
const [newCommData, setNewCommData] = useState({});
|
||||||
|
const [isLoadingCommunication, setIsLoadingCommunication] = useState(false);
|
||||||
const toast = useRef(null);
|
const toast = useRef(null);
|
||||||
|
|
||||||
const goToEvaluationPage = () => {
|
const goToEvaluationPage = () => {
|
||||||
@@ -107,28 +107,49 @@ const SoccorsoEditPreInstructor = () => {
|
|||||||
|
|
||||||
const header = renderHeader();
|
const header = renderHeader();
|
||||||
|
|
||||||
const updateEvaluationValue = (value, path, maxValue) => {
|
const headerEditDialog = () => {
|
||||||
let finalValue = value;
|
return <span>{__('Aggiungi comunicazione', 'gepafin')}</span>
|
||||||
|
|
||||||
if (maxValue) {
|
|
||||||
finalValue = value > maxValue ? maxValue : value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const newData = wrap(data).set(path.split('.'), finalValue).value();
|
const hideEditDialog = () => {
|
||||||
setData(newData);
|
setIsVisibleNewCommDialog(false);
|
||||||
|
setNewCommData({
|
||||||
|
title: '',
|
||||||
|
comment: ''
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/*const doSaveDraft = () => {
|
const footerEditDialog = () => {
|
||||||
const formData = {
|
return <div>
|
||||||
criteria: klona(data.criteria),
|
<Button type="button" label={__('Anulla', 'gepafin')} onClick={hideEditDialog} outlined/>
|
||||||
checklist: klona(data.checklist),
|
<Button
|
||||||
files: klona(data.files),
|
type="button"
|
||||||
note: data.note
|
disabled={isLoadingCommunication || isEmpty(newCommData.title) || isEmpty(newCommData.comment)}
|
||||||
}
|
label={__('Invia', 'gepafin')} onClick={createCommunication}/>
|
||||||
ApplicationEvaluationService.updateEvaluation(id, formData, updateCallback, errUpdateCallback);
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateCallback = (data) => {
|
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(newCommData, createCommunicationCallback, errCreateCommunicationCallback, [
|
||||||
|
['amendmentId', amendmentId]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
const createCommunicationCallback = (data) => {
|
||||||
if (data.status === 'SUCCESS') {
|
if (data.status === 'SUCCESS') {
|
||||||
if (toast.current) {
|
if (toast.current) {
|
||||||
toast.current.show({
|
toast.current.show({
|
||||||
@@ -137,11 +158,12 @@ const SoccorsoEditPreInstructor = () => {
|
|||||||
detail: data.message
|
detail: data.message
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
console.log(data.data)
|
||||||
}
|
}
|
||||||
storeSet.main.unsetAsyncRequest();
|
setIsLoadingCommunication(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
const errUpdateCallback = (data) => {
|
const errCreateCommunicationCallback = (data) => {
|
||||||
if (toast.current && data.message) {
|
if (toast.current && data.message) {
|
||||||
toast.current.show({
|
toast.current.show({
|
||||||
severity: 'error',
|
severity: 'error',
|
||||||
@@ -150,15 +172,15 @@ const SoccorsoEditPreInstructor = () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
set404FromErrorResponse(data);
|
set404FromErrorResponse(data);
|
||||||
storeSet.main.unsetAsyncRequest();
|
setIsLoadingCommunication(false);
|
||||||
}*/
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const parsedSoccorsoId = parseInt(amendmendId)
|
const parsedSoccorsoId = parseInt(amendmentId);
|
||||||
const soccorsoEntityId = !isNaN(parsedSoccorsoId) ? parsedSoccorsoId : 0;
|
const soccorsoEntityId = !isNaN(parsedSoccorsoId) ? parsedSoccorsoId : 0;
|
||||||
|
|
||||||
AmendmentsService.getSoccorsoById(getCallback, errGetCallback, [['id', soccorsoEntityId]]);
|
AmendmentsService.getSoccorsoById(getCallback, errGetCallback, [['id', soccorsoEntityId]]);
|
||||||
}, [amendmendId]);
|
}, [amendmentId]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="appPage">
|
<div className="appPage">
|
||||||
@@ -255,6 +277,7 @@ const SoccorsoEditPreInstructor = () => {
|
|||||||
|
|
||||||
<Button
|
<Button
|
||||||
style={{marginTop: 30}}
|
style={{marginTop: 30}}
|
||||||
|
onClick={openNewCommDialog}
|
||||||
type="button"
|
type="button"
|
||||||
label={__('Aggiungi Comunicazione', 'gepafin')}
|
label={__('Aggiungi Comunicazione', 'gepafin')}
|
||||||
icon="pi pi-plus" iconPos="right"/>
|
icon="pi pi-plus" iconPos="right"/>
|
||||||
@@ -298,6 +321,32 @@ const SoccorsoEditPreInstructor = () => {
|
|||||||
<Skeleton width="20%" height="1rem" className="mb-2"></Skeleton>
|
<Skeleton width="20%" height="1rem" className="mb-2"></Skeleton>
|
||||||
<Skeleton width="100%" height="4rem"></Skeleton>
|
<Skeleton width="100%" height="4rem"></Skeleton>
|
||||||
</>}
|
</>}
|
||||||
|
|
||||||
|
<Dialog
|
||||||
|
visible={isVisibleNewCommDialog}
|
||||||
|
modal
|
||||||
|
header={headerEditDialog}
|
||||||
|
footer={footerEditDialog}
|
||||||
|
style={{ maxWidth: '600px', width: '100%' }}
|
||||||
|
onHide={hideEditDialog}>
|
||||||
|
<div className="appForm__field">
|
||||||
|
<label
|
||||||
|
className={classNames({ 'p-error': isEmpty(newCommData.title) })}>
|
||||||
|
{__('Titolo', 'gepafin')}*
|
||||||
|
</label>
|
||||||
|
<InputText value={newCommData.title}
|
||||||
|
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}
|
||||||
|
invalid={isEmpty(newCommData.comment)}
|
||||||
|
onChange={(e) => updateNewCommData(e.target.value, 'comment')}/>
|
||||||
|
</div>
|
||||||
|
</Dialog>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ const routes = ({ role, chosenCompanyId }) => {
|
|||||||
{'ROLE_BENEFICIARY' === role ? <PageNotFound/> : null}
|
{'ROLE_BENEFICIARY' === role ? <PageNotFound/> : null}
|
||||||
{'ROLE_PRE_INSTRUCTOR' === role ? <SoccorsoAddPreInstructor/> : null}
|
{'ROLE_PRE_INSTRUCTOR' === role ? <SoccorsoAddPreInstructor/> : null}
|
||||||
</DefaultLayout>}/>
|
</DefaultLayout>}/>
|
||||||
<Route path="/domande/:id/soccorso/:amendmendId" element={<DefaultLayout>
|
<Route path="/domande/:id/soccorso/:amendmentId" element={<DefaultLayout>
|
||||||
{'ROLE_SUPER_ADMIN' === role ? <PageNotFound/> : null}
|
{'ROLE_SUPER_ADMIN' === role ? <PageNotFound/> : null}
|
||||||
{'ROLE_BENEFICIARY' === role ? <PageNotFound/> : null}
|
{'ROLE_BENEFICIARY' === role ? <PageNotFound/> : null}
|
||||||
{'ROLE_PRE_INSTRUCTOR' === role ? <SoccorsoEditPreInstructor/> : null}
|
{'ROLE_PRE_INSTRUCTOR' === role ? <SoccorsoEditPreInstructor/> : null}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export default class CommunicationService {
|
|||||||
NetworkService.get(`${API_BASE_URL}/communication/${id}`, callback, errCallback, queryParams);
|
NetworkService.get(`${API_BASE_URL}/communication/${id}`, callback, errCallback, queryParams);
|
||||||
};
|
};
|
||||||
|
|
||||||
static getCommsByAmendmentId = (id, callback, errCallback, queryParams) => {
|
static createCommunication = (body, callback, errCallback, queryParams) => {
|
||||||
NetworkService.get(`${API_BASE_URL}/communication/${id}`, callback, errCallback, queryParams);
|
NetworkService.post(`${API_BASE_URL}/communication`, body, callback, errCallback, queryParams);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user