- saving progress;
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import React from 'react';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { isNil } from 'ramda';
|
||||
|
||||
// components
|
||||
import { Button } from 'primereact/button';
|
||||
|
||||
const BandoEditFormActions = ({ openPreview, openPreviewEvaluation }) => {
|
||||
const BandoEditFormActions = ({ id, openPreview, openPreviewEvaluation }) => {
|
||||
return (
|
||||
<div className="appPageSection">
|
||||
<div className="appPageSection__actions">
|
||||
@@ -13,7 +14,7 @@ const BandoEditFormActions = ({ openPreview, openPreviewEvaluation }) => {
|
||||
label={__('Salva bozza', 'gepafin')} icon="pi pi-save" iconPos="right"/>
|
||||
<Button
|
||||
type="button"
|
||||
disabled={false}
|
||||
disabled={isNil(id)}
|
||||
outlined
|
||||
onClick={openPreview}
|
||||
label={__('Anteprima beneficiario', 'gepafin')} icon="pi pi-eye" iconPos="right"/>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { forwardRef, useImperativeHandle, useEffect } from 'react';
|
||||
import React, { forwardRef, useImperativeHandle, useEffect, useState, useMemo } from 'react';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useForm } from 'react-hook-form';
|
||||
@@ -10,9 +10,16 @@ import FormFieldRepeater from '../../../../components/FormFieldRepeater';
|
||||
import FormFieldRepeaterFaq from '../../../../components/FormFieldRepeaterFaq';
|
||||
import BandoEditFormActions from '../BandoEditFormActions';
|
||||
import UnsavedChangesDetector from '../../../../components/UnsavedChangesDetector';
|
||||
import BandoService from '../../../../service/bando-service';
|
||||
import LookupdataService from '../../../../service/lookupdata-service';
|
||||
import { storeSet, useStore } from '../../../../store';
|
||||
|
||||
const BandoEditFormStep1 = forwardRef(function ({ initialData, getFormErrors }, ref) {
|
||||
const navigate = useNavigate();
|
||||
const isAsyncRequest = useStore().main.isAsyncRequest();
|
||||
const [aimedToOptions, setAimedToOptions] = useState([]);
|
||||
const [faqOptions, setFaqOptions] = useState([]);
|
||||
const [formInitialData, setFormInitialData] = useState(initialData);
|
||||
const {
|
||||
control,
|
||||
handleSubmit,
|
||||
@@ -21,8 +28,13 @@ const BandoEditFormStep1 = forwardRef(function ({ initialData, getFormErrors },
|
||||
register,
|
||||
trigger,
|
||||
getValues,
|
||||
clearErrors
|
||||
} = useForm({defaultValues: initialData, mode: 'onChange'});
|
||||
clearErrors,
|
||||
reset
|
||||
} = useForm({
|
||||
defaultValues: useMemo(() => {
|
||||
return formInitialData;
|
||||
}, [formInitialData]), mode: 'onChange'
|
||||
});
|
||||
const values = getValues();
|
||||
let minDateStart = new Date();
|
||||
|
||||
@@ -30,22 +42,67 @@ const BandoEditFormStep1 = forwardRef(function ({ initialData, getFormErrors },
|
||||
if (!isNil(formData.dates) && formData.dates.length) {
|
||||
formData.dates = formData.dates.map(v => is(String, v) ? v : v.toISOString());
|
||||
}
|
||||
console.log('onSubmit', formData);
|
||||
|
||||
if (!formData.id) {
|
||||
BandoService.createBando(formData, createCallback, errCreateCallback);
|
||||
} else {
|
||||
BandoService.updateBandoStep1(formData.id, formData, createCallback, errCreateCallback);
|
||||
}
|
||||
};
|
||||
|
||||
// TODO temp data
|
||||
const exampleOfAimedToOptions = [{ id: 11, value: 'PMI con sede in Umbria' }];
|
||||
const exampleOfFaqOptions = [
|
||||
{ id: 2, question: 'Question 1?', answer: 'Lorem ipsum dolor', visible: true }
|
||||
];
|
||||
// end of temp data
|
||||
const createCallback = (data) => {
|
||||
if (data.status === 'SUCCESS') {
|
||||
const values = getValues();
|
||||
if (!values.id && data.data.id) {
|
||||
navigate(`/bandi/${data.data.id}`);
|
||||
} else {
|
||||
setFormInitialData(data.data);
|
||||
reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const errCreateCallback = (data) => {
|
||||
console.log('errCreateCallback', data);
|
||||
}
|
||||
|
||||
const openPreview = () => {
|
||||
navigate('/bandi/11/preview');
|
||||
navigate(`/bandi/${values.id}/preview`);
|
||||
}
|
||||
|
||||
const openPreviewEvaluation = () => {
|
||||
navigate('/bandi/11/preview-evaluation');
|
||||
navigate(`/bandi/${values.id}/preview-evaluation`);
|
||||
}
|
||||
|
||||
const lookupdataCallback = (data) => {
|
||||
if (data.status === 'SUCCESS') {
|
||||
const aimedTo = data.data
|
||||
.filter(o => o.type === 'AIMED_TO')
|
||||
.map(o => {
|
||||
delete o.type;
|
||||
return {
|
||||
...o,
|
||||
lookUpDataId: o.id
|
||||
};
|
||||
});
|
||||
setAimedToOptions(aimedTo);
|
||||
const faqItems = data.data
|
||||
.filter(o => o.type === 'FAQ')
|
||||
.map(o => {
|
||||
delete o.type;
|
||||
return {
|
||||
...o,
|
||||
lookUpDataId: o.id
|
||||
};
|
||||
});
|
||||
setFaqOptions(faqItems);
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
|
||||
const errLookupdataCallback = (data) => {
|
||||
console.log('errLookupdataCallback', data);
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
|
||||
useImperativeHandle(
|
||||
@@ -65,12 +122,26 @@ const BandoEditFormStep1 = forwardRef(function ({ initialData, getFormErrors },
|
||||
}, [errors, isValid]);
|
||||
|
||||
useEffect(() => {
|
||||
setFormInitialData(initialData);
|
||||
}, [initialData]);
|
||||
|
||||
useEffect(() => {
|
||||
reset(formInitialData);
|
||||
}, [formInitialData]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isAsyncRequest !== 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
trigger().then(() => clearErrors());
|
||||
//storeSet.main.setAsyncRequest();
|
||||
LookupdataService.getItems(lookupdataCallback, errLookupdataCallback, [['type', ['AIMED_TO', 'FAQ']]])
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<form className="appForm" onSubmit={handleSubmit(onSubmit)}>
|
||||
<UnsavedChangesDetector initialData={values} getValuesFn={getValues}/>
|
||||
<UnsavedChangesDetector initialData={formInitialData} getValuesFn={getValues}/>
|
||||
<FormField
|
||||
type="switch"
|
||||
fieldName="confidi"
|
||||
@@ -123,7 +194,7 @@ const BandoEditFormStep1 = forwardRef(function ({ initialData, getFormErrors },
|
||||
data={values}
|
||||
setDataFn={setValue}
|
||||
fieldName="aimedTo"
|
||||
options={exampleOfAimedToOptions}
|
||||
options={aimedToOptions}
|
||||
errors={errors}
|
||||
register={register}
|
||||
trigger={trigger}
|
||||
@@ -191,7 +262,7 @@ const BandoEditFormStep1 = forwardRef(function ({ initialData, getFormErrors },
|
||||
data={values}
|
||||
setDataFn={setValue}
|
||||
fieldName="faq"
|
||||
options={exampleOfFaqOptions}
|
||||
options={faqOptions}
|
||||
errors={errors}
|
||||
register={register}
|
||||
trigger={trigger}
|
||||
@@ -210,6 +281,7 @@ const BandoEditFormStep1 = forwardRef(function ({ initialData, getFormErrors },
|
||||
</div>
|
||||
|
||||
<BandoEditFormActions
|
||||
id={values.id}
|
||||
openPreview={openPreview}
|
||||
openPreviewEvaluation={openPreviewEvaluation}/>
|
||||
</form>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { forwardRef, useEffect, useImperativeHandle } from 'react';
|
||||
import React, { forwardRef, useEffect, useImperativeHandle, useMemo, useState } from 'react';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useForm } from 'react-hook-form';
|
||||
@@ -10,9 +10,14 @@ import FormFieldRepeater from '../../../../components/FormFieldRepeater';
|
||||
import FormFieldRepeaterCriteria from '../../../../components/FormFieldRepeaterCriteria';
|
||||
import BandoEditFormActions from '../BandoEditFormActions';
|
||||
import UnsavedChangesDetector from '../../../../components/UnsavedChangesDetector';
|
||||
import BandoService from '../../../../service/bando-service';
|
||||
import LookupdataService from '../../../../service/lookupdata-service';
|
||||
|
||||
const BandoEditFormStep2 = forwardRef(function ({ initialData, getFormErrors }, ref) {
|
||||
const navigate = useNavigate();
|
||||
const [criteriaOptions, setCriteriaOptions] = useState([]);
|
||||
const [checklistOptions, setChecklistOptions] = useState([]);
|
||||
const [formInitialData, setFormInitialData] = useState(initialData);
|
||||
const {
|
||||
control,
|
||||
handleSubmit,
|
||||
@@ -21,27 +26,71 @@ const BandoEditFormStep2 = forwardRef(function ({ initialData, getFormErrors },
|
||||
register,
|
||||
trigger,
|
||||
getValues,
|
||||
clearErrors
|
||||
} = useForm({defaultValues: initialData, mode: 'onChange'});
|
||||
clearErrors,
|
||||
reset
|
||||
} = useForm({
|
||||
defaultValues: useMemo(() => {
|
||||
return formInitialData;
|
||||
}, [formInitialData]), mode: 'onChange'
|
||||
});
|
||||
const values = getValues();
|
||||
const step2Props = ['threshold', 'criteria', 'checkList', 'docs', 'images'];
|
||||
|
||||
const onSubmit = (formData) => {
|
||||
if (!isNil(formData.dates) && formData.dates.length) {
|
||||
formData.dates = formData.dates.map(v => is(String, v) ? v : v.toISOString());
|
||||
}
|
||||
console.log('onSubmit', formData);
|
||||
|
||||
const forSubmit = Object.keys(formData).reduce((acc, cur) => {
|
||||
if (step2Props.includes(cur)) {
|
||||
acc[cur] = formData[cur];
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
BandoService.updateBandoStep2(formData.id, forSubmit, createCallback, errCreateCallback);
|
||||
};
|
||||
|
||||
// TODO temp data
|
||||
const exampleOfCriteriaOptions = [
|
||||
{ id: 15, value: 'Innovatività del progetto', score: 9 },
|
||||
{ id: 16, value: 'Impatto sulla competitività dell\'azienda', score: 3 },
|
||||
{ id: 17, value: 'Sostenibilità economico-finanziaria', score: 5 }
|
||||
];
|
||||
const exampleOfChecklistOptions = [
|
||||
{ id: 15, value: 'Innovatività del progetto' }
|
||||
];
|
||||
// end of temp data
|
||||
const createCallback = (data) => {
|
||||
if (data.status === 'SUCCESS') {
|
||||
setFormInitialData(data.data);
|
||||
reset();
|
||||
}
|
||||
}
|
||||
|
||||
const errCreateCallback = (data) => {
|
||||
console.log('errCreateCallback', data);
|
||||
}
|
||||
|
||||
const lookupdataCallback = (data) => {
|
||||
if (data.status === 'SUCCESS') {
|
||||
const criteria = data.data
|
||||
.filter(o => o.type === 'EVALUATION_CRITERIA')
|
||||
.map(o => {
|
||||
delete o.type;
|
||||
return {
|
||||
...o,
|
||||
score: 0,
|
||||
lookUpDataId: o.id
|
||||
};
|
||||
});
|
||||
setCriteriaOptions(criteria);
|
||||
const checklist = data.data
|
||||
.filter(o => o.type === 'CHECKLIST')
|
||||
.map(o => {
|
||||
delete o.type;
|
||||
return {
|
||||
...o,
|
||||
lookUpDataId: o.id
|
||||
};
|
||||
});
|
||||
setChecklistOptions(checklist);
|
||||
}
|
||||
}
|
||||
|
||||
const errLookupdataCallback = (data) => {
|
||||
console.log('errLookupdataCallback', data)
|
||||
}
|
||||
|
||||
const openPreview = () => {
|
||||
navigate('/bandi/preview/11');
|
||||
@@ -67,8 +116,17 @@ const BandoEditFormStep2 = forwardRef(function ({ initialData, getFormErrors },
|
||||
}
|
||||
}, [errors, isValid]);
|
||||
|
||||
useEffect(() => {
|
||||
setFormInitialData(initialData);
|
||||
}, [initialData]);
|
||||
|
||||
useEffect(() => {
|
||||
reset(formInitialData);
|
||||
}, [formInitialData]);
|
||||
|
||||
useEffect(() => {
|
||||
trigger().then(() => clearErrors());
|
||||
LookupdataService.getItems(lookupdataCallback, errLookupdataCallback, [['type', ['CHECKLIST', 'EVALUATION_CRITERIA']]])
|
||||
}, []);
|
||||
|
||||
return (
|
||||
@@ -78,7 +136,7 @@ const BandoEditFormStep2 = forwardRef(function ({ initialData, getFormErrors },
|
||||
data={values}
|
||||
setDataFn={setValue}
|
||||
fieldName="criteria"
|
||||
options={exampleOfCriteriaOptions}
|
||||
options={criteriaOptions}
|
||||
errors={errors}
|
||||
register={register}
|
||||
label={<>{__('Criteri di valutazione', 'gepafin')}*
|
||||
@@ -95,17 +153,18 @@ const BandoEditFormStep2 = forwardRef(function ({ initialData, getFormErrors },
|
||||
<FormField
|
||||
type="fileupload"
|
||||
setDataFn={setValue}
|
||||
fieldName="documentation"
|
||||
fieldName="docs"
|
||||
label={__('Documentazione', 'gepafin')}
|
||||
control={control}
|
||||
errors={errors}
|
||||
defaultValue={values['documentation']}
|
||||
defaultValue={values['docs']}
|
||||
config={{ required: __('È obbligatorio', 'gepafin') }}
|
||||
accept="application/pdf,application/vnd.ms-excel"
|
||||
chooseLabel={__('Aggiungi documento', 'gepafin')}
|
||||
multiple={true}
|
||||
doctype='document'
|
||||
register={register}
|
||||
callId={values.id}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
@@ -118,13 +177,14 @@ const BandoEditFormStep2 = forwardRef(function ({ initialData, getFormErrors },
|
||||
defaultValue={values['images']}
|
||||
doctype='images'
|
||||
register={register}
|
||||
callId={values.id}
|
||||
/>
|
||||
|
||||
<FormFieldRepeater
|
||||
data={values}
|
||||
setDataFn={setValue}
|
||||
fieldName="checklist"
|
||||
options={exampleOfChecklistOptions}
|
||||
fieldName="checkList"
|
||||
options={checklistOptions}
|
||||
errors={errors}
|
||||
register={register}
|
||||
label={<>{__('Checklist valutazione Pre-Istruttoria', 'gepafin')}*
|
||||
|
||||
@@ -1,31 +1,37 @@
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { useNavigate, useParams } from 'react-router-dom';
|
||||
//import equal from 'fast-deep-equal';
|
||||
import { is, isNil } from 'ramda';
|
||||
|
||||
// components
|
||||
// store
|
||||
import { storeSet, useStore } from '../../store';
|
||||
|
||||
// api
|
||||
import BandoService from '../../service/bando-service';
|
||||
|
||||
// tools
|
||||
import getBandoLabel from '../../helpers/getBandoLabel';
|
||||
|
||||
// components
|
||||
import { Button } from 'primereact/button';
|
||||
import { Skeleton } from 'primereact/skeleton';
|
||||
import { Steps } from 'primereact/steps';
|
||||
import BandoEditFormStep1 from './components/BandoEditFormStep1';
|
||||
import BandoEditFormStep2 from './components/BandoEditFormStep2';
|
||||
import { Messages } from 'primereact/messages';
|
||||
|
||||
// TODO temp
|
||||
import { bandoTest } from '../../tempData';
|
||||
import FormsService from '../../service/forms-service';
|
||||
|
||||
const BandoEdit = () => {
|
||||
const isAsyncRequest = useStore().main.isAsyncRequest();
|
||||
const navigate = useNavigate();
|
||||
const { id } = useParams();
|
||||
const [activeStep, setActiveStep] = useState(0)
|
||||
const [activeStep, setActiveStep] = useState(null)
|
||||
const [data, setData] = useState({});
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [forms, setForms] = useState([]);
|
||||
//const [selectedTemplate, setSelectedTemplate] = useState(null);
|
||||
//const [templates, setTemplate] = useState(null);
|
||||
const formRef = useRef(null);
|
||||
const stepErrorMsgs = useRef(null);
|
||||
const bandoMsgs = useRef(null);
|
||||
|
||||
const stepItems = [
|
||||
{
|
||||
@@ -34,7 +40,7 @@ const BandoEdit = () => {
|
||||
if (activeStep === 0) {
|
||||
return false
|
||||
}
|
||||
stepErrorMsgs.current.clear();
|
||||
bandoMsgs.current.clear();
|
||||
const isFormValid = formRef.current.isFormValid();
|
||||
//const values = formRef.current.getValues();
|
||||
//const diffData = equal(values, data);
|
||||
@@ -42,10 +48,13 @@ const BandoEdit = () => {
|
||||
if (isFormValid) {
|
||||
goToStep(0)
|
||||
} else {
|
||||
stepErrorMsgs.current.show([
|
||||
{ sticky: true, severity: 'error', summary: 'Error',
|
||||
bandoMsgs.current.show([
|
||||
{
|
||||
id: '98',
|
||||
sticky: true, severity: 'error', summary: 'Error',
|
||||
detail: __('Potrai andare su altro step dopo risolvere errori della forma', 'gepafin'),
|
||||
closable: true }
|
||||
closable: true
|
||||
}
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -56,7 +65,7 @@ const BandoEdit = () => {
|
||||
if (activeStep === 1) {
|
||||
return false
|
||||
}
|
||||
stepErrorMsgs.current.clear();
|
||||
bandoMsgs.current.clear();
|
||||
const isFormValid = formRef.current.isFormValid();
|
||||
//const values = formRef.current.getValues();
|
||||
//const diffData = equal(values, data);
|
||||
@@ -64,10 +73,13 @@ const BandoEdit = () => {
|
||||
if (isFormValid) {
|
||||
goToStep(1);
|
||||
} else {
|
||||
stepErrorMsgs.current.show([
|
||||
{ sticky: true, severity: 'error', summary: 'Error',
|
||||
bandoMsgs.current.show([
|
||||
{
|
||||
id: '98',
|
||||
sticky: true, severity: 'error', summary: 'Error',
|
||||
detail: __('Potrai andare su altro step dopo risolvere errori della forma', 'gepafin'),
|
||||
closable: true }
|
||||
closable: true
|
||||
}
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -79,40 +91,151 @@ const BandoEdit = () => {
|
||||
}
|
||||
|
||||
const openBandoFormManagement = () => {
|
||||
navigate('/bandi/11/forms');
|
||||
navigate(`/bandi/${id}/forms`);
|
||||
}
|
||||
|
||||
const validateBando = () => {
|
||||
storeSet.main.setAsyncRequest();
|
||||
bandoMsgs.current.clear();
|
||||
BandoService.validateBando(id, validateCallback, errValidateCallback);
|
||||
}
|
||||
|
||||
const validateCallback = (data) => {
|
||||
if (data.status === 'SUCCESS') {
|
||||
if (bandoMsgs.current) {
|
||||
bandoMsgs.current.show([
|
||||
{
|
||||
id: '99',
|
||||
sticky: true, severity: 'success', summary: '',
|
||||
detail: __('Potrai pubblicare il tuo Bando.', 'gepafin'),
|
||||
closable: false
|
||||
}
|
||||
]);
|
||||
}
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
|
||||
const errValidateCallback = (data) => {
|
||||
standardErrCallback(data);
|
||||
}
|
||||
|
||||
const publishBando = () => {
|
||||
storeSet.main.setAsyncRequest();
|
||||
bandoMsgs.current.clear();
|
||||
BandoService.updateBandoStatus(id, publishCallback, errPublishCallback, [['status', 'PUBLISH']]);
|
||||
}
|
||||
|
||||
const publishCallback = (data) => {
|
||||
if (data.status === 'SUCCESS') {
|
||||
if (bandoMsgs.current) {
|
||||
bandoMsgs.current.show([
|
||||
{
|
||||
id: '99',
|
||||
sticky: true, severity: 'success', summary: '',
|
||||
detail: __('Pubblicato!', 'gepafin'),
|
||||
closable: false
|
||||
}
|
||||
]);
|
||||
}
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
|
||||
const errPublishCallback = (data) => {
|
||||
standardErrCallback(data);
|
||||
}
|
||||
|
||||
const getCallback = (data) => {
|
||||
if (data.status === 'SUCCESS') {
|
||||
if (!isNil(data.data.dates) && data.data.dates.length) {
|
||||
data.data.dates = data.data.dates.map(v => is(String, v) ? new Date(v) : v);
|
||||
}
|
||||
|
||||
if (data.data.status === 'READY_TO_PUBLISH') {
|
||||
bandoMsgs.current.clear();
|
||||
bandoMsgs.current.show([
|
||||
{
|
||||
id: '1',
|
||||
sticky: true, severity: 'info', summary: 'Info',
|
||||
detail: __('Potrai pubblicare il tuo Bando.', 'gepafin'),
|
||||
closable: false
|
||||
}
|
||||
]);
|
||||
} else if (data.data.status === 'DRAFT') {
|
||||
if (bandoMsgs.current) {
|
||||
bandoMsgs.current.clear();
|
||||
bandoMsgs.current.show([
|
||||
{
|
||||
id: '1',
|
||||
sticky: true, severity: 'info', summary: 'Info',
|
||||
detail: __('Potrai pubblicare il tuo Bando solo dopo aver completato tutti i campi obbligatori contrassegnati dagli asterischi.', 'gepafin'),
|
||||
closable: false
|
||||
}
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
setData(data.data);
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
|
||||
const errGetCallback = (data) => {
|
||||
standardErrCallback(data);
|
||||
}
|
||||
|
||||
const standardErrCallback = (data) => {
|
||||
if (bandoMsgs.current && data.message) {
|
||||
bandoMsgs.current.show([
|
||||
{
|
||||
sticky: true, severity: 'error', summary: 'Error',
|
||||
detail: data.message,
|
||||
closable: true
|
||||
}
|
||||
]);
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
|
||||
const getFormsCallback = (data) => {
|
||||
if (data.status === 'SUCCESS') {
|
||||
setForms(data.data);
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
storeSet.main.setAsyncRequest();
|
||||
setActiveStep(0);
|
||||
|
||||
const parsed = parseInt(id)
|
||||
const bandoId = !isNaN(parsed) ? parsed : 0;
|
||||
|
||||
const data = 0 === bandoId
|
||||
? {
|
||||
if (bandoId === 0) {
|
||||
setData({
|
||||
status: 'draft',
|
||||
name: ''
|
||||
}
|
||||
: bandoTest;
|
||||
});
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
|
||||
if (bandoId === 0) {
|
||||
setData(data);
|
||||
setIsLoading(false);
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
if (!isNil(data.dates) && data.dates.length) {
|
||||
data.dates = data.dates.map(v => is(String, v) ? new Date(v) : v);
|
||||
if (bandoMsgs.current) {
|
||||
bandoMsgs.current.clear();
|
||||
bandoMsgs.current.show([
|
||||
{
|
||||
id: '1',
|
||||
sticky: true, severity: 'info', summary: 'Info',
|
||||
detail: __('Potrai pubblicare il tuo Bando solo dopo aver completato tutti i campi obbligatori contrassegnati dagli asterischi.', 'gepafin'),
|
||||
closable: false
|
||||
}
|
||||
|
||||
setData(data);
|
||||
|
||||
/*const templates = [
|
||||
{ name: 'Il mio template', value: 22 },
|
||||
{ name: 'Template #11', value: 11 },
|
||||
];
|
||||
setTemplate(templates);*/
|
||||
setIsLoading(false);
|
||||
}, 2000);
|
||||
]);
|
||||
}
|
||||
}, [id]);
|
||||
} else {
|
||||
BandoService.getBando(id, getCallback, errGetCallback);
|
||||
FormsService.getFormsForCall(id, getFormsCallback, () => {
|
||||
});
|
||||
}
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="appPage">
|
||||
@@ -146,7 +269,7 @@ const BandoEdit = () => {
|
||||
icon="pi pi-check"
|
||||
iconPos="right"/>
|
||||
</div> : null*/}
|
||||
{!isLoading
|
||||
{!isAsyncRequest
|
||||
? <Steps
|
||||
model={stepItems}
|
||||
activeIndex={activeStep}
|
||||
@@ -155,13 +278,14 @@ const BandoEdit = () => {
|
||||
|
||||
<div className="appPage__spacer"></div>
|
||||
|
||||
<Messages ref={stepErrorMsgs} />
|
||||
<Messages ref={bandoMsgs}/>
|
||||
|
||||
{!isLoading
|
||||
{!isAsyncRequest
|
||||
? <>
|
||||
{activeStep === 0
|
||||
? <BandoEditFormStep1 initialData={data} ref={formRef}/>
|
||||
: <BandoEditFormStep2 initialData={data} ref={formRef}/>}
|
||||
? <BandoEditFormStep1 initialData={data} ref={formRef}/> : null}
|
||||
{activeStep === 1
|
||||
? <BandoEditFormStep2 initialData={data} ref={formRef}/> : null}
|
||||
|
||||
<div className="appPageSection">
|
||||
<h2>{__('Crea o modifica il Form compilabile dal Beneficiario', 'gepafin')}</h2>
|
||||
@@ -169,6 +293,34 @@ const BandoEdit = () => {
|
||||
type="button"
|
||||
onClick={openBandoFormManagement}
|
||||
label={__('Crea/modifica form', 'gepafin')}/>
|
||||
|
||||
{forms.length
|
||||
? <ul className="">
|
||||
{forms.map(o => <li key={o.id}>
|
||||
{o.label}
|
||||
</li>)}
|
||||
</ul>
|
||||
: <p>No forms created yet.</p>}
|
||||
</div>
|
||||
|
||||
<div className="appPage__spacer"></div>
|
||||
|
||||
<div className="appPageSection">
|
||||
<h2>{__('Publicca il Form', 'gepafin')}</h2>
|
||||
|
||||
<div className="appPageSection__actions">
|
||||
<Button
|
||||
type="button"
|
||||
outlined
|
||||
disabled={!(data.status === 'DRAFT')}
|
||||
onClick={validateBando}
|
||||
label={__('Validate', 'gepafin')}/>
|
||||
<Button
|
||||
type="button"
|
||||
disabled={!(data.status === 'READY_TO_PUBLISH')}
|
||||
onClick={publishBando}
|
||||
label={__('Publish', 'gepafin')}/>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
: <>
|
||||
|
||||
Reference in New Issue
Block a user