fix(uat-batch-1): wave-1 blocker bugs — supplemental gate, file FK, downloads, search dedup, notes stale, expense form, vocab
Surgical fixes for the 7 UAT blockers that prevent productive forward
testing. Each item has a corresponding entry in alpha-uat-master.md.
- supplemental-info route relocated out of (portal) so it bypasses the
isPortalDisabledGlobally() kill-switch. URL unchanged.
- file upload service derives client_id/company_id/yacht_id from
(entityType, entityId) when not explicitly passed, so interest-tab
uploads no longer land with client_id=NULL and stay visible in the
Attachments list.
- triggerBlobDownload / triggerUrlDownload helpers in src/lib/utils
attach the anchor to the DOM before click so Chromium honours the
download attribute; 7 sites refactored, file-named downloads stop
arriving as bare UUIDs.
- search-nav-catalog dedupes by href at the result-collection layer so
the same href can no longer surface twice in the command-K dropdown
(kills the React duplicate-key warning); /admin/templates entries
merged into a single richer-keyword variant.
- NotesList gains a parentInvalidateKey prop, wired through all five
callers (interest, client, yacht, company, residential client/
interest) so the Overview "Latest note" teaser refreshes when a note
is added in the Notes tab.
- expense-form-dialog: setValue('receiptFileIds') / setValue(
'noReceiptAcknowledged') on upload/clear/checkbox so the schema-level
refine sees the field and Create stops silently no-op'ing on submit.
- bulk-add-berths-wizard: side-pontoon dropdown now reads through
useVocabulary('berth_side_pontoon_options') instead of a wrong local
enum ('Port', 'Starboard', 'Bow', 'Stern') — wizard data now matches
the rest of the platform + honours admin-editable per-port overrides.
tsc clean. 1419/1419 vitest. lint clean on touched files.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -16,6 +16,7 @@ import {
|
||||
} from '@/components/ui/dialog';
|
||||
import { apiFetch } from '@/lib/api/client';
|
||||
import { toastError } from '@/lib/api/toast-error';
|
||||
import { triggerUrlDownload } from '@/lib/utils/download';
|
||||
|
||||
interface BackupJob {
|
||||
id: string;
|
||||
@@ -87,10 +88,7 @@ export function BackupAdminPanel() {
|
||||
async function download(id: string) {
|
||||
try {
|
||||
const res = await apiFetch<{ data: { url: string } }>(`/api/v1/admin/backup/${id}/download`);
|
||||
const a = document.createElement('a');
|
||||
a.href = res.data.url;
|
||||
a.download = `backup-${id}.dump`;
|
||||
a.click();
|
||||
triggerUrlDownload(res.data.url, `backup-${id}.dump`);
|
||||
} catch (err) {
|
||||
toastError(err);
|
||||
}
|
||||
|
||||
@@ -35,12 +35,11 @@ import {
|
||||
} from '@/components/ui/select';
|
||||
import { apiFetch } from '@/lib/api/client';
|
||||
import { toastError } from '@/lib/api/toast-error';
|
||||
import { useVocabulary } from '@/hooks/use-vocabulary';
|
||||
|
||||
const DOCK_LETTERS = ['A', 'B', 'C', 'D', 'E'] as const;
|
||||
type DockLetter = (typeof DOCK_LETTERS)[number];
|
||||
|
||||
const SIDE_PONTOON_OPTIONS = ['Port', 'Starboard', 'Bow', 'Stern', ''] as const;
|
||||
|
||||
interface RowDraft {
|
||||
mooringNumber: string;
|
||||
area: string;
|
||||
@@ -77,6 +76,10 @@ export function BulkAddBerthsWizard() {
|
||||
const params = useParams<{ portSlug: string }>();
|
||||
const portSlug = params?.portSlug ?? '';
|
||||
const router = useRouter();
|
||||
// Canonical, admin-editable side-pontoon vocabulary (per-port overrides
|
||||
// honoured). Falls back to BERTH_SIDE_PONTOON_OPTIONS defaults when the
|
||||
// /api/v1/vocabularies request hasn't resolved yet.
|
||||
const sidePontoonOptions = useVocabulary('berth_side_pontoon_options');
|
||||
|
||||
const [step, setStep] = useState<'sequence' | 'edit'>('sequence');
|
||||
|
||||
@@ -261,7 +264,7 @@ export function BulkAddBerthsWizard() {
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="__none__">(none)</SelectItem>
|
||||
{SIDE_PONTOON_OPTIONS.filter(Boolean).map((p) => (
|
||||
{sidePontoonOptions.filter(Boolean).map((p) => (
|
||||
<SelectItem key={p} value={p}>
|
||||
{p}
|
||||
</SelectItem>
|
||||
@@ -331,7 +334,7 @@ export function BulkAddBerthsWizard() {
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="__none__">—</SelectItem>
|
||||
{SIDE_PONTOON_OPTIONS.filter(Boolean).map((p) => (
|
||||
{sidePontoonOptions.filter(Boolean).map((p) => (
|
||||
<SelectItem key={p} value={p}>
|
||||
{p}
|
||||
</SelectItem>
|
||||
|
||||
@@ -11,6 +11,7 @@ import { usePaginatedQuery } from '@/hooks/use-paginated-query';
|
||||
import { useRealtimeInvalidation } from '@/hooks/use-realtime-invalidation';
|
||||
import { useConfirmation } from '@/hooks/use-confirmation';
|
||||
import { apiFetch } from '@/lib/api/client';
|
||||
import { triggerUrlDownload } from '@/lib/utils/download';
|
||||
import type { FileRow } from '@/components/files/file-grid';
|
||||
|
||||
interface ClientFilesTabProps {
|
||||
@@ -39,10 +40,7 @@ export function ClientFilesTab({ clientId }: ClientFilesTabProps) {
|
||||
const res = await apiFetch<{ data: { url: string; filename: string } }>(
|
||||
`/api/v1/files/${file.id}/download`,
|
||||
);
|
||||
const a = document.createElement('a');
|
||||
a.href = res.data.url;
|
||||
a.download = res.data.filename;
|
||||
a.click();
|
||||
triggerUrlDownload(res.data.url, res.data.filename);
|
||||
} catch {
|
||||
// silent
|
||||
}
|
||||
|
||||
@@ -288,6 +288,7 @@ export function getClientTabs({ clientId, currentUserId, client }: ClientTabsOpt
|
||||
entityType="clients"
|
||||
entityId={clientId}
|
||||
currentUserId={currentUserId}
|
||||
parentInvalidateKey={['clients', clientId]}
|
||||
/>
|
||||
),
|
||||
},
|
||||
|
||||
@@ -11,6 +11,7 @@ import { usePaginatedQuery } from '@/hooks/use-paginated-query';
|
||||
import { useRealtimeInvalidation } from '@/hooks/use-realtime-invalidation';
|
||||
import { useConfirmation } from '@/hooks/use-confirmation';
|
||||
import { apiFetch } from '@/lib/api/client';
|
||||
import { triggerUrlDownload } from '@/lib/utils/download';
|
||||
import type { FileRow } from '@/components/files/file-grid';
|
||||
|
||||
interface CompanyFilesTabProps {
|
||||
@@ -39,10 +40,7 @@ export function CompanyFilesTab({ companyId }: CompanyFilesTabProps) {
|
||||
const res = await apiFetch<{ data: { url: string; filename: string } }>(
|
||||
`/api/v1/files/${file.id}/download`,
|
||||
);
|
||||
const a = document.createElement('a');
|
||||
a.href = res.data.url;
|
||||
a.download = res.data.filename;
|
||||
a.click();
|
||||
triggerUrlDownload(res.data.url, res.data.filename);
|
||||
} catch {
|
||||
// silent
|
||||
}
|
||||
|
||||
@@ -229,6 +229,7 @@ export function getCompanyTabs({
|
||||
entityType="companies"
|
||||
entityId={companyId}
|
||||
currentUserId={currentUserId}
|
||||
parentInvalidateKey={['companies', companyId]}
|
||||
/>
|
||||
),
|
||||
},
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { triggerBlobDownload } from '@/lib/utils/download';
|
||||
|
||||
interface ChartCardProps {
|
||||
title: string;
|
||||
@@ -24,22 +25,6 @@ interface ChartCardProps {
|
||||
className?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Match the pattern used elsewhere in the codebase (see
|
||||
* `src/app/(dashboard)/[portSlug]/expenses/page.tsx`, `client-files-tab.tsx`,
|
||||
* `backup-admin-panel.tsx`). All four reduce to the same dead-simple shape
|
||||
* and they all work — Chrome honours the `download` attribute and the
|
||||
* file lands with the right name.
|
||||
*/
|
||||
function triggerBlobDownload(blob: Blob, filename: string) {
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = filename;
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
async function exportContainerAsPng(container: HTMLElement, filename: string) {
|
||||
const svg = container.querySelector('svg');
|
||||
if (!svg) return;
|
||||
|
||||
@@ -88,6 +88,7 @@ export function ExpenseFormDialog({ open, onOpenChange, expense }: ExpenseFormDi
|
||||
expenseDate: new Date(expense.expenseDate),
|
||||
paymentStatus: (expense.paymentStatus as CreateExpenseInput['paymentStatus']) ?? 'unpaid',
|
||||
tripLabel: expense.tripLabel ?? undefined,
|
||||
noReceiptAcknowledged: Boolean(expense.noReceiptAcknowledged),
|
||||
});
|
||||
setUploadedReceipt(null);
|
||||
setPreviewUrl(null);
|
||||
@@ -98,6 +99,7 @@ export function ExpenseFormDialog({ open, onOpenChange, expense }: ExpenseFormDi
|
||||
currency: 'USD',
|
||||
paymentStatus: 'unpaid',
|
||||
expenseDate: new Date(),
|
||||
noReceiptAcknowledged: false,
|
||||
});
|
||||
setUploadedReceipt(null);
|
||||
setPreviewUrl(null);
|
||||
@@ -166,9 +168,15 @@ export function ExpenseFormDialog({ open, onOpenChange, expense }: ExpenseFormDi
|
||||
const json = (await res.json()) as { data: { id: string; filename: string } };
|
||||
setUploadedReceipt({ id: json.data.id, filename: json.data.filename });
|
||||
setNoReceipt(false);
|
||||
// Keep form state in sync so the schema-level refine that requires
|
||||
// receiptFileIds.length > 0 || noReceiptAcknowledged === true sees
|
||||
// a populated value at validation time.
|
||||
setValue('receiptFileIds', [json.data.id], { shouldValidate: true });
|
||||
setValue('noReceiptAcknowledged', false, { shouldValidate: true });
|
||||
} catch (err) {
|
||||
setUploadError(err instanceof Error ? err.message : 'Upload failed');
|
||||
setUploadedReceipt(null);
|
||||
setValue('receiptFileIds', undefined, { shouldValidate: true });
|
||||
} finally {
|
||||
setIsUploading(false);
|
||||
}
|
||||
@@ -180,6 +188,7 @@ export function ExpenseFormDialog({ open, onOpenChange, expense }: ExpenseFormDi
|
||||
setUploadedReceipt(null);
|
||||
setUploadError(null);
|
||||
if (fileInputRef.current) fileInputRef.current.value = '';
|
||||
setValue('receiptFileIds', undefined, { shouldValidate: true });
|
||||
}
|
||||
|
||||
function onSubmit(data: CreateExpenseInput) {
|
||||
@@ -403,6 +412,7 @@ export function ExpenseFormDialog({ open, onOpenChange, expense }: ExpenseFormDi
|
||||
const next = checked === true;
|
||||
setNoReceipt(next);
|
||||
if (next) clearReceipt();
|
||||
setValue('noReceiptAcknowledged', next, { shouldValidate: true });
|
||||
}}
|
||||
/>
|
||||
<Label htmlFor="noReceipt" className="text-sm font-normal leading-tight">
|
||||
|
||||
@@ -15,6 +15,7 @@ import { usePaginatedQuery } from '@/hooks/use-paginated-query';
|
||||
import { useRealtimeInvalidation } from '@/hooks/use-realtime-invalidation';
|
||||
import { useConfirmation } from '@/hooks/use-confirmation';
|
||||
import { apiFetch } from '@/lib/api/client';
|
||||
import { triggerUrlDownload } from '@/lib/utils/download';
|
||||
|
||||
interface InterestDocumentsTabProps {
|
||||
interestId: string;
|
||||
@@ -69,10 +70,7 @@ export function InterestDocumentsTab({ interestId }: InterestDocumentsTabProps)
|
||||
const res = await apiFetch<{ data: { url: string; filename: string } }>(
|
||||
`/api/v1/files/${file.id}/download`,
|
||||
);
|
||||
const a = document.createElement('a');
|
||||
a.href = res.data.url;
|
||||
a.download = res.data.filename;
|
||||
a.click();
|
||||
triggerUrlDownload(res.data.url, res.data.filename);
|
||||
} catch {
|
||||
// silent
|
||||
}
|
||||
@@ -141,6 +139,7 @@ export function InterestDocumentsTab({ interestId }: InterestDocumentsTabProps)
|
||||
<FileUploadZone
|
||||
entityType="client"
|
||||
entityId={interest.clientId}
|
||||
clientId={interest.clientId}
|
||||
onUploadComplete={() => {
|
||||
queryClient.invalidateQueries({ queryKey: filesQueryKey });
|
||||
}}
|
||||
|
||||
@@ -36,6 +36,7 @@ import {
|
||||
type DocumentStatus,
|
||||
} from '@/lib/labels/document-status';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { triggerUrlDownload } from '@/lib/utils/download';
|
||||
import { useUIStore } from '@/stores/ui-store';
|
||||
|
||||
interface InterestEoiTabProps {
|
||||
@@ -594,10 +595,7 @@ function SignedPdfActions({ fileId }: { fileId: string }) {
|
||||
if (mode === 'view') {
|
||||
window.open(res.data.url, '_blank', 'noopener,noreferrer');
|
||||
} else {
|
||||
const a = document.createElement('a');
|
||||
a.href = res.data.url;
|
||||
a.download = res.data.filename;
|
||||
a.click();
|
||||
triggerUrlDownload(res.data.url, res.data.filename);
|
||||
}
|
||||
} catch (err) {
|
||||
toastError(err, 'Failed to fetch signed PDF');
|
||||
|
||||
@@ -1208,7 +1208,12 @@ export function getInterestTabs({
|
||||
id: 'notes',
|
||||
label: 'Notes',
|
||||
content: (
|
||||
<NotesList entityType="interests" entityId={interestId} currentUserId={currentUserId} />
|
||||
<NotesList
|
||||
entityType="interests"
|
||||
entityId={interestId}
|
||||
currentUserId={currentUserId}
|
||||
parentInvalidateKey={['interests', interestId]}
|
||||
/>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
@@ -116,6 +116,7 @@ export function getResidentialClientTabs({
|
||||
entityType="residential_clients"
|
||||
entityId={clientId}
|
||||
currentUserId={currentUserId}
|
||||
parentInvalidateKey={['residential-client', clientId]}
|
||||
/>
|
||||
),
|
||||
},
|
||||
|
||||
@@ -59,6 +59,7 @@ export function getResidentialInterestTabs({
|
||||
entityType="residential_interests"
|
||||
entityId={interestId}
|
||||
currentUserId={currentUserId}
|
||||
parentInvalidateKey={['residential-interest', interestId]}
|
||||
/>
|
||||
),
|
||||
},
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { useQuery, useMutation, useQueryClient, type QueryKey } from '@tanstack/react-query';
|
||||
import { formatDistanceToNow } from 'date-fns';
|
||||
import { Lock, Pencil, Trash2, Send, Loader2 } from 'lucide-react';
|
||||
import { useAutoAnimate } from '@formkit/auto-animate/react';
|
||||
@@ -100,6 +100,14 @@ interface NotesListProps {
|
||||
* residential_clients}. Ignored for interests / residential_interests.
|
||||
*/
|
||||
aggregate?: boolean;
|
||||
/**
|
||||
* Optional parent-entity query key to invalidate alongside the notes
|
||||
* query on create/update/delete. The parent entity detail typically
|
||||
* hydrates a `recentNote` / `notesCount` teaser that goes stale after
|
||||
* a note mutation; passing the detail's query key here keeps it in
|
||||
* sync without a hard refresh.
|
||||
*/
|
||||
parentInvalidateKey?: QueryKey;
|
||||
}
|
||||
|
||||
const NOTE_EDIT_WINDOW_MS = 15 * 60 * 1000; // 15 minutes
|
||||
@@ -126,8 +134,20 @@ function sortByGroup(notes: Note[]): Note[] {
|
||||
});
|
||||
}
|
||||
|
||||
export function NotesList({ entityType, entityId, currentUserId, aggregate }: NotesListProps) {
|
||||
export function NotesList({
|
||||
entityType,
|
||||
entityId,
|
||||
currentUserId,
|
||||
aggregate,
|
||||
parentInvalidateKey,
|
||||
}: NotesListProps) {
|
||||
const queryClient = useQueryClient();
|
||||
const invalidateAll = () => {
|
||||
queryClient.invalidateQueries({ queryKey });
|
||||
if (parentInvalidateKey) {
|
||||
queryClient.invalidateQueries({ queryKey: parentInvalidateKey });
|
||||
}
|
||||
};
|
||||
const [newNote, setNewNote] = useState('');
|
||||
const [editingId, setEditingId] = useState<string | null>(null);
|
||||
const [editContent, setEditContent] = useState('');
|
||||
@@ -164,7 +184,7 @@ export function NotesList({ entityType, entityId, currentUserId, aggregate }: No
|
||||
const createMutation = useMutation({
|
||||
mutationFn: (content: string) => apiFetch(baseEndpoint, { method: 'POST', body: { content } }),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey });
|
||||
invalidateAll();
|
||||
setNewNote('');
|
||||
},
|
||||
});
|
||||
@@ -173,14 +193,14 @@ export function NotesList({ entityType, entityId, currentUserId, aggregate }: No
|
||||
mutationFn: ({ noteId, content }: { noteId: string; content: string }) =>
|
||||
apiFetch(`${baseEndpoint}/${noteId}`, { method: 'PATCH', body: { content } }),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey });
|
||||
invalidateAll();
|
||||
setEditingId(null);
|
||||
},
|
||||
});
|
||||
|
||||
const deleteMutation = useMutation({
|
||||
mutationFn: (noteId: string) => apiFetch(`${baseEndpoint}/${noteId}`, { method: 'DELETE' }),
|
||||
onSuccess: () => queryClient.invalidateQueries({ queryKey }),
|
||||
onSuccess: () => invalidateAll(),
|
||||
});
|
||||
|
||||
function canEdit(note: Note): boolean {
|
||||
|
||||
@@ -348,7 +348,13 @@ export function getYachtTabs({ yachtId, currentUserId, yacht }: YachtTabsOptions
|
||||
id: 'notes',
|
||||
label: 'Notes',
|
||||
content: (
|
||||
<NotesList entityType="yachts" entityId={yachtId} currentUserId={currentUserId} aggregate />
|
||||
<NotesList
|
||||
entityType="yachts"
|
||||
entityId={yachtId}
|
||||
currentUserId={currentUserId}
|
||||
aggregate
|
||||
parentInvalidateKey={['yachts', yachtId]}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user