- added login and loginAdmin;
- fixed bug with saving application data;
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import React, { useState, useEffect, useCallback, useRef } from 'react';
|
||||
import { __, sprintf } from '@wordpress/i18n';
|
||||
import { useNavigate, useParams } from 'react-router-dom';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { klona } from 'klona';
|
||||
import { head, range, is, isNil } from 'ramda';
|
||||
import { head, range, is, pluck } from 'ramda';
|
||||
import { useForm } from 'react-hook-form';
|
||||
|
||||
// store
|
||||
@@ -40,6 +40,7 @@ const BandoApplication = () => {
|
||||
const [bandoTitle, setBandoTitle] = useState('');
|
||||
const [formId, setFormId] = useState('');
|
||||
const [totalSteps, setTotalSteps] = useState(0);
|
||||
const [completedSteps, setCompletedSteps] = useState(0);
|
||||
const [activeStep, setActiveStep] = useState(1);
|
||||
const [stepItems, setStepItems] = useState([{ label: 'Passo' }]);
|
||||
const isAsyncRequest = useStore().main.isAsyncRequest();
|
||||
@@ -67,12 +68,52 @@ const BandoApplication = () => {
|
||||
}
|
||||
|
||||
const onSubmit = () => {
|
||||
const applId = getApplicationId();
|
||||
storeSet.main.setAsyncRequest();
|
||||
|
||||
ApplicationService.updateStatusApplication(applId, {}, submitApplicationCallback, errSubmitApplicationCallback, [
|
||||
['status', 'SUBMIT']
|
||||
]);
|
||||
};
|
||||
|
||||
const saveDraft = useCallback(() => {
|
||||
const submitApplicationCallback = (data) => {
|
||||
if (data.status === 'SUCCESS') {
|
||||
if (toast.current) {
|
||||
toast.current.show({
|
||||
severity: 'success',
|
||||
summary: '',
|
||||
detail: __('La domanda è stata presentata!', 'gepafin')
|
||||
});
|
||||
}
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
|
||||
const errSubmitApplicationCallback = (data) => {
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
if (data.status === 'VALIDATION_ERROR') {
|
||||
if (formMsgs.current) {
|
||||
formMsgs.current.show([
|
||||
{
|
||||
id: '99',
|
||||
sticky: true, severity: 'error', summary: '',
|
||||
detail: data.data.join(', '),
|
||||
closable: true
|
||||
}
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
set404FromErrorResponse(data);
|
||||
}
|
||||
}
|
||||
|
||||
const saveDraft = () => {
|
||||
trigger();
|
||||
const formValues = getValues();
|
||||
const newFormValues = Object.keys(formValues).reduce((acc, cur) => {
|
||||
const usedFieldsIds = pluck('id', formData);
|
||||
const newFormValues = Object.keys(formValues)
|
||||
.filter(v => usedFieldsIds.includes(v))
|
||||
.reduce((acc, cur) => {
|
||||
const formField = head(formData.filter(o => o.id === cur));
|
||||
let fieldVal = formValues[cur];
|
||||
|
||||
@@ -103,32 +144,33 @@ const BandoApplication = () => {
|
||||
formMsgs.current.clear();
|
||||
}
|
||||
|
||||
ApplicationService.submitForm(applId, submitData, submitFormCallback, errSubmitFormCallback, [
|
||||
ApplicationService.saveDraft(applId, submitData, saveDraftCallback, errSaveDraftCallback, [
|
||||
['formId', formId]
|
||||
]);
|
||||
}
|
||||
}, [errors]);
|
||||
}
|
||||
|
||||
const getApplicationId = () => {
|
||||
const parsed = parseInt(id)
|
||||
return !isNaN(parsed) ? parsed : 0;
|
||||
}
|
||||
|
||||
const submitFormCallback = (data) => {
|
||||
const saveDraftCallback = (data) => {
|
||||
if (data.status === 'SUCCESS') {
|
||||
console.log(data.data);
|
||||
if (toast.current) {
|
||||
toast.current.show({
|
||||
severity: 'success',
|
||||
summary: '',
|
||||
detail: __('Saved!', 'gepafin')
|
||||
detail: __('Salvato!', 'gepafin')
|
||||
});
|
||||
}
|
||||
// update info about application completeness
|
||||
ApplicationService.getApplicationForm(data.data.id, getStatusCheckCallback, errGetStatusCheckCallbacks);
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
|
||||
const errSubmitFormCallback = (data) => {
|
||||
const errSaveDraftCallback = (data) => {
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
if (data.status === 'VALIDATION_ERROR') {
|
||||
if (formMsgs.current) {
|
||||
@@ -183,7 +225,8 @@ const BandoApplication = () => {
|
||||
|
||||
setFormId(data.data.formId);
|
||||
setTotalSteps(data.data.totalFormSteps);
|
||||
setActiveStep(data.data.currentStep)
|
||||
setCompletedSteps(data.data.completedSteps);
|
||||
setActiveStep(data.data.currentStep);
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
@@ -203,9 +246,18 @@ const BandoApplication = () => {
|
||||
}
|
||||
}
|
||||
|
||||
const getStatusCheckCallback = (data) => {
|
||||
if (data.status === 'SUCCESS') {
|
||||
setCompletedSteps(data.data.completedSteps);
|
||||
}
|
||||
}
|
||||
|
||||
const errGetStatusCheckCallbacks = (data) => {
|
||||
set404FromErrorResponse(data);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const newFormData = klona(formInitialData);
|
||||
console.log('newFormData', newFormData);
|
||||
newFormData.map(o => setValue(o.fieldId, o.fieldValue));
|
||||
}, [formInitialData]);
|
||||
|
||||
@@ -325,6 +377,11 @@ const BandoApplication = () => {
|
||||
label={__('Vai avanti', 'gepafin')}
|
||||
icon="pi pi-arrow-right"
|
||||
iconPos="right"/> : null}
|
||||
<Button
|
||||
disabled={completedSteps === 0 || completedSteps !== totalSteps}
|
||||
label={__('Invio', 'gepafin')}
|
||||
icon="pi pi-check"
|
||||
iconPos="right"/>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
Reference in New Issue
Block a user