- updated zustand and react libraries;
- added 'put in draft' btn;
This commit is contained in:
@@ -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