Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x | /**
* @file useInventoryState.ts
* @module pages/inventory/hooks/useInventoryState
*
* @summary
* Centralized state management for inventory page.
* Manages filters, pagination, sorting, dialog toggles, and selection.
*
* @enterprise
* - Single source of truth for UI state
* - Separated from data fetching and processing logic
* - Allows components to be pure and testable
*/
import * as React from 'react';
import type { GridPaginationModel, GridSortModel } from '@mui/x-data-grid';
/**
* Complete inventory page state interface.
*
* @interface InventoryState
*/
export interface InventoryState {
// Filters
q: string;
supplierId: string | number | null;
belowMinOnly: boolean;
// Pagination & Sorting
paginationModel: GridPaginationModel;
sortModel: GridSortModel;
// Selection
selectedId: string | null;
// Dialog toggles
openNew: boolean;
openEdit: boolean;
openEditName: boolean;
openDelete: boolean;
openAdjust: boolean;
openPrice: boolean;
}
/**
* State setter functions.
*/
export interface InventoryStateSetters {
setQ: (q: string) => void;
setSupplierId: (id: string | number | null) => void;
setBelowMinOnly: (below: boolean) => void;
setPaginationModel: (model: GridPaginationModel) => void;
setSortModel: (model: GridSortModel) => void;
setSelectedId: (id: string | null) => void;
setOpenNew: (open: boolean) => void;
setOpenEdit: (open: boolean) => void;
setOpenEditName: (open: boolean) => void;
setOpenDelete: (open: boolean) => void;
setOpenAdjust: (open: boolean) => void;
setOpenPrice: (open: boolean) => void;
}
/**
* Hook for managing inventory page state.
*
* Returns unified state object and setter functions.
*
* @returns State and setter functions
*/
export const useInventoryState = (): InventoryState & InventoryStateSetters => {
const [q, setQ] = React.useState('');
const [supplierId, setSupplierId] = React.useState<string | number | null>(null);
const [belowMinOnly, setBelowMinOnly] = React.useState(false);
const [paginationModel, setPaginationModel] = React.useState<GridPaginationModel>({
page: 0,
pageSize: 10,
});
const [sortModel, setSortModel] = React.useState<GridSortModel>([
{ field: 'name', sort: 'asc' },
]);
const [selectedId, setSelectedId] = React.useState<string | null>(null);
const [openNew, setOpenNew] = React.useState(false);
const [openEdit, setOpenEdit] = React.useState(false);
const [openEditName, setOpenEditName] = React.useState(false);
const [openDelete, setOpenDelete] = React.useState(false);
const [openAdjust, setOpenAdjust] = React.useState(false);
const [openPrice, setOpenPrice] = React.useState(false);
return {
q,
supplierId,
belowMinOnly,
paginationModel,
sortModel,
selectedId,
openNew,
openEdit,
openEditName,
openDelete,
openAdjust,
openPrice,
setQ,
setSupplierId,
setBelowMinOnly,
setPaginationModel,
setSortModel,
setSelectedId,
setOpenNew,
setOpenEdit,
setOpenEditName,
setOpenDelete,
setOpenAdjust,
setOpenPrice,
};
};
|