fix: transform message error with customers.

This commit is contained in:
elforjani3
2021-01-02 15:07:51 +02:00
parent 3c0dc6f27a
commit a1c228a8a4
2 changed files with 20 additions and 4 deletions

View File

@@ -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]);

View File

@@ -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',
};