'use client'; import { useState } from 'react'; import { useMutation, useQueryClient } from '@tanstack/react-query'; import { Eye, EyeOff, Loader2 } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from '@/components/ui/dialog'; import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group'; import { Label } from '@/components/ui/label'; import { apiFetch } from '@/lib/api/client'; import { cn } from '@/lib/utils'; interface AddBerthToInterestDialogProps { interestId: string; berth: { berthId: string; mooringNumber: string }; open: boolean; onOpenChange: (open: boolean) => void; onAdded?: () => void; } type RoleChoice = 'specific' | 'exploring'; export function AddBerthToInterestDialog({ interestId, berth, open, onOpenChange, onAdded, }: AddBerthToInterestDialogProps) { const queryClient = useQueryClient(); const [choice, setChoice] = useState('specific'); const mutation = useMutation({ mutationFn: async (isSpecificInterest: boolean) => apiFetch(`/api/v1/interests/${interestId}/berths`, { method: 'POST', body: { berthId: berth.berthId, isSpecificInterest }, }), onSuccess: () => { // Invalidate the recommender cache + linked-berths cache so both // surfaces re-fetch immediately. (See plan §5.3 / §5.5.) queryClient.invalidateQueries({ queryKey: ['berth-recommendations', interestId] }); queryClient.invalidateQueries({ queryKey: ['interest-berths', interestId] }); queryClient.invalidateQueries({ queryKey: ['interests', interestId] }); onAdded?.(); onOpenChange(false); }, }); const handleSubmit = () => { mutation.mutate(choice === 'specific'); }; return ( Add berth {berth.mooringNumber} to interest Choose how this berth relates to the deal. This drives whether it shows as “Under Offer” on the public map. setChoice(v as RoleChoice)} className="gap-3" > } /> } /> {mutation.isError ? (

{(mutation.error as Error)?.message ?? 'Failed to add berth.'}

) : null}
); } interface RoleCardProps { value: RoleChoice; checked: boolean; title: string; description: string; consequence: string; icon: React.ReactNode; } function RoleCard({ value, checked, title, description, consequence, icon }: RoleCardProps) { return ( ); }