All files / src/pages/inventory/handlers useRefreshHandler.ts

100% Statements 44/44
100% Branches 2/2
100% Functions 1/1
100% Lines 44/44

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 451x 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 3x 2x 2x 2x 2x 3x 3x 3x 3x 3x 3x  
/**
 * @file useRefreshHandler.ts
 * @module pages/inventory/handlers/useRefreshHandler
 *
 * @summary
 * Custom hook that provides data refresh handler for InventoryBoard.
 * Manages: Reload data by resetting pagination.
 *
 * @enterprise
 * - Separation of concerns: handler logic isolated from component
 * - Single responsibility: triggers data reload via state changes
 */
 
import { useCallback } from 'react';
import type { InventoryState, InventoryStateSetters } from '../hooks/useInventoryState';
 
type InventoryStateReturn = InventoryState & InventoryStateSetters;
 
/**
 * Hook providing data refresh handler.
 *
 * Triggers data reload by resetting pagination to first page.
 * This causes useInventoryData to refetch data.
 *
 * @param state - Inventory board state object
 * @returns Object with handler function for refresh action
 *
 * @example
 * ```tsx
 * const { handleReload } = useRefreshHandler(state);
 * ```
 */
export function useRefreshHandler(state: InventoryStateReturn) {
  const handleReload = useCallback(() => {
    // Trigger data reload by resetting pagination
    // Since hooks can't be called conditionally, reload happens via dependency changes
    // Force reload by resetting pagination to first page
    state.setPaginationModel({ page: 0, pageSize: state.paginationModel.pageSize });
  }, [state]);
 
  return {
    handleReload,
  };
}