mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
fix(server): Handle the delete error when the matched transaction
This commit is contained in:
@@ -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(() => {
|
||||
|
||||
20
packages/webapp/src/containers/Alerts/Expenses/_utils.ts
Normal file
20
packages/webapp/src/containers/Alerts/Expenses/_utils.ts
Normal 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.',
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -11,6 +11,7 @@ import withDrawerActions from '@/containers/Drawer/withDrawerActions';
|
||||
|
||||
import { compose } from '@/utils';
|
||||
import { DRAWERS } from '@/constants/drawers';
|
||||
import { handleDeleteErrors } from './_utils';
|
||||
|
||||
/**
|
||||
* Journal delete alert.
|
||||
@@ -48,9 +49,16 @@ function JournalDeleteAlert({
|
||||
closeAlert(name);
|
||||
closeDrawer(DRAWERS.JOURNAL_DETAILS);
|
||||
})
|
||||
.catch(() => {
|
||||
closeAlert(name);
|
||||
});
|
||||
.catch(
|
||||
({
|
||||
response: {
|
||||
data: { errors },
|
||||
},
|
||||
}) => {
|
||||
handleDeleteErrors(errors);
|
||||
closeAlert(name);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -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.',
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -12,6 +12,7 @@ import { useDeletePaymentMade } from '@/hooks/query';
|
||||
|
||||
import { compose } from '@/utils';
|
||||
import { DRAWERS } from '@/constants/drawers';
|
||||
import { handleDeleteErrors } from './_utils';
|
||||
|
||||
/**
|
||||
* Payment made delete alert.
|
||||
@@ -47,6 +48,15 @@ function PaymentMadeDeleteAlert({
|
||||
});
|
||||
closeDrawer(DRAWERS.PAYMENT_MADE_DETAILS);
|
||||
})
|
||||
.catch(
|
||||
({
|
||||
response: {
|
||||
data: { errors },
|
||||
},
|
||||
}) => {
|
||||
handleDeleteErrors(errors);
|
||||
},
|
||||
)
|
||||
.finally(() => {
|
||||
closeAlert(name);
|
||||
});
|
||||
|
||||
11
packages/webapp/src/containers/Alerts/PaymentMades/_utils.ts
Normal file
11
packages/webapp/src/containers/Alerts/PaymentMades/_utils.ts
Normal 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.',
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -14,6 +14,7 @@ import withAlertStoreConnect from '@/containers/Alert/withAlertStoreConnect';
|
||||
import withAlertActions from '@/containers/Alert/withAlertActions';
|
||||
import withDrawerActions from '@/containers/Drawer/withDrawerActions';
|
||||
|
||||
import { handleDeleteErrors } from './_utils';
|
||||
import { compose } from '@/utils';
|
||||
import { DRAWERS } from '@/constants/drawers';
|
||||
|
||||
@@ -53,7 +54,15 @@ function PaymentReceiveDeleteAlert({
|
||||
});
|
||||
closeDrawer(DRAWERS.PAYMENT_RECEIVE_DETAILS);
|
||||
})
|
||||
.catch(() => {})
|
||||
.catch(
|
||||
({
|
||||
response: {
|
||||
data: { errors },
|
||||
},
|
||||
}) => {
|
||||
handleDeleteErrors(errors);
|
||||
},
|
||||
)
|
||||
.finally(() => {
|
||||
closeAlert(name);
|
||||
});
|
||||
|
||||
@@ -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.',
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -117,6 +117,12 @@ export const handleDeleteErrors = (errors) => {
|
||||
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({
|
||||
|
||||
Reference in New Issue
Block a user