- unblocked saving call form partially;
This commit is contained in:
@@ -5,12 +5,13 @@ import { isNil } from 'ramda';
|
||||
// components
|
||||
import { Button } from 'primereact/button';
|
||||
|
||||
const BandoEditFormActions = ({ id, openPreview, openPreviewEvaluation, status }) => {
|
||||
const BandoEditFormActions = ({ id, openPreview, openPreviewEvaluation, submitFn }) => {
|
||||
return (
|
||||
<div className="appPageSection">
|
||||
<div className="appPageSection__actions">
|
||||
<Button
|
||||
type="submit"
|
||||
type="button"
|
||||
onClick={submitFn}
|
||||
label={__('Salva bozza', 'gepafin')} icon="pi pi-save" iconPos="right"/>
|
||||
<Button
|
||||
type="button"
|
||||
|
||||
@@ -63,6 +63,27 @@ const BandoEditFormStep1 = forwardRef(function ({ initialData, getFormErrors, st
|
||||
}
|
||||
};
|
||||
|
||||
const onSaveDraft = () => {
|
||||
const formData = getValues();
|
||||
if (!isNil(formData.dates) && formData.dates.length) {
|
||||
formData.dates = formData.dates.map(v => {
|
||||
if (is(String, v)) {
|
||||
return v;
|
||||
} else {
|
||||
const tzAwareDate = new TZDate(v, 'Europe/Berlin');
|
||||
return tzAwareDate.toISOString().substring(0, 19);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
storeSet.main.setAsyncRequest();
|
||||
if (!formData.id) {
|
||||
BandoService.createBando(formData, createCallback, errCreateCallback);
|
||||
} else {
|
||||
BandoService.updateBandoStep1(formData.id, formData, createCallback, errCreateCallback);
|
||||
}
|
||||
}
|
||||
|
||||
const createCallback = (data) => {
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
if (data.status === 'SUCCESS') {
|
||||
@@ -321,6 +342,7 @@ const BandoEditFormStep1 = forwardRef(function ({ initialData, getFormErrors, st
|
||||
<BandoEditFormActions
|
||||
id={values.id}
|
||||
status={status}
|
||||
submitFn={onSaveDraft}
|
||||
openPreview={openPreview}
|
||||
openPreviewEvaluation={openPreviewEvaluation}/>
|
||||
</form>
|
||||
|
||||
@@ -67,6 +67,27 @@ const BandoEditFormStep2 = forwardRef(function ({ initialData, getFormErrors, st
|
||||
BandoService.updateBandoStep2(formData.id, forSubmit, createCallback, errCreateCallback);
|
||||
};
|
||||
|
||||
const onSaveDraft = () => {
|
||||
const formData = getValues();
|
||||
if (!isNil(formData.dates) && formData.dates.length) {
|
||||
formData.dates = formData.dates.map(v => {
|
||||
if (is(String, v)) {
|
||||
return v;
|
||||
} else {
|
||||
const tzAwareDate = new TZDate(v, 'Europe/Berlin');
|
||||
return tzAwareDate.toISOString().substring(0, 19);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
storeSet.main.setAsyncRequest();
|
||||
if (!formData.id) {
|
||||
BandoService.createBando(formData, createCallback, errCreateCallback);
|
||||
} else {
|
||||
BandoService.updateBandoStep1(formData.id, formData, createCallback, errCreateCallback);
|
||||
}
|
||||
}
|
||||
|
||||
const createCallback = (data) => {
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
if (data.status === 'SUCCESS') {
|
||||
@@ -252,6 +273,7 @@ const BandoEditFormStep2 = forwardRef(function ({ initialData, getFormErrors, st
|
||||
<BandoEditFormActions
|
||||
id={values.id}
|
||||
status={status}
|
||||
submitFn={onSaveDraft}
|
||||
openPreview={openPreview}
|
||||
openPreviewEvaluation={openPreviewEvaluation}/>
|
||||
</form>
|
||||
|
||||
@@ -47,7 +47,8 @@ const BandoEdit = () => {
|
||||
//const values = formRef.current.getValues();
|
||||
//const diffData = equal(values, data);
|
||||
// TODO warn about unsaved data
|
||||
if (isFormValid) {
|
||||
goToStep(0);
|
||||
/*if (isFormValid) {
|
||||
goToStep(0)
|
||||
} else {
|
||||
bandoMsgs.current.show([
|
||||
@@ -58,7 +59,7 @@ const BandoEdit = () => {
|
||||
closable: true
|
||||
}
|
||||
]);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -67,12 +68,14 @@ const BandoEdit = () => {
|
||||
if (activeStep === 1) {
|
||||
return false
|
||||
}
|
||||
console.log('11');
|
||||
bandoMsgs.current.clear();
|
||||
const isFormValid = formRef.current.isFormValid();
|
||||
//const values = formRef.current.getValues();
|
||||
//const diffData = equal(values, data);
|
||||
// TODO warn about unsaved data
|
||||
if (isFormValid) {
|
||||
goToStep(1);
|
||||
/*if (isFormValid) {
|
||||
goToStep(1);
|
||||
} else {
|
||||
bandoMsgs.current.show([
|
||||
@@ -83,7 +86,7 @@ const BandoEdit = () => {
|
||||
closable: true
|
||||
}
|
||||
]);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
];
|
||||
@@ -235,8 +238,7 @@ const BandoEdit = () => {
|
||||
|
||||
if (bandoId === 0) {
|
||||
setData({
|
||||
status: 'draft',
|
||||
name: ''
|
||||
status: null
|
||||
});
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
|
||||
@@ -293,7 +295,7 @@ const BandoEdit = () => {
|
||||
? <Steps
|
||||
model={stepItems}
|
||||
activeIndex={activeStep}
|
||||
readOnly={false}/>
|
||||
readOnly={isNil(data.status)}/>
|
||||
: null}
|
||||
<BlockingOverlay shouldDisplay={isAsyncRequest}/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user