From 16ce29cafa3182206177b84ad71762771d6e5311 Mon Sep 17 00:00:00 2001 From: elforjani3 Date: Fri, 19 Mar 2021 19:10:26 +0200 Subject: [PATCH] refactoring(bill & item) : catch error message. --- client/src/containers/Items/utils.js | 13 +++++++++++++ .../Purchases/Bills/BillForm/utils.js | 19 ++++++++++++++++++- client/src/lang/en/index.js | 4 ++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/client/src/containers/Items/utils.js b/client/src/containers/Items/utils.js index c94bfa919..56d9f7b9b 100644 --- a/client/src/containers/Items/utils.js +++ b/client/src/containers/Items/utils.js @@ -37,4 +37,17 @@ export const handleDeleteErrors = (errors) => { intent: Intent.DANGER, }); } + if ( + errors.find( + (error) => error.type === 'TYPE_CANNOT_CHANGE_WITH_ITEM_HAS_TRANSACTIONS', + ) + ) { + AppToaster.show({ + message: formatMessage({ + id: + 'cannot_change_item_type_to_inventory_with_item_has_associated_transactions', + }), + intent: Intent.DANGER, + }); + } }; diff --git a/client/src/containers/Purchases/Bills/BillForm/utils.js b/client/src/containers/Purchases/Bills/BillForm/utils.js index 06256c9e5..2658c3ec4 100644 --- a/client/src/containers/Purchases/Bills/BillForm/utils.js +++ b/client/src/containers/Purchases/Bills/BillForm/utils.js @@ -1,4 +1,7 @@ import moment from 'moment'; +import { formatMessage } from 'services/intl'; +import { Intent } from '@blueprintjs/core'; +import { AppToaster } from 'components'; import { transformToForm, repeatValue } from 'utils'; export const MIN_LINES_NUMBER = 4; @@ -36,4 +39,18 @@ export const transformToEditForm = (bill) => { ), ], }; -} \ No newline at end of file +}; + +// handle delete errors. +export const handleDeleteErrors = (errors) => { + if ( + errors.find((error) => error.type === 'BILL_HAS_ASSOCIATED_PAYMENT_ENTRIES') + ) { + AppToaster.show({ + message: formatMessage({ + id: 'cannot_delete_bill_that_has_payment_transactions', + }), + intent: Intent.DANGER, + }); + } +}; diff --git a/client/src/lang/en/index.js b/client/src/lang/en/index.js index c0e9d7c0e..90f7a3fb4 100644 --- a/client/src/lang/en/index.js +++ b/client/src/lang/en/index.js @@ -1015,4 +1015,8 @@ export default { deposit_customer_account: 'Deposit customer account', withdrawal_customer_account: 'Withdrawal customer account', vendor_advance_deposit: 'Vendor advance deposit', + cannot_delete_bill_that_has_payment_transactions: + 'Cannot delete bill that has associated payment transactions.', + cannot_change_item_type_to_inventory_with_item_has_associated_transactions: + 'Cannot change item type to inventory with item has associated transactions.', };