All files / src/pages/suppliers/dialogs/EditSupplierDialog useEditSupplierConfirmation.ts

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

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 681x 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 6x 6x 6x 6x 1x 1x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x  
/**
 * @file useEditSupplierConfirmation.ts
 * @module dialogs/EditSupplierDialog/useEditSupplierConfirmation
 *
 * @summary
 * Hook for managing supplier edit confirmation state.
 * Handles confirmation dialog visibility and pending changes.
 *
 * @enterprise
 * - Focused confirmation state management
 * - Reusable for other edit dialogs
 * - Clean API for confirmation flow
 */
 
import * as React from 'react';
import type { EditSupplierForm } from '../../../../api/suppliers';
 
/**
 * Hook return type for confirmation state.
 *
 * @interface UseEditSupplierConfirmationReturn
 */
export interface UseEditSupplierConfirmationReturn {
  /** Whether confirmation dialog is open */
  showConfirmation: boolean;
  /** Set confirmation visibility */
  setShowConfirmation: (show: boolean) => void;
  /** Pending changes to apply */
  pendingChanges: EditSupplierForm | null;
  /** Set pending changes */
  setPendingChanges: (changes: EditSupplierForm | null) => void;
  /** Reset to initial state */
  reset: () => void;
}
 
/**
 * Hook for managing supplier edit confirmation state.
 *
 * Manages:
 * - Confirmation dialog visibility
 * - Pending changes before confirmation
 * - State reset for next workflow
 *
 * @returns Confirmation state and handlers
 *
 * @example
 * ```ts
 * const { showConfirmation, pendingChanges, setShowConfirmation } = useEditSupplierConfirmation();
 * ```
 */
export const useEditSupplierConfirmation = (): UseEditSupplierConfirmationReturn => {
  const [showConfirmation, setShowConfirmation] = React.useState(false);
  const [pendingChanges, setPendingChanges] = React.useState<EditSupplierForm | null>(null);
 
  const reset = React.useCallback(() => {
    setShowConfirmation(false);
    setPendingChanges(null);
  }, []);
 
  return {
    showConfirmation,
    setShowConfirmation,
    pendingChanges,
    setPendingChanges,
    reset,
  };
};