Files
pn-new-crm/src/components/interests/add-berth-to-interest-dialog.tsx
Matt 221ae5784e chore(autonomous-session): consolidate uncommitted work from prior session
Bundles the prior autonomous-session output that was sitting unstaged:

- Em-dash sweep across src/ + tests/ (en-dash/em-dash to hyphen, ~2280 instances)
- country-flag-icons rollout (CountryFlag component, replaces emoji glyphs that
  never rendered on Windows; lazy-loads the 3x2 SVG index as a single chunk
  after the per-subpath dynamic-import approach silently failed in webpack)
- Admin IA Phase 1+2: 7-domain regroup, 41 to 38 pages, /admin/berths index,
  redirects (ocr to ai, reports to dashboard, invitations to users),
  docs/admin-ia-proposal.md
- Per-template email tester (registry + endpoint + UI on Email admin page)
- Cancel-document mode picker (delete-from-Documenso vs keep-for-audit)
- Dashboard PDF report: 25 widgets, SVG charts, date-range picker, 11 resolvers
- Customize-widgets per-region sortables at xl+ (charts/rails/feed); single
  flat sortable below xl when the layout stacks; per-viewport saved orders
- Audit doc updates capturing each shipped item
- Lint fixes: react-compiler immutability in DonutChart (reduce instead of
  let-reassign), set-state-in-effect disables in CountryFlag and
  UploadForSigning preview-bytes effect, unused 'confirm' destructures in
  interest contract + reservation tabs, unescaped apostrophe in test-template
  card copy
2026-05-23 00:52:59 +02:00

153 lines
4.8 KiB
TypeScript

'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<RoleChoice>('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 (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent>
<DialogHeader>
<DialogTitle>Add berth {berth.mooringNumber} to interest</DialogTitle>
<DialogDescription>
Choose how this berth relates to the deal. This drives whether it shows as &ldquo;Under
Offer&rdquo; on the public map.
</DialogDescription>
</DialogHeader>
<RadioGroup
value={choice}
onValueChange={(v) => setChoice(v as RoleChoice)}
className="gap-3"
>
<RoleCard
value="specific"
checked={choice === 'specific'}
title="Pitching specifically"
description="The client is pitched on this exact berth."
consequence="This berth will appear as under interest on the public map."
icon={<Eye className="size-4" aria-hidden />}
/>
<RoleCard
value="exploring"
checked={choice === 'exploring'}
title="Just exploring"
description="The berth is being considered or covered by the EOI bundle, but not pitched specifically."
consequence="This berth stays marked “Available” on the public map - the link is internal only."
icon={<EyeOff className="size-4" aria-hidden />}
/>
</RadioGroup>
{mutation.isError ? (
<p className="text-sm text-destructive">
{(mutation.error as Error)?.message ?? 'Failed to add berth.'}
</p>
) : null}
<DialogFooter>
<Button
type="button"
variant="outline"
onClick={() => onOpenChange(false)}
disabled={mutation.isPending}
>
Cancel
</Button>
<Button type="button" onClick={handleSubmit} disabled={mutation.isPending}>
{mutation.isPending ? (
<Loader2 className="mr-1.5 size-3.5 animate-spin" aria-hidden />
) : null}
Add berth to interest
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}
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 (
<Label
htmlFor={`role-${value}`}
className={cn(
'flex cursor-pointer items-start gap-3 rounded-lg border p-3 transition-colors',
checked ? 'border-brand-300 bg-brand-50/50 ring-1 ring-brand-200' : 'border-border',
)}
>
<RadioGroupItem value={value} id={`role-${value}`} className="mt-1" />
<div className="flex-1 space-y-1">
<div className="flex items-center gap-1.5 text-sm font-semibold">
{icon}
{title}
</div>
<p className="text-xs text-muted-foreground">{description}</p>
<p className="text-xs font-medium text-foreground/80">{consequence}</p>
</div>
</Label>
);
}