diff --git a/src/helpers/getBandoLabel.js b/src/helpers/getBandoLabel.js index 0986759..0439b31 100644 --- a/src/helpers/getBandoLabel.js +++ b/src/helpers/getBandoLabel.js @@ -20,6 +20,9 @@ const getBandoLabel = (status) => { case 'AWAITING': return __('In attesa', 'gepafin'); + case 'AWAIT': + return __('In attesa', 'gepafin'); + case 'EXPIRED': return __('Scaduto', 'gepafin'); diff --git a/src/helpers/getBandoSeverity.js b/src/helpers/getBandoSeverity.js index 829fd52..e2232ee 100644 --- a/src/helpers/getBandoSeverity.js +++ b/src/helpers/getBandoSeverity.js @@ -18,6 +18,9 @@ const getBandoSeverity = (status) => { case 'AWAITING': return 'warning'; + case 'AWAIT': + return 'warning'; + case 'EXPIRED': return 'closed'; diff --git a/src/pages/BandoApplication/index.js b/src/pages/BandoApplication/index.js index bb80674..e9259dc 100644 --- a/src/pages/BandoApplication/index.js +++ b/src/pages/BandoApplication/index.js @@ -4,7 +4,6 @@ import { useParams } from 'react-router-dom'; import { head, is, pluck, isEmpty, pathOr } from 'ramda'; import { useForm } from 'react-hook-form'; import { TZDate } from '@date-fns/tz'; -import { klona } from 'klona'; // store import { storeSet, storeGet, useStore } from '../../store'; @@ -86,7 +85,7 @@ const BandoApplication = () => { const activeStepIndex = activeStep - 1; const values = getValues(); - const onSubmit = () => { + const onValidate = () => { const applId = getApplicationId(); storeSet.main.setAsyncRequest(); formMsgs.current.clear(); @@ -94,6 +93,70 @@ const BandoApplication = () => { ApplicationService.validateApplication(applId, {}, validateApplicationCallback, errValidateApplicationCallback); }; + const onSubmit = () => { + const applId = getApplicationId(); + storeSet.main.setAsyncRequest(); + formMsgs.current.clear(); + + ApplicationService.updateStatusApplication(applId, {}, submitApplicationCallback, errSubmitApplicationCallback, [ + ['status', 'SUBMIT'] + ]); + }; + + const submitApplicationCallback = (data) => { + if (data.status === 'SUCCESS') { + if (data.data.status) { + setApplicationStatus(data.data.status); // ask why not 'applicationStatus'? + } + } + 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 if (data.status === 'EXCEPTION_ERROR') { + if (formMsgs.current) { + formMsgs.current.show([ + { + id: '99', + sticky: true, severity: 'error', summary: '', + detail: data.message, + closable: true + } + ]); + } + } else if (data.status === 'BAD_REQUEST') { + if (formMsgs.current) { + formMsgs.current.show([ + { + id: '99', + sticky: true, severity: 'error', summary: '', + detail: data.message, + closable: true + } + ]); + toast.current.show({ + severity: 'error', + summary: '', + detail: data.message + }); + } + } else { + set404FromErrorResponse(data); + } + } + const validateApplicationCallback = (data) => { if (data.status === 'SUCCESS') { if (data.data.status) { @@ -383,13 +446,19 @@ const BandoApplication = () => { const handleSetSignedDocumentFromFileupload = (fieldName, stateFieldData) => { setSignedPdfFile(stateFieldData); - if (!isEmpty(stateFieldData)) { + setApplicationStatus('READY'); + + /*if (!isEmpty(stateFieldData)) { setVisibleConfirmation(true); - } + }*/ } useEffect(() => { if ('SUBMIT' === applicationStatus) { + setVisibleConfirmation(true); + } + + if (['AWAIT', 'READY', 'SUBMIT'].includes(applicationStatus)) { const applId = getApplicationId(); if (applId) { @@ -451,13 +520,14 @@ const BandoApplication = () => {