handle Errors message api

This commit is contained in:
elforjani3
2020-10-28 14:58:56 +02:00
parent 6e64b5e04a
commit 23d840be4f
9 changed files with 140 additions and 60 deletions

View File

@@ -24,7 +24,7 @@ import withBillDetail from './withBillDetail';
import { AppToaster } from 'components';
import useMedia from 'hooks/useMedia';
import { ERROR } from 'common/errors';
import { compose, repeatValue } from 'utils';
const MIN_LINES_NUMBER = 5;
@@ -137,7 +137,6 @@ function BillForm({
[],
);
const defaultInitialValues = useMemo(
() => ({
vendor_id: '',
@@ -192,6 +191,16 @@ function BillForm({
: [];
}, [bill]);
const handleErrors = (errors, { setErrors }) => {
if (errors.some((e) => e.type === ERROR.BILL_NUMBER_EXISTS)) {
setErrors({
bill_number: formatMessage({
id: 'bill_number_exists',
}),
});
}
};
const formik = useFormik({
// enableReinitialize: true,
validationSchema,
@@ -222,7 +231,8 @@ function BillForm({
saveBillSubmit({ action: 'update', ...payload });
resetForm();
})
.catch((error) => {
.catch((errors) => {
handleErrors(errors, { setErrors });
setSubmitting(false);
});
} else {
@@ -240,6 +250,7 @@ function BillForm({
resetForm();
})
.catch((errors) => {
handleErrors(errors, { setErrors });
setSubmitting(false);
});
}