diff --git a/client/src/containers/Customers/CustomersList.js b/client/src/containers/Customers/CustomersList.js index 9c090ff86..34da5edde 100644 --- a/client/src/containers/Customers/CustomersList.js +++ b/client/src/containers/Customers/CustomersList.js @@ -59,7 +59,7 @@ function CustomersList({ ['resource-views', 'customers'], (key, resourceName) => requestFetchResourceViews(resourceName), ); - + const fetchCustomers = useQuery( ['customers-table', customersTableQuery], (key, query) => requestFetchCustomers({ ...query }), @@ -146,6 +146,20 @@ function CustomersList({ setBulkDelete(false); }, []); + const transformApiErrors = (errors) => { + if ( + errors.find( + (error) => error.type === 'SOME.CUSTOMERS.HAVE.SALES_INVOICES', + ) + ) { + AppToaster.show({ + message: formatMessage({ + id: 'some_customers_have_sales_invoices', + }), + intent: Intent.DANGER, + }); + } + }; // Handle confirm customers bulk delete. const handleConfirmBulkDelete = useCallback(() => { requestDeleteBulkCustomers(bulkDelete) @@ -158,7 +172,8 @@ function CustomersList({ intent: Intent.SUCCESS, }); }) - .catch((error) => { + .catch((errors) => { + transformApiErrors(errors); setBulkDelete(false); }); }, [requestDeleteBulkCustomers, bulkDelete, formatMessage]); diff --git a/client/src/lang/en/index.js b/client/src/lang/en/index.js index 67c23222b..9e241c1dc 100644 --- a/client/src/lang/en/index.js +++ b/client/src/lang/en/index.js @@ -938,5 +938,6 @@ export default { no_results: 'No results.', the_invoice_cannot_be_deleted: 'The invoice cannot be deleted cause has associated payment transactions', - category_name_exists:'Category name exists' - }; + category_name_exists: 'Category name exists', + some_customers_have_sales_invoices: 'Some customers have sales invoices', +};