All files / src/pages/inventory/dialogs/DeleteItemDialog useDeleteItemQueries.ts

100% Statements 53/53
100% Branches 1/1
100% Functions 1/1
100% Lines 53/53

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 541x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x  
/**
 * useDeleteItemQueries - Data query coordination
 *
 * Manages: supplier list query, item search query, item details query
 * Responsibility: React Query orchestration with smart dependencies
 * Pattern: Queries only fire when parent state requires them
 */
 
import type { SupplierOption } from '../../../../api/analytics/types';
import {
  useSuppliersQuery,
  useItemSearchQuery,
  useItemDetailsQuery,
} from '../../../../api/inventory/hooks/useInventoryData';
 
export function useDeleteItemQueries(
  dialogOpen: boolean,
  selectedSupplier: SupplierOption | null,
  itemQuery: string,
  selectedItemId?: string
) {
  /**
   * Suppliers query
   * Fires: when dialog opens
   * Caches: globally across component tree via React Query
   * Returns: loading state, error, and supplier list with id/label
   */
  const suppliersQuery = useSuppliersQuery(dialogOpen);
 
  /**
   * Items search query
   * Fires: only when supplier is selected AND query has 2+ characters
   * Dependency: selectedSupplier ensures we filter by supplier context
   * Returns: filtered items matching search, loading state during fetch
   */
  const itemsQuery = useItemSearchQuery(selectedSupplier, itemQuery);
 
  /**
   * Item details query
   * Fires: only when specific item is selected
   * Dependency: selectedItemId (item.id) to fetch detailed data
   * Returns: name, onHand quantity, and other item details for preview
   */
  const itemDetailsQuery = useItemDetailsQuery(selectedItemId);
 
  return {
    suppliersQuery,
    itemsQuery,
    itemDetailsQuery,
  };
}
 
export type UseDeleteItemQueriesReturn = ReturnType<typeof useDeleteItemQueries>;