- added step 3 and evaluation form creation for call;
This commit is contained in:
@@ -27,6 +27,7 @@ import { storeSet } from '../../../../store';
|
||||
import set404FromErrorResponse from '../../../../helpers/set404FromErrorResponse';
|
||||
import getTimeParsedFromString from '../../../../helpers/getTimeParsedFromString';
|
||||
import formatDateString from '../../../../helpers/formatDateString';
|
||||
import EvaluationFormsService from '../../../../service/evaluation-forms-service';
|
||||
|
||||
const BandoEditFormStep1 = forwardRef(function ({ initialData, setInitialData, getFormErrors, status }, ref) {
|
||||
const navigate = useNavigate();
|
||||
@@ -115,7 +116,12 @@ const BandoEditFormStep1 = forwardRef(function ({ initialData, setInitialData, g
|
||||
}
|
||||
const values = getValues();
|
||||
if (!values.id && data.data.id) {
|
||||
navigate(`/bandi/${data.data.id}`);
|
||||
storeSet.main.setAsyncRequest();
|
||||
const sampleFormData = {
|
||||
label: `Evaluation form for call #${data.data.id}`,
|
||||
content: []
|
||||
}
|
||||
EvaluationFormsService.createFormForCall(data.data.id, sampleFormData, createFormCallback, errCreateFormCallback)
|
||||
} else {
|
||||
setFormInitialData(data.data);
|
||||
setInitialData(data.data);
|
||||
@@ -135,6 +141,18 @@ const BandoEditFormStep1 = forwardRef(function ({ initialData, setInitialData, g
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
|
||||
const createFormCallback = (resp) => {
|
||||
if (resp.status === 'SUCCESS') {
|
||||
navigate(`/bandi/${resp.data.callId}`);
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
|
||||
const errCreateFormCallback = (resp) => {
|
||||
set404FromErrorResponse(resp);
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
|
||||
const openPreview = () => {
|
||||
navigate(`/bandi/${values.id}/preview`);
|
||||
}
|
||||
|
||||
@@ -94,7 +94,11 @@ const BandoEditFormStep2 = forwardRef(function ({ initialData, setInitialData, g
|
||||
delete formData.endDate;
|
||||
|
||||
storeSet.main.setAsyncRequest();
|
||||
BandoService.updateBandoStep2(formData.id, formData, createCallback, errCreateCallback);
|
||||
if (values.evaluationVersion === 'V1') {
|
||||
BandoService.updateBandoStep2(formData.id, formData, createCallback, errCreateCallback);
|
||||
} else if (values.evaluationVersion === 'V2') {
|
||||
BandoService.updateBandoStep2V2(formData.id, formData, createCallback, errCreateCallback);
|
||||
}
|
||||
}
|
||||
|
||||
const createCallback = (data) => {
|
||||
@@ -221,7 +225,8 @@ const BandoEditFormStep2 = forwardRef(function ({ initialData, setInitialData, g
|
||||
return (
|
||||
<form className="appForm" onSubmit={handleSubmit(onSubmit)}>
|
||||
<UnsavedChangesDetector getValuesFn={getValues}/>
|
||||
<FormFieldRepeaterCriteria
|
||||
{values.evaluationVersion === 'V1'
|
||||
? <FormFieldRepeaterCriteria
|
||||
data={values}
|
||||
disabled={shouldDisableField('criteria')}
|
||||
setDataFn={setValue}
|
||||
@@ -238,7 +243,7 @@ const BandoEditFormStep2 = forwardRef(function ({ initialData, setInitialData, g
|
||||
.filter(o => isEmpty(o.value) || isEmpty(o.score)).length === 0
|
||||
|| __('Non lasciare il valore vuoto', 'gepafin')
|
||||
}
|
||||
}}/>
|
||||
}}/> : null}
|
||||
|
||||
<FormField
|
||||
type="fileuploadasync"
|
||||
@@ -275,7 +280,8 @@ const BandoEditFormStep2 = forwardRef(function ({ initialData, setInitialData, g
|
||||
multiple={false}
|
||||
/>
|
||||
|
||||
<FormFieldRepeater
|
||||
{values.evaluationVersion === 'V1'
|
||||
? <FormFieldRepeater
|
||||
data={values['checkList']}
|
||||
disabled={shouldDisableField('checkList')}
|
||||
setDataFn={setValue}
|
||||
@@ -292,7 +298,7 @@ const BandoEditFormStep2 = forwardRef(function ({ initialData, setInitialData, g
|
||||
.filter(o => isEmpty(o.value)).length === 0 || __('Non lasciare il valore vuoto', 'gepafin')
|
||||
}
|
||||
}}
|
||||
/>
|
||||
/> : null}
|
||||
|
||||
<div className="appPage__spacer"></div>
|
||||
|
||||
|
||||
147
src/pages/BandoEdit/components/BandoEditFormStep3/index.js
Normal file
147
src/pages/BandoEdit/components/BandoEditFormStep3/index.js
Normal file
@@ -0,0 +1,147 @@
|
||||
import React, { forwardRef, useEffect, useRef, useState } from 'react';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { useNavigate, useParams } from 'react-router-dom';
|
||||
import { klona } from 'klona';
|
||||
import { DndProvider } from 'react-dnd';
|
||||
import { HTML5Backend } from 'react-dnd-html5-backend';
|
||||
|
||||
// api
|
||||
import EvaluationFormsService from '../../../../service/evaluation-forms-service';
|
||||
import FormsService from '../../../../service/forms-service';
|
||||
|
||||
// store
|
||||
import { storeGet, storeSet } from '../../../../store';
|
||||
|
||||
// tools
|
||||
import set404FromErrorResponse from '../../../../helpers/set404FromErrorResponse';
|
||||
|
||||
// components
|
||||
import BandoEditFormActions from '../BandoEditFormActions';
|
||||
import { Toast } from 'primereact/toast';
|
||||
import FormBuilder from '../../../BandoFormsEdit/components/FormBuilder';
|
||||
import { elementItems } from '../../../../tempData';
|
||||
|
||||
|
||||
const BandoEditFormStep3 = forwardRef(function () {
|
||||
const navigate = useNavigate();
|
||||
const { id } = useParams();
|
||||
const [formName, setFormName] = useState('');
|
||||
const [bandoStatus, setBandoStatus] = useState('');
|
||||
const toast = useRef(null);
|
||||
|
||||
const getBandoId = () => {
|
||||
const parsed = parseInt(id)
|
||||
return !isNaN(parsed) ? parsed : 0;
|
||||
}
|
||||
|
||||
const onSaveDraft = () => {
|
||||
const content = storeGet.main.formElements();
|
||||
const formId = storeGet.main.formId();
|
||||
const formData = {
|
||||
label: formName,
|
||||
content
|
||||
}
|
||||
|
||||
storeSet.main.setAsyncRequest();
|
||||
EvaluationFormsService.updateForm(formId, formData, updateFormCallback, errUpdateFormCallback)
|
||||
}
|
||||
|
||||
const updateFormCallback = (resp) => {
|
||||
if (resp.status === 'SUCCESS') {
|
||||
setBandoStatus(resp.data.callStatus);
|
||||
if (toast.current) {
|
||||
toast.current.show({
|
||||
severity: 'success',
|
||||
summary: '',
|
||||
detail: __('Il bando è stato aggiornato correttamente!', 'gepafin')
|
||||
});
|
||||
}
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
|
||||
const errUpdateFormCallback = (resp) => {
|
||||
set404FromErrorResponse(resp);
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
|
||||
const openPreview = () => {
|
||||
const bandoId = getBandoId();
|
||||
navigate(`/bandi/${bandoId}/preview`);
|
||||
}
|
||||
|
||||
const openPreviewEvaluation = () => {
|
||||
const bandoId = getBandoId();
|
||||
navigate(`/bandi/${bandoId}/preview-evaluation`);
|
||||
}
|
||||
|
||||
const getElementItemsCallback = (data) => {
|
||||
if (data.status === 'SUCCESS') {
|
||||
storeSet.main.elementItems(elementItems.sort((a, b) => a.sortOrder - b.sortOrder));
|
||||
//storeSet.main.elementItems(data.data.sort((a, b) => a.sortOrder - b.sortOrder));
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
|
||||
const errGetElementItemsCallbacks = (data) => {
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
|
||||
const getFormCallback = (resp) => {
|
||||
if (resp.status === 'SUCCESS') {
|
||||
storeSet.main.formId(resp.data.id);
|
||||
storeSet.main.formLabel(resp.data.label);
|
||||
setFormName(resp.data.label);
|
||||
setBandoStatus(resp.data.callStatus);
|
||||
const elements = klona(resp.data.content);
|
||||
storeSet.main.formElements(elements);
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
|
||||
const errGetFormCallback = (resp) => {
|
||||
set404FromErrorResponse(resp);
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
storeSet.main.setAsyncRequest();
|
||||
EvaluationFormsService.getFormForCall(id, getFormCallback, errGetFormCallback)
|
||||
}, [id]);
|
||||
|
||||
useEffect(() => {
|
||||
storeSet.main.setAsyncRequest();
|
||||
FormsService.getElementItems(getElementItemsCallback, errGetElementItemsCallbacks);
|
||||
|
||||
return () => {
|
||||
storeSet.main.formId(0);
|
||||
storeSet.main.formElements([]);
|
||||
}
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="appForm">
|
||||
<div className="appPageSection">
|
||||
<DndProvider backend={HTML5Backend}>
|
||||
<FormBuilder bandoStatus={bandoStatus}/>
|
||||
</DndProvider>
|
||||
</div>
|
||||
|
||||
<div className="appPage__spacer"></div>
|
||||
|
||||
<div className="appPageSection__hr">
|
||||
<span>{__('Azioni', 'gepafin')}</span>
|
||||
</div>
|
||||
|
||||
<Toast ref={toast} />
|
||||
<BandoEditFormActions
|
||||
id={id}
|
||||
status={bandoStatus}
|
||||
submitFn={onSaveDraft}
|
||||
openPreview={openPreview}
|
||||
openPreviewEvaluation={openPreviewEvaluation}/>
|
||||
</div>
|
||||
)
|
||||
})
|
||||
|
||||
export default BandoEditFormStep3;
|
||||
@@ -23,6 +23,7 @@ import { Messages } from 'primereact/messages';
|
||||
import FormsService from '../../service/forms-service';
|
||||
import BlockingOverlay from '../../components/BlockingOverlay';
|
||||
import { Toast } from 'primereact/toast';
|
||||
import BandoEditFormStep3 from './components/BandoEditFormStep3';
|
||||
|
||||
const BandoEdit = () => {
|
||||
const isAsyncRequest = useStore().main.isAsyncRequest();
|
||||
@@ -35,28 +36,45 @@ const BandoEdit = () => {
|
||||
const bandoMsgs = useRef(null);
|
||||
const toast = useRef(null);
|
||||
|
||||
const stepItems = [
|
||||
{
|
||||
label: __('Testi', 'gepafin'),
|
||||
command: () => {
|
||||
if (activeStep === 0) {
|
||||
return false
|
||||
const stepItems = (evalProcessVer) => {
|
||||
let steps = [
|
||||
{
|
||||
label: __('Testi', 'gepafin'),
|
||||
command: () => {
|
||||
if (activeStep === 0) {
|
||||
return false
|
||||
}
|
||||
bandoMsgs.current.clear();
|
||||
goToStep(0);
|
||||
}
|
||||
bandoMsgs.current.clear();
|
||||
goToStep(0);
|
||||
}
|
||||
},
|
||||
{
|
||||
label: __('Gestione', 'gepafin'),
|
||||
command: () => {
|
||||
if (activeStep === 1) {
|
||||
return false
|
||||
},
|
||||
{
|
||||
label: __('Gestione', 'gepafin'),
|
||||
command: () => {
|
||||
if (activeStep === 1) {
|
||||
return false
|
||||
}
|
||||
bandoMsgs.current.clear();
|
||||
goToStep(1);
|
||||
}
|
||||
bandoMsgs.current.clear();
|
||||
goToStep(1);
|
||||
}
|
||||
];
|
||||
|
||||
if (evalProcessVer === 'V2') {
|
||||
steps.push({
|
||||
label: __('Valutazione', 'gepafin'),
|
||||
command: () => {
|
||||
if (activeStep === 2) {
|
||||
return false
|
||||
}
|
||||
bandoMsgs.current.clear();
|
||||
goToStep(2);
|
||||
}
|
||||
})
|
||||
}
|
||||
];
|
||||
|
||||
return steps;
|
||||
}
|
||||
|
||||
const goToStep = (step) => {
|
||||
setActiveStep(step);
|
||||
@@ -238,7 +256,8 @@ const BandoEdit = () => {
|
||||
|
||||
if (bandoId === 0) {
|
||||
setData({
|
||||
status: null
|
||||
status: null,
|
||||
evaluationVersion: 'V2'
|
||||
});
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
|
||||
@@ -274,7 +293,7 @@ const BandoEdit = () => {
|
||||
|
||||
{!isEmpty(data)
|
||||
? <Steps
|
||||
model={stepItems}
|
||||
model={stepItems(data.evaluationVersion)}
|
||||
activeIndex={activeStep}
|
||||
readOnly={isNil(data.status)}/>
|
||||
: null}
|
||||
@@ -293,6 +312,9 @@ const BandoEdit = () => {
|
||||
{activeStep === 1
|
||||
? <BandoEditFormStep2 initialData={data} setInitialData={setData} ref={formRef} status={data.status}/>
|
||||
: null}
|
||||
{activeStep === 2 && data.evaluationVersion === 'V2'
|
||||
? <BandoEditFormStep3/>
|
||||
: null}
|
||||
|
||||
<div className="appPageSection">
|
||||
<h2>{__('Crea o modifica il Form compilabile dal Beneficiario', 'gepafin')}</h2>
|
||||
|
||||
@@ -110,7 +110,6 @@ const BandoFormsEdit = () => {
|
||||
|
||||
const formCreateCallback = (data, shouldRedirect) => {
|
||||
if (data.status === 'SUCCESS') {
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
const bandoId = getBandoId();
|
||||
if (shouldRedirect) {
|
||||
navigate(`/bandi/${bandoId}/forms/${data.data.id}/preview`);
|
||||
@@ -127,6 +126,7 @@ const BandoFormsEdit = () => {
|
||||
});
|
||||
}
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
|
||||
const errFormCreateCallback = (data) => {
|
||||
@@ -221,7 +221,7 @@ const BandoFormsEdit = () => {
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
|
||||
const errGetElementItemsCallbacks = (data) => {
|
||||
const errGetElementItemsCallback = (data) => {
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
|
||||
@@ -261,7 +261,7 @@ const BandoFormsEdit = () => {
|
||||
const bandoFormId = !isNaN(parsedFormId) ? parsedFormId : 0;
|
||||
|
||||
storeSet.main.setAsyncRequest();
|
||||
FormsService.getElementItems(getElementItemsCallback, errGetElementItemsCallbacks);
|
||||
FormsService.getElementItems(getElementItemsCallback, errGetElementItemsCallback);
|
||||
|
||||
if (bandoFormId) {
|
||||
storeSet.main.setAsyncRequest();
|
||||
|
||||
Reference in New Issue
Block a user