import React, { useCallback } from 'react'; import { useHistory } from 'react-router-dom'; import { compose } from 'utils'; import { DataTable } from 'components'; import PaymentMadesEmptyStatus from './PaymentMadesEmptyStatus'; import TableSkeletonRows from 'components/Datatable/TableSkeletonRows'; import TableSkeletonHeader from 'components/Datatable/TableHeaderSkeleton'; import withPaymentMadeActions from './withPaymentMadeActions'; import withPaymentMade from './withPaymentMade'; import withCurrentOrganization from 'containers/Organization/withCurrentOrganization'; import withAlertsActions from 'containers/Alert/withAlertActions'; import withDrawerActions from 'containers/Drawer/withDrawerActions'; import { usePaymentMadesTableColumns, ActionsMenu } from './components'; import { usePaymentMadesListContext } from './PaymentMadesListProvider'; /** * Payment made datatable transactions. */ function PaymentMadesTable({ // #withPaymentMadeActions setPaymentMadesTableState, // #withPaymentMade paymentMadesTableState, // #withAlerts openAlert, // #withDrawerActions openDrawer, }) { // Payment mades table columns. const columns = usePaymentMadesTableColumns(); // Payment mades list context. const { paymentMades, pagination, isEmptyStatus, isPaymentsLoading, isPaymentsFetching, } = usePaymentMadesListContext(); // History context. const history = useHistory(); // Handles the edit payment made action. const handleEditPaymentMade = (paymentMade) => { history.push(`/payment-mades/${paymentMade.id}/edit`); }; // Handles the delete payment made action. const handleDeletePaymentMade = (paymentMade) => { openAlert('payment-made-delete', { paymentMadeId: paymentMade.id }); }; // Handle view detail payment made. const handleViewDetailPaymentMade = ({ id }) => { openDrawer('payment-made-detail-drawer', { paymentMadeId: id }); }; // Handle cell click. const handleCellClick = (cell, event) => { openDrawer('payment-made-detail-drawer', { paymentMadeId: cell.row.original.id, }); }; // Handle datatable fetch data once the table state change. const handleDataTableFetchData = useCallback( ({ pageIndex, pageSize, sortBy }) => { setPaymentMadesTableState({ pageIndex, pageSize, sortBy }); }, [setPaymentMadesTableState], ); // Display empty status instead of the table. if (isEmptyStatus) { return ; } return ( ); } export default compose( withPaymentMadeActions, withPaymentMade(({ paymentMadesTableState }) => ({ paymentMadesTableState })), withAlertsActions, withDrawerActions, withCurrentOrganization(), )(PaymentMadesTable);