mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-14 11:50:31 +00:00
feat(branch & warehouse): handle error.
This commit is contained in:
@@ -6,6 +6,7 @@ import { Intent } from '@blueprintjs/core';
|
||||
|
||||
import { AppToaster } from 'components';
|
||||
import { CreateBranchFormSchema } from './BranchForm.schema';
|
||||
import { transformErrors } from './utils';
|
||||
|
||||
import BranchFormContent from './BranchFormContent';
|
||||
import { useBranchFormContext } from './BranchFormProvider';
|
||||
@@ -28,13 +29,8 @@ function BranchForm({
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}) {
|
||||
const {
|
||||
dialogName,
|
||||
branch,
|
||||
branchId,
|
||||
createBranchMutate,
|
||||
editBranchMutate,
|
||||
} = useBranchFormContext();
|
||||
const { dialogName, branch, branchId, createBranchMutate, editBranchMutate } =
|
||||
useBranchFormContext();
|
||||
|
||||
// Initial form values.
|
||||
const initialValues = {
|
||||
@@ -63,6 +59,7 @@ function BranchForm({
|
||||
}) => {
|
||||
if (errors) {
|
||||
}
|
||||
transformErrors(errors, { setErrors });
|
||||
setSubmitting(false);
|
||||
};
|
||||
|
||||
|
||||
14
src/containers/Dialogs/BranchFormDialog/utils.js
Normal file
14
src/containers/Dialogs/BranchFormDialog/utils.js
Normal file
@@ -0,0 +1,14 @@
|
||||
import intl from 'react-intl-universal';
|
||||
|
||||
|
||||
/**
|
||||
* Transformes the response errors types.
|
||||
*/
|
||||
export const transformErrors = (errors, { setErrors }) => {
|
||||
|
||||
if (errors.find((error) => error.type === 'BRANCH_CODE_NOT_UNIQUE')) {
|
||||
setErrors({
|
||||
code: intl.get('branche.error.warehouse_code_not_unique'),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import { AppToaster } from 'components';
|
||||
import { CreateWarehouseFormSchema } from './WarehouseForm.schema';
|
||||
import { useWarehouseFormContext } from './WarehouseFormProvider';
|
||||
import WarehouseFormContent from './WarehouseFormContent';
|
||||
import { transformErrors } from './utils';
|
||||
|
||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||
import { compose, transformToForm } from 'utils';
|
||||
@@ -66,6 +67,8 @@ function WarehouseForm({
|
||||
}) => {
|
||||
if (errors) {
|
||||
}
|
||||
transformErrors(errors, { setErrors });
|
||||
|
||||
setSubmitting(false);
|
||||
};
|
||||
|
||||
|
||||
12
src/containers/Dialogs/WarehouseFormDialog/utils.js
Normal file
12
src/containers/Dialogs/WarehouseFormDialog/utils.js
Normal file
@@ -0,0 +1,12 @@
|
||||
import intl from 'react-intl-universal';
|
||||
|
||||
/**
|
||||
* Transformes the response errors types.
|
||||
*/
|
||||
export const transformErrors = (errors, { setErrors }) => {
|
||||
if (errors.find((error) => error.type === 'WAREHOUSE_CODE_NOT_UNIQUE')) {
|
||||
setErrors({
|
||||
code: intl.get('warehouse.error.warehouse_code_not_unique'),
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -1897,5 +1897,7 @@
|
||||
"vendor_opening_balance.label.opening_balance": "Opening balance",
|
||||
"vendor_opening_balance.label.opening_balance_at": "Opening balance at",
|
||||
"customer.label.opening_branch": "Opening Balance Branch",
|
||||
"vendor.label.opening_branch": "Opening Balance Branch"
|
||||
"vendor.label.opening_branch": "Opening Balance Branch",
|
||||
"warehouse.error.warehouse_code_not_unique":"Warehouse code not unique",
|
||||
"branche.error.warehouse_code_not_unique":"Branch code not unique"
|
||||
}
|
||||
Reference in New Issue
Block a user