'use client'; import { useState } from 'react'; import { useMutation, useQueryClient } from '@tanstack/react-query'; import { Loader2, Trophy, XCircle } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Label } from '@/components/ui/label'; import { Textarea } from '@/components/ui/textarea'; import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle, } from '@/components/ui/dialog'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@/components/ui/select'; import { apiFetch } from '@/lib/api/client'; import { type InterestOutcome } from '@/lib/validators/interests'; const OUTCOME_LABELS: Record = { won: 'Won', lost_other_marina: 'Lost - went to another marina', lost_unqualified: 'Lost - unqualified', lost_no_response: 'Lost - no response', cancelled: 'Cancelled', }; const LOST_OUTCOMES: InterestOutcome[] = [ 'lost_other_marina', 'lost_unqualified', 'lost_no_response', 'cancelled', ]; interface Props { interestId: string; open: boolean; onOpenChange: (open: boolean) => void; /** Determines which outcomes are offered. 'won' opens with just the Won option preselected. */ mode: 'won' | 'lost'; } export function InterestOutcomeDialog({ interestId, open, onOpenChange, mode }: Props) { const queryClient = useQueryClient(); const choices: InterestOutcome[] = mode === 'won' ? ['won'] : LOST_OUTCOMES; const [outcome, setOutcome] = useState(choices[0]!); const [reason, setReason] = useState(''); const mutation = useMutation({ mutationFn: () => apiFetch(`/api/v1/interests/${interestId}/outcome`, { method: 'POST', body: { outcome, reason: reason || undefined }, }), onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['interests', interestId] }); queryClient.invalidateQueries({ queryKey: ['interests'] }); onOpenChange(false); setReason(''); }, }); function handleOpenChange(next: boolean) { if (!next) { setReason(''); setOutcome(choices[0]!); } onOpenChange(next); } return ( {mode === 'won' ? ( ) : ( )} {mode === 'won' ? 'Mark interest as won' : 'Close interest as lost'}
{mode === 'lost' ? (
) : null}