mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 06:10:31 +00:00
feat: add delete reconcile & handle error.
This commit is contained in:
@@ -0,0 +1,83 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import intl from 'react-intl-universal';
|
||||||
|
import { FormattedMessage as T, FormattedHTMLMessage } from 'components';
|
||||||
|
import { Intent, Alert } from '@blueprintjs/core';
|
||||||
|
import { AppToaster } from 'components';
|
||||||
|
|
||||||
|
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
|
||||||
|
import withAlertActions from 'containers/Alert/withAlertActions';
|
||||||
|
import withDrawerActions from 'containers/Drawer/withDrawerActions';
|
||||||
|
|
||||||
|
import { useDeleteReconcileVendorCredit } from 'hooks/query';
|
||||||
|
import { compose } from 'utils';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reconcile vendor credit delete alert.
|
||||||
|
*/
|
||||||
|
function ReconcileVendorCreditDeleteAlert({
|
||||||
|
name,
|
||||||
|
|
||||||
|
// #withAlertStoreConnect
|
||||||
|
isOpen,
|
||||||
|
payload: { vendorCreditId },
|
||||||
|
|
||||||
|
// #withAlertActions
|
||||||
|
closeAlert,
|
||||||
|
|
||||||
|
// #withDrawerActions
|
||||||
|
closeDrawer,
|
||||||
|
}) {
|
||||||
|
const { isLoading, mutateAsync: deleteReconcileVendorCreditMutate } =
|
||||||
|
useDeleteReconcileVendorCredit();
|
||||||
|
|
||||||
|
// handle cancel delete credit note alert.
|
||||||
|
const handleCancelDeleteAlert = () => {
|
||||||
|
closeAlert(name);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleConfirmReconcileVendorCreditDelete = () => {
|
||||||
|
deleteReconcileVendorCreditMutate(vendorCreditId)
|
||||||
|
.then(() => {
|
||||||
|
AppToaster.show({
|
||||||
|
message: intl.get('reconcile_vendor_credit.alert.success_message'),
|
||||||
|
intent: Intent.SUCCESS,
|
||||||
|
});
|
||||||
|
// closeDrawer('vendor-credit-detail-drawer');
|
||||||
|
})
|
||||||
|
.catch(
|
||||||
|
({
|
||||||
|
response: {
|
||||||
|
data: { errors },
|
||||||
|
},
|
||||||
|
}) => {},
|
||||||
|
)
|
||||||
|
.finally(() => {
|
||||||
|
closeAlert(name);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Alert
|
||||||
|
cancelButtonText={<T id={'cancel'} />}
|
||||||
|
confirmButtonText={<T id={'delete'} />}
|
||||||
|
icon="trash"
|
||||||
|
intent={Intent.DANGER}
|
||||||
|
isOpen={isOpen}
|
||||||
|
onCancel={handleCancelDeleteAlert}
|
||||||
|
onConfirm={handleConfirmReconcileVendorCreditDelete}
|
||||||
|
loading={isLoading}
|
||||||
|
>
|
||||||
|
<p>
|
||||||
|
<FormattedHTMLMessage
|
||||||
|
id={'reconcile_vendor_credit.alert.once_you_delete_this_reconcile_vendor_credit'}
|
||||||
|
/>
|
||||||
|
</p>
|
||||||
|
</Alert>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default compose(
|
||||||
|
withAlertStoreConnect(),
|
||||||
|
withAlertActions,
|
||||||
|
withDrawerActions,
|
||||||
|
)(ReconcileVendorCreditDeleteAlert);
|
||||||
@@ -7,7 +7,7 @@ import { AppToaster } from 'components';
|
|||||||
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
|
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 '../../Purchases/CreditNotes/CreditNotesLanding/utils';
|
||||||
import { useDeleteVendorCredit } from 'hooks/query';
|
import { useDeleteVendorCredit } from 'hooks/query';
|
||||||
import { compose } from 'utils';
|
import { compose } from 'utils';
|
||||||
|
|
||||||
@@ -48,7 +48,9 @@ function VendorCreditDeleteAlert({
|
|||||||
response: {
|
response: {
|
||||||
data: { errors },
|
data: { errors },
|
||||||
},
|
},
|
||||||
}) => {},
|
}) => {
|
||||||
|
handleDeleteErrors(errors);
|
||||||
|
},
|
||||||
)
|
)
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
closeAlert(name);
|
closeAlert(name);
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { DataTable, Card } from 'components';
|
||||||
|
|
||||||
|
import '../../../../style/pages/RefundCreditNote/List.scss';
|
||||||
|
|
||||||
|
import withAlertsActions from 'containers/Alert/withAlertActions';
|
||||||
|
import { useVendorCreditDetailDrawerContext } from '../VendorCreditDetailDrawerProvider';
|
||||||
|
import {
|
||||||
|
useReconcileVendorCreditTransactionsTableColumns,
|
||||||
|
ActionsMenu,
|
||||||
|
} from './components';
|
||||||
|
import { compose } from 'utils';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reconcile vendor credit transactions table.
|
||||||
|
*/
|
||||||
|
function ReconcileVendorCreditTransactionsTable({
|
||||||
|
// #withAlertsActions
|
||||||
|
openAlert,
|
||||||
|
}) {
|
||||||
|
const columns = useReconcileVendorCreditTransactionsTableColumns();
|
||||||
|
|
||||||
|
const { reconcileVendorCredits } = useVendorCreditDetailDrawerContext();
|
||||||
|
|
||||||
|
// Handle delete reconile credit.
|
||||||
|
const handleDeleteReconcileVendorCredit = ({ id }) => {
|
||||||
|
openAlert('reconcile-vendor-delete', { vendorCreditId: id });
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card>
|
||||||
|
<DataTable
|
||||||
|
columns={columns}
|
||||||
|
data={reconcileVendorCredits}
|
||||||
|
ContextMenu={ActionsMenu}
|
||||||
|
payload={{
|
||||||
|
onDelete: handleDeleteReconcileVendorCredit,
|
||||||
|
}}
|
||||||
|
className={'datatable--refund-transactions'}
|
||||||
|
/>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default compose(withAlertsActions)(
|
||||||
|
ReconcileVendorCreditTransactionsTable,
|
||||||
|
);
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Intent, MenuItem, Menu } from '@blueprintjs/core';
|
||||||
|
import intl from 'react-intl-universal';
|
||||||
|
import { FormatDateCell, Icon } from 'components';
|
||||||
|
import { safeCallback } from 'utils';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Actions menu.
|
||||||
|
*/
|
||||||
|
export function ActionsMenu({ payload: { onDelete }, row: { original } }) {
|
||||||
|
return (
|
||||||
|
<Menu>
|
||||||
|
<MenuItem
|
||||||
|
icon={<Icon icon="trash-16" iconSize={16} />}
|
||||||
|
text={intl.get('delete_transaction')}
|
||||||
|
intent={Intent.DANGER}
|
||||||
|
onClick={safeCallback(onDelete, original)}
|
||||||
|
/>
|
||||||
|
</Menu>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useReconcileVendorCreditTransactionsTableColumns() {
|
||||||
|
return React.useMemo(
|
||||||
|
() => [
|
||||||
|
{
|
||||||
|
Header: intl.get('date'),
|
||||||
|
accessor: 'formatted_bill_date',
|
||||||
|
Cell: FormatDateCell,
|
||||||
|
width: 100,
|
||||||
|
className: 'date',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Header: intl.get('bill_number'),
|
||||||
|
accessor: 'bill_reference_no',
|
||||||
|
width: 100,
|
||||||
|
className: 'bill_number',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Header: intl.get('amount'),
|
||||||
|
accessor: 'formatted_amount',
|
||||||
|
width: 100,
|
||||||
|
className: 'amount',
|
||||||
|
align: 'right',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -39,9 +39,9 @@ export function useRefundCreditTransactionsTableColumns() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Header: intl.get('refund_vendor_credit.column.withdrawal_account'),
|
Header: intl.get('refund_vendor_credit.column.withdrawal_account'),
|
||||||
accessor: ({ from_account }) => from_account.name,
|
accessor: ({ deposit_account }) => deposit_account.name,
|
||||||
width: 100,
|
width: 100,
|
||||||
className: 'from_account',
|
className: 'deposit_account',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'reference_no',
|
id: 'reference_no',
|
||||||
|
|||||||
@@ -125,6 +125,16 @@ export const handleDeleteErrors = (errors) => {
|
|||||||
intent: Intent.DANGER,
|
intent: Intent.DANGER,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (
|
||||||
|
errors.find((error) => error.type === 'BILL_HAS_APPLIED_TO_VENDOR_CREDIT')
|
||||||
|
) {
|
||||||
|
AppToaster.show({
|
||||||
|
message: intl.get(
|
||||||
|
'bills.error.you_couldn_t_delete_bill_has_reconciled_with_vendor_credit',
|
||||||
|
),
|
||||||
|
intent: Intent.DANGER,
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
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 === 'VENDOR_CREDIT_HAS_APPLIED_BILLS')
|
||||||
|
) {
|
||||||
|
AppToaster.show({
|
||||||
|
message: intl.get(
|
||||||
|
'vendor_credit.error.you_couldn_t_delete_vendor_credit_has_reconciled',
|
||||||
|
),
|
||||||
|
intent: Intent.DANGER,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
errors.find(
|
||||||
|
(error) => error.type === 'VENDOR_CREDIT_HAS_REFUND_TRANSACTIONS',
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
AppToaster.show({
|
||||||
|
message: intl.get(
|
||||||
|
'vendor_credit.error.you_couldn_t_delete_vendor_credit_that_has_associated_refund',
|
||||||
|
),
|
||||||
|
intent: Intent.DANGER,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user