mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 05:40:31 +00:00
chrone: sperate client and server to different repos.
This commit is contained in:
119
src/containers/InventoryAdjustments/InventoryAdjustmentTable.js
Normal file
119
src/containers/InventoryAdjustments/InventoryAdjustmentTable.js
Normal file
@@ -0,0 +1,119 @@
|
||||
import React, { useCallback } from 'react';
|
||||
import intl from 'react-intl-universal';
|
||||
|
||||
import { DataTable } from 'components';
|
||||
import { TABLES } from 'common/tables';
|
||||
|
||||
import { useInventoryAdjustmentsColumns, ActionsMenu } from './components';
|
||||
import { useMemorizedColumnsWidths } from 'hooks';
|
||||
import { useInventoryAdjustmentsContext } from './InventoryAdjustmentsProvider';
|
||||
|
||||
import withAlertsActions from 'containers/Alert/withAlertActions';
|
||||
import withDrawerActions from 'containers/Drawer/withDrawerActions';
|
||||
import withInventoryAdjustmentActions from './withInventoryAdjustmentActions';
|
||||
import withInventoryAdjustments from './withInventoryAdjustments';
|
||||
|
||||
import { compose } from 'utils';
|
||||
|
||||
/**
|
||||
* Inventory adjustments datatable.
|
||||
*/
|
||||
function InventoryAdjustmentDataTable({
|
||||
// #withInventoryAdjustmentsActions
|
||||
setInventoryAdjustmentTableState,
|
||||
|
||||
// #withInventoryAdjustments
|
||||
inventoryAdjustmentTableState,
|
||||
|
||||
// #withAlertsActions
|
||||
openAlert,
|
||||
|
||||
// #withDrawerActions
|
||||
openDrawer,
|
||||
|
||||
// #ownProps
|
||||
tableProps,
|
||||
}) {
|
||||
const {
|
||||
isAdjustmentsLoading,
|
||||
isAdjustmentsFetching,
|
||||
|
||||
inventoryAdjustments,
|
||||
pagination,
|
||||
} = useInventoryAdjustmentsContext();
|
||||
|
||||
// Handle delete inventory adjustment transaction.
|
||||
const handleDeleteAdjustment = ({ id }) => {
|
||||
openAlert('inventory-adjustment-delete', { inventoryId: id });
|
||||
};
|
||||
|
||||
// Handle the inventory adjustment publish action.
|
||||
const handlePublishInventoryAdjustment = ({ id }) => {
|
||||
openAlert('inventory-adjustment-publish', { inventoryId: id });
|
||||
};
|
||||
// Handle view detail inventory adjustment.
|
||||
const handleViewDetailInventoryAdjustment = ({ id }) => {
|
||||
openDrawer('inventory-adjustment-drawer', { inventoryId: id });
|
||||
};
|
||||
|
||||
// Inventory adjustments columns.
|
||||
const columns = useInventoryAdjustmentsColumns();
|
||||
|
||||
const [initialColumnsWidths, , handleColumnResizing] =
|
||||
useMemorizedColumnsWidths(TABLES.INVENTORY_ADJUSTMENTS);
|
||||
|
||||
// Handle the table fetch data once states changing.
|
||||
const handleDataTableFetchData = useCallback(
|
||||
({ pageSize, pageIndex, sortBy }) => {
|
||||
setInventoryAdjustmentTableState({
|
||||
pageSize,
|
||||
pageIndex,
|
||||
sortBy,
|
||||
});
|
||||
},
|
||||
[setInventoryAdjustmentTableState],
|
||||
);
|
||||
// Handle cell click.
|
||||
const handleCellClick = (cell, event) => {
|
||||
openDrawer('inventory-adjustment-drawer', {
|
||||
inventoryId: cell.row.original.id,
|
||||
});
|
||||
};
|
||||
return (
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={inventoryAdjustments}
|
||||
loading={isAdjustmentsLoading}
|
||||
headerLoading={isAdjustmentsLoading}
|
||||
progressBarLoading={isAdjustmentsFetching}
|
||||
noInitialFetch={true}
|
||||
onFetchData={handleDataTableFetchData}
|
||||
manualSortBy={true}
|
||||
selectionColumn={true}
|
||||
pagination={true}
|
||||
pagesCount={pagination.pagesCount}
|
||||
autoResetSortBy={false}
|
||||
autoResetPage={false}
|
||||
onCellClick={handleCellClick}
|
||||
initialColumnsWidths={initialColumnsWidths}
|
||||
onColumnResizing={handleColumnResizing}
|
||||
payload={{
|
||||
onDelete: handleDeleteAdjustment,
|
||||
onPublish: handlePublishInventoryAdjustment,
|
||||
onViewDetails: handleViewDetailInventoryAdjustment,
|
||||
}}
|
||||
ContextMenu={ActionsMenu}
|
||||
noResults={intl.get('there_is_no_inventory_adjustments_transactions_yet')}
|
||||
{...tableProps}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withAlertsActions,
|
||||
withInventoryAdjustmentActions,
|
||||
withDrawerActions,
|
||||
withInventoryAdjustments(({ inventoryAdjustmentTableState }) => ({
|
||||
inventoryAdjustmentTableState,
|
||||
})),
|
||||
)(InventoryAdjustmentDataTable);
|
||||
Reference in New Issue
Block a user