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 | 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 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x | /**
* @file useQuantityAdjustFormState.ts
* @module dialogs/QuantityAdjustDialog/useQuantityAdjustFormState
*
* @summary
* Pure state management hook for quantity adjustment form.
* Manages UI state: supplier selection, item selection, search query, and form errors.
*
* @enterprise
* Separates state concerns from query/fetch logic for cleaner testing and composition.
* All state updates are deterministic and testable without HTTP calls.
*/
import * as React from 'react';
import type { SupplierOption, ItemOption } from '../../../../api/analytics/types';
/**
* State values for quantity adjustment form.
*
* @interface QuantityAdjustFormState
* @property {SupplierOption | null} selectedSupplier - Currently selected supplier
* @property {ItemOption | null} selectedItem - Currently selected item
* @property {string} itemQuery - Search query for item filtering
* @property {string} formError - Form-level error message
*/
export interface QuantityAdjustFormState {
selectedSupplier: SupplierOption | null;
selectedItem: ItemOption | null;
itemQuery: string;
formError: string;
}
/**
* Setter functions for state management.
*
* @interface QuantityAdjustFormStateSetters
*/
export interface QuantityAdjustFormStateSetters {
setSelectedSupplier: (supplier: SupplierOption | null) => void;
setSelectedItem: (item: ItemOption | null) => void;
setItemQuery: (query: string) => void;
setFormError: (error: string) => void;
}
/**
* Pure state management hook for quantity adjustment form.
*
* Provides separated state and setter functions without any async/query logic.
* This allows for easy composition with other hooks and clean testing.
*
* @returns State object and setter functions
*
* @example
* ```ts
* const { selectedSupplier, selectedItem, ...state } = useQuantityAdjustFormState();
* const { setSelectedSupplier, setSelectedItem, ...setters } = useQuantityAdjustFormState();
* ```
*/
export const useQuantityAdjustFormState = (): QuantityAdjustFormState &
QuantityAdjustFormStateSetters => {
const [selectedSupplier, setSelectedSupplier] = React.useState<SupplierOption | null>(null);
const [selectedItem, setSelectedItem] = React.useState<ItemOption | null>(null);
const [itemQuery, setItemQuery] = React.useState('');
const [formError, setFormError] = React.useState('');
return {
selectedSupplier,
selectedItem,
itemQuery,
formError,
setSelectedSupplier,
setSelectedItem,
setItemQuery,
setFormError,
};
};
|