All files / src/stores partnerModalStore.ts

100% Statements 5/5
100% Branches 0/0
100% Functions 4/4
100% Lines 4/4

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                                                            10x               4x               5x               12x            
/**
 * Partner Modal Zustand Store (Story 2.8.3)
 *
 * Task 3b: GREEN Phase Implementation
 * AC1: Create Partner Modal
 * AC2: Edit Partner Modal
 *
 * Manages UI state for partner create/edit modal:
 * - Modal open/close state
 * - Mode tracking (create vs edit)
 * - Partner data for editing
 *
 * State is transient (not persisted) - resets on page reload
 */
 
import { create } from 'zustand';
import type { PartnerResponse } from '@/services/api/partnerApi';
 
interface PartnerModalStore {
  // State
  isOpen: boolean;
  mode: 'create' | 'edit';
  partnerToEdit: PartnerResponse | null;
 
  // Actions
  openCreateModal: () => void;
  openEditModal: (partner: PartnerResponse) => void;
  closeModal: () => void;
}
 
export const usePartnerModalStore = create<PartnerModalStore>((set) => ({
  // Initial state
  isOpen: false,
  mode: 'create',
  partnerToEdit: null,
 
  // Open create modal
  openCreateModal: () =>
    set({
      isOpen: true,
      mode: 'create',
      partnerToEdit: null,
    }),
 
  // Open edit modal with partner data
  openEditModal: (partner: PartnerResponse) =>
    set({
      isOpen: true,
      mode: 'edit',
      partnerToEdit: partner,
    }),
 
  // Close modal and reset state
  closeModal: () =>
    set({
      isOpen: false,
      mode: 'create',
      partnerToEdit: null,
    }),
}));