fix(vendor): catch error message.

This commit is contained in:
elforjani3
2021-03-21 18:20:48 +02:00
parent ad50da4214
commit 27670d51ed
3 changed files with 27 additions and 8 deletions

View File

@@ -6,7 +6,7 @@ import {
} from 'react-intl';
import { Intent, Alert } from '@blueprintjs/core';
import { AppToaster } from 'components';
import { transformErrors } from 'containers/Customers/utils';
import { transformErrors } from 'containers/Vendors/utils';
import { useDeleteVendor } from 'hooks/query';
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
@@ -28,10 +28,7 @@ function VendorDeleteAlert({
closeAlert,
}) {
const { formatMessage } = useIntl();
const {
mutateAsync: deleteVendorMutate,
isLoading
} = useDeleteVendor();
const { mutateAsync: deleteVendorMutate, isLoading } = useDeleteVendor();
// Handle cancel delete the vendor.
const handleCancelDeleteAlert = () => {
@@ -49,9 +46,15 @@ function VendorDeleteAlert({
intent: Intent.SUCCESS,
});
})
.catch((errors) => {
transformErrors(errors);
})
.catch(
({
response: {
data: { errors },
},
}) => {
transformErrors(errors);
},
)
.finally(() => {
closeAlert(name);
});

View 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,
});
}
};