Fix : Customers.

This commit is contained in:
elforjani3
2020-11-11 17:27:44 +02:00
parent 77aeaf2c60
commit cda856ef8d
4 changed files with 86 additions and 71 deletions

View File

@@ -87,17 +87,33 @@ function CustomersList({
setDeleteCustomer(false);
}, [setDeleteCustomer]);
// handle confirm delete customer.
const handleConfirmDeleteCustomer = useCallback(() => {
requestDeleteCustomer(deleteCustomer.id).then(() => {
const transformErrors = (errors) => {
if (errors.some((e) => e.type === 'CUSTOMER.HAS.SALES_INVOICES')) {
AppToaster.show({
message: formatMessage({
id: 'the_customer_has_been_successfully_deleted',
id: 'customer_has_sales_invoices',
}),
intent: Intent.SUCCESS,
intent: Intent.DANGER,
});
}
};
// handle confirm delete customer.
const handleConfirmDeleteCustomer = useCallback(() => {
requestDeleteCustomer(deleteCustomer.id)
.then(() => {
setDeleteCustomer(false);
AppToaster.show({
message: formatMessage({
id: 'the_customer_has_been_successfully_deleted',
}),
intent: Intent.SUCCESS,
});
})
.catch((errors) => {
setDeleteCustomer(false);
transformErrors(errors);
});
setDeleteCustomer(false);
});
}, [requestDeleteCustomer, deleteCustomer, formatMessage]);
// Handle fetch data table.