From 545a66282552761b943fbb183fd2753e213d3614 Mon Sep 17 00:00:00 2001 From: elforjani3 Date: Wed, 24 Mar 2021 15:24:46 +0200 Subject: [PATCH] fix(bills) : catch error message. --- .../Alerts/Bills/BillDeleteAlert.js | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/client/src/containers/Alerts/Bills/BillDeleteAlert.js b/client/src/containers/Alerts/Bills/BillDeleteAlert.js index 5300c1c76..7ec6085a5 100644 --- a/client/src/containers/Alerts/Bills/BillDeleteAlert.js +++ b/client/src/containers/Alerts/Bills/BillDeleteAlert.js @@ -6,6 +6,7 @@ import { AppToaster } from 'components'; import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect'; import withAlertActions from 'containers/Alert/withAlertActions'; +import { handleDeleteErrors } from 'containers/Purchases/Bills/BillForm/utils'; import { useDeleteBill } from 'hooks/query'; import { compose } from 'utils'; @@ -32,15 +33,27 @@ function BillDeleteAlert({ // Handle confirm delete invoice const handleConfirmBillDelete = () => { - deleteBillMutate(billId).then(() => { - AppToaster.show({ - message: formatMessage({ - id: 'the_bill_has_been_deleted_successfully', - }), - intent: Intent.SUCCESS, + deleteBillMutate(billId) + .then(() => { + AppToaster.show({ + message: formatMessage({ + id: 'the_bill_has_been_deleted_successfully', + }), + intent: Intent.SUCCESS, + }); + }) + .catch( + ({ + response: { + data: { errors }, + }, + }) => { + handleDeleteErrors(errors); + }, + ) + .finally(() => { + closeAlert(name); }); - closeAlert(name); - }); }; return (