- updated zustand and react libraries;
- added 'put in draft' btn;
This commit is contained in:
@@ -99,7 +99,7 @@ const BandoEditFormStep1 = forwardRef(function ({ initialData, setInitialData, g
|
||||
delete formData.startDate;
|
||||
delete formData.endDate;
|
||||
|
||||
storeSet.main.setAsyncRequest();
|
||||
storeSet('setAsyncRequest');
|
||||
if (!formData.id) {
|
||||
BandoService.createBando(formData, createCallback, errCreateCallback);
|
||||
} else {
|
||||
@@ -108,7 +108,7 @@ const BandoEditFormStep1 = forwardRef(function ({ initialData, setInitialData, g
|
||||
}
|
||||
|
||||
const createCallback = (data) => {
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
if (data.status === 'SUCCESS') {
|
||||
if (toast.current) {
|
||||
toast.current.show({
|
||||
@@ -119,7 +119,7 @@ const BandoEditFormStep1 = forwardRef(function ({ initialData, setInitialData, g
|
||||
}
|
||||
const values = getValues();
|
||||
if (!values.id && data.data.id) {
|
||||
storeSet.main.setAsyncRequest();
|
||||
storeSet('setAsyncRequest');
|
||||
const sampleFormData = {
|
||||
label: `Evaluation form for call #${data.data.id}`,
|
||||
content: []
|
||||
@@ -141,19 +141,19 @@ const BandoEditFormStep1 = forwardRef(function ({ initialData, setInitialData, g
|
||||
});
|
||||
}
|
||||
set404FromErrorResponse(data);
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
}
|
||||
|
||||
const createFormCallback = (resp) => {
|
||||
if (resp.status === 'SUCCESS') {
|
||||
navigate(`/bandi/${resp.data.callId}`);
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
}
|
||||
|
||||
const errCreateFormCallback = (resp) => {
|
||||
set404FromErrorResponse(resp);
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
}
|
||||
|
||||
const openPreview = () => {
|
||||
@@ -189,11 +189,11 @@ const BandoEditFormStep1 = forwardRef(function ({ initialData, setInitialData, g
|
||||
});
|
||||
setFaqOptions(faqItems);
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
}
|
||||
|
||||
const errLookupdataCallback = (data) => {
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
}
|
||||
|
||||
const shouldDisableField = (fieldName) => {
|
||||
@@ -223,7 +223,7 @@ const BandoEditFormStep1 = forwardRef(function ({ initialData, setInitialData, g
|
||||
}, [errors, isValid]);
|
||||
|
||||
useEffect(() => {
|
||||
storeSet.main.formInitialData(initialData);
|
||||
storeSet('formInitialData', initialData);
|
||||
setFormInitialData(initialData);
|
||||
}, [initialData]);
|
||||
|
||||
@@ -256,7 +256,7 @@ const BandoEditFormStep1 = forwardRef(function ({ initialData, setInitialData, g
|
||||
LookupdataService.getItems(lookupdataCallback, errLookupdataCallback, [['type', ['AIMED_TO', 'FAQ']]]);
|
||||
|
||||
return () => {
|
||||
storeSet.main.formInitialData({});
|
||||
storeSet('formInitialData', {});
|
||||
}
|
||||
}, []);
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ const BandoEditFormStep2 = forwardRef(function ({ initialData, setInitialData, g
|
||||
delete formData.startDate;
|
||||
delete formData.endDate;
|
||||
|
||||
storeSet.main.setAsyncRequest();
|
||||
storeSet('setAsyncRequest');
|
||||
if (values.evaluationVersion === 'V1') {
|
||||
BandoService.updateBandoStep2(formData.id, formData, createCallback, errCreateCallback);
|
||||
} else if (values.evaluationVersion === 'V2') {
|
||||
@@ -102,7 +102,7 @@ const BandoEditFormStep2 = forwardRef(function ({ initialData, setInitialData, g
|
||||
}
|
||||
|
||||
const createCallback = (data) => {
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
if (data.status === 'SUCCESS') {
|
||||
toast.current.show({
|
||||
severity: 'success',
|
||||
@@ -116,7 +116,7 @@ const BandoEditFormStep2 = forwardRef(function ({ initialData, setInitialData, g
|
||||
}
|
||||
|
||||
const errCreateCallback = (data) => {
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
console.log('errCreateCallback', data);
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ const BandoEditFormStep2 = forwardRef(function ({ initialData, setInitialData, g
|
||||
}, [errors, isValid]);
|
||||
|
||||
useEffect(() => {
|
||||
storeSet.main.formInitialData(initialData);
|
||||
storeSet('formInitialData', initialData);
|
||||
setFormInitialData(initialData);
|
||||
}, [initialData]);
|
||||
|
||||
@@ -205,7 +205,7 @@ const BandoEditFormStep2 = forwardRef(function ({ initialData, setInitialData, g
|
||||
LookupdataService.getItems(lookupdataCallback, errLookupdataCallback, [['type', ['CHECKLIST', 'EVALUATION_CRITERIA']]]);
|
||||
|
||||
return () => {
|
||||
storeSet.main.formInitialData({});
|
||||
storeSet('formInitialData', {});
|
||||
}
|
||||
}, []);
|
||||
|
||||
|
||||
@@ -35,14 +35,14 @@ const BandoEditFormStep3 = forwardRef(function () {
|
||||
}
|
||||
|
||||
const onSaveDraft = () => {
|
||||
const content = storeGet.main.formElements();
|
||||
const formId = storeGet.main.formId();
|
||||
const content = storeGet('formElements');
|
||||
const formId = storeGet('formId');
|
||||
const formData = {
|
||||
label: formName,
|
||||
content
|
||||
}
|
||||
|
||||
storeSet.main.setAsyncRequest();
|
||||
storeSet('setAsyncRequest');
|
||||
EvaluationFormsService.updateForm(formId, formData, updateFormCallback, errUpdateFormCallback)
|
||||
}
|
||||
|
||||
@@ -57,12 +57,12 @@ const BandoEditFormStep3 = forwardRef(function () {
|
||||
});
|
||||
}
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
}
|
||||
|
||||
const errUpdateFormCallback = (resp) => {
|
||||
set404FromErrorResponse(resp);
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
}
|
||||
|
||||
const openPreview = () => {
|
||||
@@ -77,51 +77,52 @@ const BandoEditFormStep3 = forwardRef(function () {
|
||||
|
||||
const getElementItemsCallback = (data) => {
|
||||
if (data.status === 'SUCCESS') {
|
||||
//storeSet.main.elementItems(elementItems.sort((a, b) => a.sortOrder - b.sortOrder));
|
||||
storeSet.main.elementItems(
|
||||
//storeSet('elementItems', elementItems.sort((a, b) => a.sortOrder - b.sortOrder));
|
||||
storeSet(
|
||||
'elementItems',
|
||||
data.data
|
||||
.filter(o => !['fileselect'].includes(o.name))
|
||||
.sort((a, b) => a.sortOrder - b.sortOrder)
|
||||
);
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
}
|
||||
|
||||
const errGetElementItemsCallbacks = (data) => {
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
}
|
||||
|
||||
const getFormCallback = (resp) => {
|
||||
if (resp.status === 'SUCCESS') {
|
||||
storeSet.main.formId(resp.data.id);
|
||||
storeSet.main.formLabel(resp.data.label);
|
||||
storeSet('formId', resp.data.id);
|
||||
storeSet('formLabel', resp.data.label);
|
||||
setFormName(resp.data.label);
|
||||
setBandoStatus(resp.data.callStatus);
|
||||
const elements = klona(resp.data.content);
|
||||
storeSet.main.formElements(elements);
|
||||
storeSet('formElements', elements);
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
}
|
||||
|
||||
const errGetFormCallback = (resp) => {
|
||||
set404FromErrorResponse(resp);
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
storeSet.main.setAsyncRequest();
|
||||
storeSet('setAsyncRequest');
|
||||
EvaluationFormsService.getFormForCall(id, getFormCallback, errGetFormCallback)
|
||||
}, [id]);
|
||||
|
||||
useEffect(() => {
|
||||
storeSet.main.setAsyncRequest();
|
||||
storeSet('setAsyncRequest');
|
||||
FormsService.getElementItems(getElementItemsCallback, errGetElementItemsCallbacks);
|
||||
|
||||
return () => {
|
||||
storeSet.main.formId(0);
|
||||
storeSet.main.formElements([]);
|
||||
storeSet.main.activeElement('');
|
||||
storeSet.main.selectedElement('');
|
||||
storeSet('formId', 0);
|
||||
storeSet('formElements', []);
|
||||
storeSet('activeElement', '');
|
||||
storeSet('selectedElement', '');
|
||||
}
|
||||
}, []);
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import { useNavigate, useParams } from 'react-router-dom';
|
||||
import { is, isNil, isEmpty } from 'ramda';
|
||||
|
||||
// store
|
||||
import { storeSet, useStore } from '../../store';
|
||||
import { storeSet, useStoreValue } from '../../store';
|
||||
|
||||
// api
|
||||
import BandoService from '../../service/bando-service';
|
||||
@@ -24,9 +24,10 @@ import FormsService from '../../service/forms-service';
|
||||
import BlockingOverlay from '../../components/BlockingOverlay';
|
||||
import { Toast } from 'primereact/toast';
|
||||
import BandoEditFormStep3 from './components/BandoEditFormStep3';
|
||||
import { ConfirmPopup, confirmPopup } from 'primereact/confirmpopup';
|
||||
|
||||
const BandoEdit = () => {
|
||||
const isAsyncRequest = useStore().main.isAsyncRequest();
|
||||
const isAsyncRequest = useStoreValue('isAsyncRequest');
|
||||
const navigate = useNavigate();
|
||||
const { id } = useParams();
|
||||
const [activeStep, setActiveStep] = useState(null)
|
||||
@@ -89,7 +90,7 @@ const BandoEdit = () => {
|
||||
}
|
||||
|
||||
const validateBando = () => {
|
||||
storeSet.main.setAsyncRequest();
|
||||
storeSet('setAsyncRequest');
|
||||
bandoMsgs.current.clear();
|
||||
BandoService.validateBando(id, validateCallback, errValidateCallback);
|
||||
}
|
||||
@@ -115,12 +116,12 @@ const BandoEdit = () => {
|
||||
}
|
||||
}
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
}
|
||||
|
||||
const errValidateCallback = (resp) => {
|
||||
if (resp.status === 'VALIDATION_ERROR') {
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
if (bandoMsgs.current) {
|
||||
bandoMsgs.current.show(resp.data.map((v, i) => ({
|
||||
id: i,
|
||||
@@ -142,7 +143,7 @@ const BandoEdit = () => {
|
||||
}
|
||||
|
||||
const publishBando = () => {
|
||||
storeSet.main.setAsyncRequest();
|
||||
storeSet('setAsyncRequest');
|
||||
bandoMsgs.current.clear();
|
||||
BandoService.updateBandoStatus(id, publishCallback, errPublishCallback, [['status', 'PUBLISH']]);
|
||||
}
|
||||
@@ -172,7 +173,7 @@ const BandoEdit = () => {
|
||||
}
|
||||
setData(resp.data);
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
}
|
||||
|
||||
const errPublishCallback = (resp) => {
|
||||
@@ -219,12 +220,12 @@ const BandoEdit = () => {
|
||||
}
|
||||
setData(resp.data);
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
}
|
||||
|
||||
const errGetCallback = (resp) => {
|
||||
set404FromErrorResponse(resp);
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
}
|
||||
|
||||
const standardErrCallback = (resp) => {
|
||||
@@ -237,18 +238,70 @@ const BandoEdit = () => {
|
||||
}
|
||||
]);
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
}
|
||||
|
||||
const getFormsCallback = (resp) => {
|
||||
if (resp.status === 'SUCCESS') {
|
||||
setForms(resp.data);
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
}
|
||||
|
||||
const confirmDelete = (event) => {
|
||||
confirmPopup({
|
||||
target: event.currentTarget,
|
||||
message: __('Sei sicuro di mettere il bando in bozza?', 'gepafin'),
|
||||
acceptLabel: __('Si', 'gepafin'),
|
||||
icon: 'pi pi-info-circle',
|
||||
defaultFocus: 'reject',
|
||||
acceptClassName: 'p-button-danger',
|
||||
accept: unpublishBando,
|
||||
reject: () => {
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const unpublishBando = () => {
|
||||
storeSet('setAsyncRequest');
|
||||
bandoMsgs.current.clear();
|
||||
BandoService.updateBandoStatus(id, unpublishCallback, errUnpublishCallback, [['status', 'DRAFT']]);
|
||||
}
|
||||
|
||||
const unpublishCallback = (resp) => {
|
||||
if (resp.status === 'SUCCESS') {
|
||||
if (bandoMsgs.current) {
|
||||
bandoMsgs.current.show([
|
||||
{
|
||||
id: '99',
|
||||
sticky: true, severity: 'success', summary: '',
|
||||
detail: __('Stato cambiato!', 'gepafin'),
|
||||
closable: false
|
||||
}
|
||||
]);
|
||||
}
|
||||
if (toast.current) {
|
||||
toast.current.show({
|
||||
severity: 'success',
|
||||
summary: '',
|
||||
detail: __('Stato cambiato!', 'gepafin')
|
||||
});
|
||||
}
|
||||
if (resp.data.docs) {
|
||||
resp.data.docs = resp.data.docs
|
||||
.filter(o => o.source === 'CALL' && o.type === 'DOCUMENT');
|
||||
}
|
||||
setData(resp.data);
|
||||
}
|
||||
storeSet('unsetAsyncRequest');
|
||||
}
|
||||
|
||||
const errUnpublishCallback = (resp) => {
|
||||
standardErrCallback(resp);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
storeSet.main.setAsyncRequest();
|
||||
storeSet('setAsyncRequest');
|
||||
setActiveStep(0);
|
||||
|
||||
const parsed = parseInt(id)
|
||||
@@ -259,7 +312,7 @@ const BandoEdit = () => {
|
||||
status: null,
|
||||
evaluationVersion: 'V2'
|
||||
});
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
|
||||
if (bandoMsgs.current) {
|
||||
bandoMsgs.current.clear();
|
||||
@@ -307,10 +360,12 @@ const BandoEdit = () => {
|
||||
{!isEmpty(data)
|
||||
? <>
|
||||
{activeStep === 0
|
||||
? <BandoEditFormStep1 initialData={data} setInitialData={setData} ref={formRef} status={data.status}/>
|
||||
? <BandoEditFormStep1 initialData={data} setInitialData={setData} ref={formRef}
|
||||
status={data.status}/>
|
||||
: null}
|
||||
{activeStep === 1
|
||||
? <BandoEditFormStep2 initialData={data} setInitialData={setData} ref={formRef} status={data.status}/>
|
||||
? <BandoEditFormStep2 initialData={data} setInitialData={setData} ref={formRef}
|
||||
status={data.status}/>
|
||||
: null}
|
||||
{activeStep === 2 && data.evaluationVersion === 'V2'
|
||||
? <BandoEditFormStep3/>
|
||||
@@ -363,6 +418,14 @@ const BandoEdit = () => {
|
||||
disabled={!(data.status === 'READY_TO_PUBLISH')}
|
||||
onClick={publishBando}
|
||||
label={__('Publish', 'gepafin')}/>
|
||||
{'PUBLISH' === data.status
|
||||
? <>
|
||||
<ConfirmPopup/>
|
||||
<Button
|
||||
onClick={confirmDelete}
|
||||
disabled={isAsyncRequest}
|
||||
severity="warning"
|
||||
label={__('Mettere in bozza', 'gepafin')}/></> : null}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
|
||||
Reference in New Issue
Block a user