diff --git a/src/containers/Alerts/CreditNotes/CreditNoteDeleteAlert.js b/src/containers/Alerts/CreditNotes/CreditNoteDeleteAlert.js index be664372a..5c70206cd 100644 --- a/src/containers/Alerts/CreditNotes/CreditNoteDeleteAlert.js +++ b/src/containers/Alerts/CreditNotes/CreditNoteDeleteAlert.js @@ -9,6 +9,7 @@ import withAlertActions from 'containers/Alert/withAlertActions'; import withDrawerActions from 'containers/Drawer/withDrawerActions'; import { useDeleteCreditNote } from 'hooks/query'; +import { handleDeleteErrors } from '../../Sales/CreditNotes/CreditNotesLanding/utils'; import { compose } from 'utils'; /** @@ -48,7 +49,9 @@ function CreditNoteDeleteAlert({ response: { data: { errors }, }, - }) => {}, + }) => { + handleDeleteErrors(errors); + }, ) .finally(() => { closeAlert(name); diff --git a/src/containers/Sales/CreditNotes/CreditNotesLanding/utils.js b/src/containers/Sales/CreditNotes/CreditNotesLanding/utils.js new file mode 100644 index 000000000..9d94edad5 --- /dev/null +++ b/src/containers/Sales/CreditNotes/CreditNotesLanding/utils.js @@ -0,0 +1,29 @@ +import React from 'react'; +import intl from 'react-intl-universal'; +import { Intent } from '@blueprintjs/core'; +import { AppToaster } from 'components'; + +export const handleDeleteErrors = (errors) => { + if ( + errors.find((error) => error.type === 'CREDIT_NOTE_HAS_APPLIED_INVOICES') + ) { + AppToaster.show({ + message: intl.get( + 'credit_note.error.you_couldn_t_delete_credit_note_that_has_associated_invoice', + ), + intent: Intent.DANGER, + }); + } + if ( + errors.find( + (error) => error.type === 'CREDIT_NOTE_HAS_REFUNDS_TRANSACTIONS', + ) + ) { + AppToaster.show({ + message: intl.get( + 'credit_note.error.you_couldn_t_delete_credit_note_that_has_associated_refund', + ), + intent: Intent.DANGER, + }); + } +}; diff --git a/src/containers/Sales/Invoices/InvoicesLanding/components.js b/src/containers/Sales/Invoices/InvoicesLanding/components.js index 68e68ae89..35d373136 100644 --- a/src/containers/Sales/Invoices/InvoicesLanding/components.js +++ b/src/containers/Sales/Invoices/InvoicesLanding/components.js @@ -99,6 +99,18 @@ export const handleDeleteErrors = (errors) => { intent: Intent.DANGER, }); } + if ( + errors.find( + (error) => error.type === 'SALE_INVOICE_HAS_APPLIED_TO_CREDIT_NOTES', + ) + ) { + AppToaster.show({ + message: intl.get( + 'invoices.error.you_couldn_t_delete_sale_invoice_that_has_reconciled', + ), + intent: Intent.DANGER, + }); + } }; export function ActionsMenu({