- added registartion page;
- implemented validation helper-functions; - fixed form fields datepicker and datepicker range; - updated routes logic; - fixed FAQ items editing/submission;
This commit is contained in:
@@ -4,6 +4,7 @@ import { useNavigate } from 'react-router-dom';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { is, isEmpty, isNil } from 'ramda';
|
||||
import { klona } from 'klona';
|
||||
import { TZDate } from '@date-fns/tz';
|
||||
|
||||
// components
|
||||
import FormField from '../../../../components/FormField';
|
||||
@@ -20,7 +21,7 @@ import LookupdataService from '../../../../service/lookupdata-service';
|
||||
// store
|
||||
import { storeSet } from '../../../../store';
|
||||
|
||||
const BandoEditFormStep2 = forwardRef(function ({ initialData, getFormErrors }, ref) {
|
||||
const BandoEditFormStep2 = forwardRef(function ({ initialData, getFormErrors, status }, ref) {
|
||||
const navigate = useNavigate();
|
||||
const [criteriaOptions, setCriteriaOptions] = useState([]);
|
||||
const [checklistOptions, setChecklistOptions] = useState([]);
|
||||
@@ -33,8 +34,7 @@ const BandoEditFormStep2 = forwardRef(function ({ initialData, getFormErrors },
|
||||
register,
|
||||
trigger,
|
||||
getValues,
|
||||
clearErrors,
|
||||
reset
|
||||
clearErrors
|
||||
} = useForm({
|
||||
defaultValues: useMemo(() => {
|
||||
return formInitialData;
|
||||
@@ -46,7 +46,14 @@ const BandoEditFormStep2 = forwardRef(function ({ initialData, getFormErrors },
|
||||
|
||||
const onSubmit = (formData) => {
|
||||
if (!isNil(formData.dates) && formData.dates.length) {
|
||||
formData.dates = formData.dates.map(v => is(String, v) ? v : v.toISOString());
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const forSubmit = Object.keys(formData).reduce((acc, cur) => {
|
||||
@@ -56,10 +63,12 @@ const BandoEditFormStep2 = forwardRef(function ({ initialData, getFormErrors },
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
storeSet.main.setAsyncRequest();
|
||||
BandoService.updateBandoStep2(formData.id, forSubmit, createCallback, errCreateCallback);
|
||||
};
|
||||
|
||||
const createCallback = (data) => {
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
if (data.status === 'SUCCESS') {
|
||||
toast.current.show({
|
||||
severity: 'success',
|
||||
@@ -68,11 +77,11 @@ const BandoEditFormStep2 = forwardRef(function ({ initialData, getFormErrors },
|
||||
});
|
||||
const newFormData = {...formInitialData, ...data.data};
|
||||
setFormInitialData(newFormData);
|
||||
reset(newFormData);
|
||||
}
|
||||
}
|
||||
|
||||
const errCreateCallback = (data) => {
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
console.log('errCreateCallback', data);
|
||||
}
|
||||
|
||||
@@ -109,11 +118,11 @@ const BandoEditFormStep2 = forwardRef(function ({ initialData, getFormErrors },
|
||||
}
|
||||
|
||||
const openPreview = () => {
|
||||
navigate(`/tenders/${values.id}/preview`);
|
||||
navigate(`/bandi/${values.id}/preview`);
|
||||
}
|
||||
|
||||
const openPreviewEvaluation = () => {
|
||||
navigate(`/tenders/${values.id}/preview-evaluation`);
|
||||
navigate(`/bandi/${values.id}/preview-evaluation`);
|
||||
}
|
||||
|
||||
useImperativeHandle(
|
||||
@@ -142,7 +151,7 @@ const BandoEditFormStep2 = forwardRef(function ({ initialData, getFormErrors },
|
||||
if (!isNil(formInitialData.dates) && formInitialData.dates.length) {
|
||||
newFormData.dates = formInitialData.dates.map(v => is(String, v) ? new Date(v) : (v ? v : ''));
|
||||
}
|
||||
reset(newFormData);
|
||||
Object.keys(newFormData).map(v => setValue(v, newFormData[v]));
|
||||
}, [formInitialData]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -154,11 +163,16 @@ const BandoEditFormStep2 = forwardRef(function ({ initialData, getFormErrors },
|
||||
}
|
||||
}, []);
|
||||
|
||||
const shouldDisableField = () => {
|
||||
return values.status === 'PUBLISH'
|
||||
}
|
||||
|
||||
return (
|
||||
<form className="appForm" onSubmit={handleSubmit(onSubmit)}>
|
||||
<UnsavedChangesDetector getValuesFn={getValues}/>
|
||||
<FormFieldRepeaterCriteria
|
||||
data={values}
|
||||
disabled={shouldDisableField()}
|
||||
setDataFn={setValue}
|
||||
fieldName="criteria"
|
||||
options={criteriaOptions}
|
||||
@@ -177,6 +191,7 @@ const BandoEditFormStep2 = forwardRef(function ({ initialData, getFormErrors },
|
||||
|
||||
<FormField
|
||||
type="fileuploadasync"
|
||||
disabled={shouldDisableField()}
|
||||
setDataFn={setValue}
|
||||
fieldName="docs"
|
||||
label={__('Documentazione', 'gepafin')}
|
||||
@@ -195,6 +210,7 @@ const BandoEditFormStep2 = forwardRef(function ({ initialData, getFormErrors },
|
||||
|
||||
<FormField
|
||||
type="fileuploadasync"
|
||||
disabled={shouldDisableField()}
|
||||
setDataFn={setValue}
|
||||
fieldName="images"
|
||||
label={__('Immagine del Bando', 'gepafin')}
|
||||
@@ -209,6 +225,7 @@ const BandoEditFormStep2 = forwardRef(function ({ initialData, getFormErrors },
|
||||
|
||||
<FormFieldRepeater
|
||||
data={values['checkList']}
|
||||
disabled={shouldDisableField()}
|
||||
setDataFn={setValue}
|
||||
fieldName="checkList"
|
||||
options={checklistOptions}
|
||||
@@ -234,6 +251,7 @@ const BandoEditFormStep2 = forwardRef(function ({ initialData, getFormErrors },
|
||||
<Toast ref={toast} />
|
||||
<BandoEditFormActions
|
||||
id={values.id}
|
||||
status={status}
|
||||
openPreview={openPreview}
|
||||
openPreviewEvaluation={openPreviewEvaluation}/>
|
||||
</form>
|
||||
|
||||
Reference in New Issue
Block a user