@@ -13,7 +14,7 @@ const BandoEditFormActions = ({ openPreview, openPreviewEvaluation }) => {
label={__('Salva bozza', 'gepafin')} icon="pi pi-save" iconPos="right"/>
diff --git a/src/pages/BandoEdit/components/BandoEditFormStep1/index.js b/src/pages/BandoEdit/components/BandoEditFormStep1/index.js
index bdd0ccd..c7bbb81 100644
--- a/src/pages/BandoEdit/components/BandoEditFormStep1/index.js
+++ b/src/pages/BandoEdit/components/BandoEditFormStep1/index.js
@@ -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 (
diff --git a/src/pages/BandoEdit/components/BandoEditFormStep2/index.js b/src/pages/BandoEdit/components/BandoEditFormStep2/index.js
index d4e742d..a5f2169 100644
--- a/src/pages/BandoEdit/components/BandoEditFormStep2/index.js
+++ b/src/pages/BandoEdit/components/BandoEditFormStep2/index.js
@@ -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 },
{__('Checklist valutazione Pre-Istruttoria', 'gepafin')}*
diff --git a/src/pages/BandoEdit/index.js b/src/pages/BandoEdit/index.js
index e816789..3fe8aa1 100644
--- a/src/pages/BandoEdit/index.js
+++ b/src/pages/BandoEdit/index.js
@@ -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 (
@@ -146,7 +269,7 @@ const BandoEdit = () => {
icon="pi pi-check"
iconPos="right"/>
: null*/}
- {!isLoading
+ {!isAsyncRequest
? {
-
+
- {!isLoading
+ {!isAsyncRequest
? <>
{activeStep === 0
- ?
- : }
+ ? : null}
+ {activeStep === 1
+ ? : null}
{__('Crea o modifica il Form compilabile dal Beneficiario', 'gepafin')}
@@ -169,6 +293,34 @@ const BandoEdit = () => {
type="button"
onClick={openBandoFormManagement}
label={__('Crea/modifica form', 'gepafin')}/>
+
+ {forms.length
+ ?
+ {forms.map(o => -
+ {o.label}
+
)}
+
+ :
No forms created yet.
}
+
+
+
+
+
+
{__('Publicca il Form', 'gepafin')}
+
+
+
+
+
>
: <>
diff --git a/src/pages/BandoForms/index.js b/src/pages/BandoForms/index.js
index 19002ae..c868532 100644
--- a/src/pages/BandoForms/index.js
+++ b/src/pages/BandoForms/index.js
@@ -1,18 +1,25 @@
-import React, { useState, useEffect, useRef } from 'react';
+import React, { useState, useEffect } from 'react';
import { __ } from '@wordpress/i18n';
import { useParams, useNavigate } from 'react-router-dom';
+import { isEmpty } from 'ramda';
// components
import { Button } from 'primereact/button';
import { Dropdown } from 'primereact/dropdown';
+// service
+import FormsService from '../../service/forms-service';
+
+// store
+import { storeSet } from '../../store';
+
const BandoForms = () => {
const { id } = useParams();
const navigate = useNavigate()
- const [templates, setTemplate] = useState(null);
+ const [templates, setTemplates] = useState(null);
const [selectedTemplate, setSelectedTemplate] = useState(null);
- //const [data, setData] = useState({});
- //const [isLoading, setIsLoading] = useState(true);
+ const [selectedForm, setSelectedForm] = useState(null);
+ const [forms, setForms] = useState([]);
const doCreateNewForm = () => {
navigate(`/bandi/${id}/forms/new`);
@@ -22,17 +29,35 @@ const BandoForms = () => {
navigate(`/bandi/${id}`);
}
+ const goToEditForm = () => {
+ if (selectedForm && selectedForm !== 0) {
+ navigate(`/bandi/${id}/forms/${selectedForm}`);
+ }
+ }
+
+ const goToEditFormFromTemplate = () => {
+ console.log('goToEditFormFromTemplate', selectedTemplate)
+ //navigate(`/bandi/${id}`);
+ }
+
+ const getFormsCallback = (data) => {
+ if (data.status === 'SUCCESS') {
+ const forms = data.data.map(o => ({label: o.label, value: o.id}))
+ setForms(forms);
+ }
+ storeSet.main.unsetAsyncRequest();
+ }
+
useEffect(() => {
const parsed = parseInt(id)
const bandoId = !isNaN(parsed) ? parsed : 0;
- const templates = [
- { name: 'Il mio template', value: 22 },
- { name: 'Template #11', value: 11 },
- ];
- setTemplate(templates);
+ setTemplates([
+ {label: "Form template", value: 11}
+ ])
- // TODO
+ storeSet.main.setAsyncRequest();
+ FormsService.getFormsForCall(bandoId, getFormsCallback, () => {});
}, [id]);
return (
@@ -66,8 +91,15 @@ const BandoForms = () => {
value={selectedTemplate}
onChange={(e) => setSelectedTemplate(e.value)}
options={templates}
- optionLabel="name"
+ optionLabel="label"
placeholder={__('Seleziona template', 'gepafin')}/>
+