mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 14:50:32 +00:00
fix(vendor): catch error message.
This commit is contained in:
@@ -6,7 +6,7 @@ import {
|
|||||||
} from 'react-intl';
|
} from 'react-intl';
|
||||||
import { Intent, Alert } from '@blueprintjs/core';
|
import { Intent, Alert } from '@blueprintjs/core';
|
||||||
import { AppToaster } from 'components';
|
import { AppToaster } from 'components';
|
||||||
import { transformErrors } from 'containers/Customers/utils';
|
import { transformErrors } from 'containers/Vendors/utils';
|
||||||
import { useDeleteVendor } from 'hooks/query';
|
import { useDeleteVendor } from 'hooks/query';
|
||||||
|
|
||||||
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
|
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
|
||||||
@@ -28,10 +28,7 @@ function VendorDeleteAlert({
|
|||||||
closeAlert,
|
closeAlert,
|
||||||
}) {
|
}) {
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
const {
|
const { mutateAsync: deleteVendorMutate, isLoading } = useDeleteVendor();
|
||||||
mutateAsync: deleteVendorMutate,
|
|
||||||
isLoading
|
|
||||||
} = useDeleteVendor();
|
|
||||||
|
|
||||||
// Handle cancel delete the vendor.
|
// Handle cancel delete the vendor.
|
||||||
const handleCancelDeleteAlert = () => {
|
const handleCancelDeleteAlert = () => {
|
||||||
@@ -49,9 +46,15 @@ function VendorDeleteAlert({
|
|||||||
intent: Intent.SUCCESS,
|
intent: Intent.SUCCESS,
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((errors) => {
|
.catch(
|
||||||
transformErrors(errors);
|
({
|
||||||
})
|
response: {
|
||||||
|
data: { errors },
|
||||||
|
},
|
||||||
|
}) => {
|
||||||
|
transformErrors(errors);
|
||||||
|
},
|
||||||
|
)
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
closeAlert(name);
|
closeAlert(name);
|
||||||
});
|
});
|
||||||
|
|||||||
15
client/src/containers/Vendors/utils.js
Normal file
15
client/src/containers/Vendors/utils.js
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Intent } from '@blueprintjs/core';
|
||||||
|
import { AppToaster } from 'components';
|
||||||
|
import { formatMessage } from 'services/intl';
|
||||||
|
|
||||||
|
export const transformErrors = (errors) => {
|
||||||
|
if (errors.find((error) => error.type === 'VENDOR.HAS.ASSOCIATED.BILLS')) {
|
||||||
|
AppToaster.show({
|
||||||
|
message: formatMessage({
|
||||||
|
id: 'cannot_delete_vendor_that_has_associated_purchase_bills',
|
||||||
|
}),
|
||||||
|
intent: Intent.DANGER,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1020,4 +1020,5 @@ export default {
|
|||||||
cannot_change_item_type_to_inventory_with_item_has_associated_transactions:
|
cannot_change_item_type_to_inventory_with_item_has_associated_transactions:
|
||||||
'Cannot change item type to inventory with item has associated transactions.',
|
'Cannot change item type to inventory with item has associated transactions.',
|
||||||
work_phone: 'Work Phone',
|
work_phone: 'Work Phone',
|
||||||
|
cannot_delete_vendor_that_has_associated_purchase_bills:'Cannot delete vendor that has associated purchase bills.'
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user