fix(server): Handle the delete error when the matched transaction

This commit is contained in:
Ahmed Bouhuolia
2024-06-29 10:30:03 +02:00
parent 978ce6c441
commit cb1f587637
9 changed files with 92 additions and 14 deletions

View File

@@ -11,6 +11,7 @@ import withDrawerActions from '@/containers/Drawer/withDrawerActions';
import { useDeleteExpense } from '@/hooks/query';
import { compose } from '@/utils';
import { DRAWERS } from '@/constants/drawers';
import { handleDeleteErrors } from './_utils';
/**
* Expense delete alert.
@@ -51,16 +52,7 @@ function ExpenseDeleteAlert({
data: { errors },
},
}) => {
if (
errors.find((e) => e.type === 'EXPENSE_HAS_ASSOCIATED_LANDED_COST')
) {
AppToaster.show({
intent: Intent.DANGER,
message: intl.get(
'couldn_t_delete_expense_transaction_has_associated_located_landed_cost_transaction',
),
});
}
handleDeleteErrors(errors);
},
)
.finally(() => {

View File

@@ -0,0 +1,20 @@
import { Intent } from '@blueprintjs/core';
import intl from 'react-intl-universal';
import { AppToaster } from '@/components';
export const handleDeleteErrors = (errors: any) => {
if (errors.find((e: any) => e.type === 'EXPENSE_HAS_ASSOCIATED_LANDED_COST')) {
AppToaster.show({
intent: Intent.DANGER,
message: intl.get(
'couldn_t_delete_expense_transaction_has_associated_located_landed_cost_transaction',
),
});
}
if (errors.find((e: any) => e.type === 'CANNOT_DELETE_TRANSACTION_MATCHED')) {
AppToaster.show({
intent: Intent.DANGER,
message: 'Cannot delete a transaction matched with a bank transaction.',
});
}
};