feat: add context menu.

This commit is contained in:
elforjani13
2021-12-20 11:12:38 +02:00
parent 7095903653
commit 0ca0a2ee0b
3 changed files with 70 additions and 2 deletions

View File

@@ -1,13 +1,28 @@
import React from 'react';
import { useHistory } from 'react-router-dom';
import { DataTable } from '../../../../../components';
import { useItemDetailDrawerContext } from '../../ItemDetailDrawerProvider';
import { useItemAssociatedBillTransactions } from 'hooks/query';
import { useBillTransactionsColumns, ActionsMenu } from './components';
import withAlertsActions from 'containers/Alert/withAlertActions';
import withDrawerActions from 'containers/Drawer/withDrawerActions';
import { compose } from 'utils';
/**
* Bill payment transactions data table.
*/
export default function BillPaymentTransactions() {
function BillPaymentTransactions({
// #withAlertsActions
openAlert,
// #withDrawerActions
closeDrawer,
}) {
const history = useHistory();
const columns = useBillTransactionsColumns();
const { itemId } = useItemDetailDrawerContext();
@@ -21,6 +36,18 @@ export default function BillPaymentTransactions() {
enabled: !!itemId,
});
// Handles delete payment transactions.
const handleDeletePaymentTransactons = ({ bill_id }) => {
openAlert('bill-delete', {
billId: bill_id,
});
};
// Handles edit payment transactions.
const handleEditPaymentTransactions = ({ bill_id }) => {
history.push(`/bills/${bill_id}/edit`);
closeDrawer('item-detail-drawer');
};
return (
<DataTable
columns={columns}
@@ -29,6 +56,14 @@ export default function BillPaymentTransactions() {
headerLoading={isBillTransactionsLoading}
progressBarLoading={isBillTransactionFetching}
ContextMenu={ActionsMenu}
payload={{
onEdit: handleEditPaymentTransactions,
onDelete: handleDeletePaymentTransactons,
}}
/>
);
}
export default compose(
withAlertsActions,
withDrawerActions,
)(BillPaymentTransactions);