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 { useDeleteExpense } from '@/hooks/query';
import { compose } from '@/utils'; import { compose } from '@/utils';
import { DRAWERS } from '@/constants/drawers'; import { DRAWERS } from '@/constants/drawers';
import { handleDeleteErrors } from './_utils';
/** /**
* Expense delete alert. * Expense delete alert.
@@ -51,16 +52,7 @@ function ExpenseDeleteAlert({
data: { errors }, data: { errors },
}, },
}) => { }) => {
if ( handleDeleteErrors(errors);
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',
),
});
}
}, },
) )
.finally(() => { .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.',
});
}
};

View File

@@ -11,6 +11,7 @@ import withDrawerActions from '@/containers/Drawer/withDrawerActions';
import { compose } from '@/utils'; import { compose } from '@/utils';
import { DRAWERS } from '@/constants/drawers'; import { DRAWERS } from '@/constants/drawers';
import { handleDeleteErrors } from './_utils';
/** /**
* Journal delete alert. * Journal delete alert.
@@ -48,9 +49,16 @@ function JournalDeleteAlert({
closeAlert(name); closeAlert(name);
closeDrawer(DRAWERS.JOURNAL_DETAILS); closeDrawer(DRAWERS.JOURNAL_DETAILS);
}) })
.catch(() => { .catch(
({
response: {
data: { errors },
},
}) => {
handleDeleteErrors(errors);
closeAlert(name); closeAlert(name);
}); },
);
}; };
return ( return (

View File

@@ -0,0 +1,11 @@
import { AppToaster } from '@/components';
import { Intent } from '@blueprintjs/core';
export const handleDeleteErrors = (errors: any) => {
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.',
});
}
};

View File

@@ -12,6 +12,7 @@ import { useDeletePaymentMade } from '@/hooks/query';
import { compose } from '@/utils'; import { compose } from '@/utils';
import { DRAWERS } from '@/constants/drawers'; import { DRAWERS } from '@/constants/drawers';
import { handleDeleteErrors } from './_utils';
/** /**
* Payment made delete alert. * Payment made delete alert.
@@ -47,6 +48,15 @@ function PaymentMadeDeleteAlert({
}); });
closeDrawer(DRAWERS.PAYMENT_MADE_DETAILS); closeDrawer(DRAWERS.PAYMENT_MADE_DETAILS);
}) })
.catch(
({
response: {
data: { errors },
},
}) => {
handleDeleteErrors(errors);
},
)
.finally(() => { .finally(() => {
closeAlert(name); closeAlert(name);
}); });

View File

@@ -0,0 +1,11 @@
import { AppToaster } from '@/components';
import { Intent } from '@blueprintjs/core';
export const handleDeleteErrors = (errors: any) => {
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.',
});
}
};

View File

@@ -14,6 +14,7 @@ import withAlertStoreConnect from '@/containers/Alert/withAlertStoreConnect';
import withAlertActions from '@/containers/Alert/withAlertActions'; import withAlertActions from '@/containers/Alert/withAlertActions';
import withDrawerActions from '@/containers/Drawer/withDrawerActions'; import withDrawerActions from '@/containers/Drawer/withDrawerActions';
import { handleDeleteErrors } from './_utils';
import { compose } from '@/utils'; import { compose } from '@/utils';
import { DRAWERS } from '@/constants/drawers'; import { DRAWERS } from '@/constants/drawers';
@@ -53,7 +54,15 @@ function PaymentReceiveDeleteAlert({
}); });
closeDrawer(DRAWERS.PAYMENT_RECEIVE_DETAILS); closeDrawer(DRAWERS.PAYMENT_RECEIVE_DETAILS);
}) })
.catch(() => {}) .catch(
({
response: {
data: { errors },
},
}) => {
handleDeleteErrors(errors);
},
)
.finally(() => { .finally(() => {
closeAlert(name); closeAlert(name);
}); });

View File

@@ -0,0 +1,11 @@
import { Intent } from '@blueprintjs/core';
import { AppToaster } from '@/components';
export const handleDeleteErrors = (errors: any) => {
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.',
});
}
};

View File

@@ -117,6 +117,12 @@ export const handleDeleteErrors = (errors) => {
intent: Intent.DANGER, intent: Intent.DANGER,
}); });
} }
if (errors.find((e) => e.type === 'CANNOT_DELETE_TRANSACTION_MATCHED')) {
AppToaster.show({
intent: Intent.DANGER,
message: 'Cannot delete a transaction matched with a bank transaction.',
});
}
}; };
export function ActionsMenu({ export function ActionsMenu({