mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
feat(warehouse & Branch): handle error.
This commit is contained in:
@@ -5,6 +5,7 @@ import { Intent, Alert } from '@blueprintjs/core';
|
||||
import { AppToaster } from 'components';
|
||||
|
||||
import { useDeleteBranch } from 'hooks/query';
|
||||
import { handleDeleteErrors } from '../../Preferences/Branches/utils';
|
||||
|
||||
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
|
||||
import withAlertActions from 'containers/Alert/withAlertActions';
|
||||
@@ -24,7 +25,6 @@ function BranchDeleteAlert({
|
||||
// #withAlertActions
|
||||
closeAlert,
|
||||
}) {
|
||||
|
||||
const { mutateAsync: deleteBranch, isLoading } = useDeleteBranch();
|
||||
|
||||
// Handle cancel delete alert.
|
||||
@@ -46,7 +46,9 @@ function BranchDeleteAlert({
|
||||
response: {
|
||||
data: { errors },
|
||||
},
|
||||
}) => {},
|
||||
}) => {
|
||||
handleDeleteErrors(errors);
|
||||
},
|
||||
)
|
||||
.finally(() => {
|
||||
closeAlert(name);
|
||||
|
||||
@@ -4,6 +4,7 @@ import { FormattedMessage as T, FormattedHTMLMessage } from 'components';
|
||||
import { Intent, Alert } from '@blueprintjs/core';
|
||||
import { AppToaster } from 'components';
|
||||
import { useDeleteWarehouse } from 'hooks/query';
|
||||
import { handleDeleteErrors } from '../../Preferences/Warehouses/utils';
|
||||
|
||||
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
|
||||
import withAlertActions from 'containers/Alert/withAlertActions';
|
||||
@@ -46,7 +47,9 @@ function WarehouseDeleteAlert({
|
||||
response: {
|
||||
data: { errors },
|
||||
},
|
||||
}) => {},
|
||||
}) => {
|
||||
handleDeleteErrors(errors);
|
||||
},
|
||||
)
|
||||
.finally(() => {
|
||||
closeAlert(name);
|
||||
|
||||
15
src/containers/Preferences/Branches/utils.js
Normal file
15
src/containers/Preferences/Branches/utils.js
Normal file
@@ -0,0 +1,15 @@
|
||||
import intl from 'react-intl-universal';
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
import { AppToaster } from 'components';
|
||||
|
||||
/**
|
||||
* Handle delete errors.
|
||||
*/
|
||||
export const handleDeleteErrors = (errors) => {
|
||||
if (errors.find((error) => error.type === 'COULD_NOT_DELETE_ONLY_BRANCH')) {
|
||||
AppToaster.show({
|
||||
message: intl.get('branch.error.could_not_delete_only_branch'),
|
||||
intent: Intent.DANGER,
|
||||
});
|
||||
}
|
||||
};
|
||||
17
src/containers/Preferences/Warehouses/utils.js
Normal file
17
src/containers/Preferences/Warehouses/utils.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import intl from 'react-intl-universal';
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
import { AppToaster } from 'components';
|
||||
|
||||
/**
|
||||
* Handle delete errors.
|
||||
*/
|
||||
export const handleDeleteErrors = (errors) => {
|
||||
if (
|
||||
errors.find((error) => error.type === 'COULD_NOT_DELETE_ONLY_WAERHOUSE')
|
||||
) {
|
||||
AppToaster.show({
|
||||
message: intl.get('warehouse.error.could_not_delete_only_waerhouse'),
|
||||
intent: Intent.DANGER,
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user