fix : handle errors message in sale invoice

This commit is contained in:
elforjani3
2021-01-02 13:43:40 +02:00
parent db70d04743
commit 792c96c344

View File

@@ -78,17 +78,36 @@ function InvoiceList({
setDeleteInvoice(false);
}, [setDeleteInvoice]);
// handleConfirm delete invoice
const handleConfirmInvoiceDelete = useCallback(() => {
requestDeleteInvoice(deleteInvoice.id).then(() => {
const handleDeleteErrors = (errors) => {
if (
errors.find(
(error) => error.type === 'INVOICE_HAS_ASSOCIATED_PAYMENT_ENTRIES',
)
) {
AppToaster.show({
message: formatMessage({
id: 'the_invocie_has_been_successfully_deleted',
id: 'the_invoice_cannot_be_deleted',
}),
intent: Intent.SUCCESS,
intent: Intent.DANGER,
});
}
};
// handleConfirm delete invoice
const handleConfirmInvoiceDelete = useCallback(() => {
requestDeleteInvoice(deleteInvoice.id)
.then(() => {
AppToaster.show({
message: formatMessage({
id: 'the_invocie_has_been_successfully_deleted',
}),
intent: Intent.SUCCESS,
});
})
.catch((errors) => {
handleDeleteErrors(errors);
setDeleteInvoice(false);
});
setDeleteInvoice(false);
});
}, [deleteInvoice, requestDeleteInvoice, formatMessage]);
// Handle cancel/confirm invoice deliver.