diff --git a/client/src/containers/Alerts/Expenses/ExpenseDeleteAlert.js b/client/src/containers/Alerts/Expenses/ExpenseDeleteAlert.js index b367fec84..f8604be99 100644 --- a/client/src/containers/Alerts/Expenses/ExpenseDeleteAlert.js +++ b/client/src/containers/Alerts/Expenses/ExpenseDeleteAlert.js @@ -21,11 +21,7 @@ function ExpenseDeleteAlert({ isOpen, payload: { expenseId }, }) { - - const { - mutateAsync: deleteExpenseMutate, - isLoading, - } = useDeleteExpense(); + const { mutateAsync: deleteExpenseMutate, isLoading } = useDeleteExpense(); // Handle cancel expense journal. const handleCancelExpenseDelete = () => { @@ -34,17 +30,34 @@ function ExpenseDeleteAlert({ // Handle confirm delete expense. const handleConfirmExpenseDelete = () => { - deleteExpenseMutate(expenseId).then(() => { - AppToaster.show({ - message: intl.get( - 'the_expense_has_been_deleted_successfully', - { number: expenseId }, - ), - intent: Intent.SUCCESS, - }); - }).finally(() => { - closeAlert('expense-delete'); - }); + deleteExpenseMutate(expenseId) + .then(() => { + AppToaster.show({ + message: intl.get('the_expense_has_been_deleted_successfully', { + number: expenseId, + }), + intent: Intent.SUCCESS, + }); + closeAlert('expense-delete'); + }) + .catch( + ({ + response: { + data: { errors }, + }, + }) => { + if ( + errors.find((e) => e.type === 'EXPENSE_HAS_ASSOCIATED_LANDED_COST') + ) { + AppToaster.show({ + intent: Intent.DANGER, + message: intl.get( + 'couldn_t_delete_expense_transaction_has_associated_located_landed_cost_transaction', + ), + }); + } + }, + ); }; return ( @@ -68,4 +81,4 @@ function ExpenseDeleteAlert({ export default compose( withAlertStoreConnect(), withAlertActions, -)(ExpenseDeleteAlert); \ No newline at end of file +)(ExpenseDeleteAlert); diff --git a/client/src/containers/Purchases/Bills/BillForm/utils.js b/client/src/containers/Purchases/Bills/BillForm/utils.js index 47ebec4a2..dba011cf7 100644 --- a/client/src/containers/Purchases/Bills/BillForm/utils.js +++ b/client/src/containers/Purchases/Bills/BillForm/utils.js @@ -51,4 +51,14 @@ export const handleDeleteErrors = (errors) => { intent: Intent.DANGER, }); } + if ( + errors.find((error) => error.type === 'BILL_HAS_ASSOCIATED_LANDED_COSTS') + ) { + AppToaster.show({ + message: intl.get( + 'cannot_delete_bill_that_has_associated_landed_cost_transactions', + ), + intent: Intent.DANGER, + }); + } }; diff --git a/client/src/lang/en/index.json b/client/src/lang/en/index.json index 1643a7891..6ad074587 100644 --- a/client/src/lang/en/index.json +++ b/client/src/lang/en/index.json @@ -1136,5 +1136,8 @@ "select_transaction":"Select transaction account", "details":"Details", "located_landed_cost":"Located Landed Cost", - "delete_transaction":"Delete transaction" + "delete_transaction":"Delete transaction", + "cannot_delete_bill_that_has_associated_landed_cost_transactions":"Cannot delete bill that has associated landed cost transactions.", + "couldn_t_delete_expense_transaction_has_associated_located_landed_cost_transaction":"Couldn't delete expense transaction has associated located landed cost transaction" + } \ No newline at end of file