2026-04-24 14:36:34 +02:00
|
|
|
|
'use client';
|
|
|
|
|
|
|
|
|
|
|
|
import { useState } from 'react';
|
|
|
|
|
|
import Link from 'next/link';
|
|
|
|
|
|
import { useParams } from 'next/navigation';
|
|
|
|
|
|
import { Plus } from 'lucide-react';
|
|
|
|
|
|
|
|
|
|
|
|
import { Button } from '@/components/ui/button';
|
|
|
|
|
|
import {
|
|
|
|
|
|
Table,
|
|
|
|
|
|
TableHeader,
|
|
|
|
|
|
TableBody,
|
|
|
|
|
|
TableCell,
|
|
|
|
|
|
TableHead,
|
|
|
|
|
|
TableRow,
|
|
|
|
|
|
} from '@/components/ui/table';
|
|
|
|
|
|
import { EmptyState } from '@/components/shared/empty-state';
|
|
|
|
|
|
import { PermissionGate } from '@/components/shared/permission-gate';
|
|
|
|
|
|
import { YachtForm } from '@/components/yachts/yacht-form';
|
|
|
|
|
|
|
|
|
|
|
|
interface ClientYachtsTabProps {
|
|
|
|
|
|
clientId: string;
|
|
|
|
|
|
yachts: Array<{
|
|
|
|
|
|
id: string;
|
|
|
|
|
|
name: string;
|
|
|
|
|
|
hullNumber: string | null;
|
|
|
|
|
|
registration: string | null;
|
|
|
|
|
|
lengthFt: string | null;
|
|
|
|
|
|
widthFt: string | null;
|
|
|
|
|
|
status: string;
|
|
|
|
|
|
}>;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
fix(audit): backlog sweep — partial archived indexes, custom-fields per-entity gate, polish
Wave through the 2026-05-07 backlog of small/concrete audit-final-deferred
items (deferring the Documenso Phases 2-7 build and items needing design
decisions or live external instances).
DB schema:
- Migration 0046 converts 5 composite (port_id, archived_at) indexes to
partial WHERE archived_at IS NULL — clients, interests, yachts, and
both residential tables. Smaller, faster planner choice for the
dominant list-query shape.
Multi-tenant isolation:
- document_sends now verifies recipient.interestId belongs to the port
before landing on the audit row (the surrounding clientId check was
already port-scoped; interestId pollution was the gap).
Routes / API:
- /api/v1/custom-fields/[entityId] requires entityType query param and
gates on the matching resource permission (clients/interests/berths/
yachts/companies). Fixes the cross-resource gap where a user with
clients.view could read company custom-field values.
- Admin user list trash button wrapped in PermissionGate (edit was
already gated; remove was not).
Service polish:
- berth-recommender accepts string-shaped JSONB booleans
('true'/'false') so admin UIs that wrap values as strings don't
silently fall through to defaults.
- expense-pdf renderReceiptHeader anchors all text positions to a
captured baseY rather than reading mutating doc.y after rect+stroke.
Headers no longer drift on the first receipt page after a soft page
break.
- berth-pdf apply: collect non-finite numeric coercion drops + warn-log
them so partial silent drops are observable (was invisible because
the no-fields-supplied check only fires when ALL drop).
- Storage cache fingerprint comment documenting the encrypted-secret
invariant + the explicit invalidation hook.
UI polish:
- invoice-detail typed: replaced two `any` casts with a proper
InvoiceDetailData / LineItem / LinkedExpense interface set.
- YachtForm now accepts initialOwner prop. Wired through:
- client-yachts-tab passes { type: 'client', id: clientId }
- interest-form passes { type: 'client', id: selectedClientId }
- Interest-form yacht picker now includes company-owned yachts where
the selected client is a member (fetches client.companies and feeds
YachtPicker an array filter). Plus an inline "Add new" button that
opens YachtForm pre-bound to the client.
- YachtPicker accepts ownerFilter as single OR array for "match any"
semantics.
BACKLOG.md updated with what landed vs what's still deferred (and why
each deferred item is genuinely larger than this push warrants).
Tests: 1185/1185 vitest, tsc clean.
2026-05-07 21:45:42 +02:00
|
|
|
|
export function ClientYachtsTab({ clientId, yachts }: ClientYachtsTabProps) {
|
2026-04-24 14:36:34 +02:00
|
|
|
|
const routeParams = useParams<{ portSlug: string }>();
|
|
|
|
|
|
const portSlug = routeParams?.portSlug ?? '';
|
|
|
|
|
|
const [createOpen, setCreateOpen] = useState(false);
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<div className="space-y-4">
|
|
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
|
<h3 className="text-sm font-medium">Client-owned yachts</h3>
|
|
|
|
|
|
<PermissionGate resource="yachts" action="create">
|
|
|
|
|
|
<Button size="sm" onClick={() => setCreateOpen(true)}>
|
|
|
|
|
|
<Plus className="mr-1.5 h-4 w-4" />
|
|
|
|
|
|
Add yacht
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</PermissionGate>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{yachts.length === 0 ? (
|
fix(ux): popover collision padding, PWA manifest, webhook toasts, portal toast, dashboard error boundary, GDPR poll backoff, empty-state CTA
Grab-bag of UX gaps from audit-pass-#2 + #3. Each one is a small,
focused fix; bundled because they touch different surfaces.
- Popover: collisionPadding={16} + responsive
w-[min(calc(100vw-2rem),18rem)] so popovers stop clipping past the
viewport on iPhone 12 portrait.
- public/manifest.json (was missing) + manifest reference in
layout.tsx — PWA installability now works; icons (192/512/512-
maskable) were already present.
- Admin webhooks page: 4 silent `// ignore` catches in load/delete/
toggle/regenerate replaced with toast.error / toast.success. Users
no longer see a stale list with no feedback when an op fails.
- Portal document-download button: blocking alert() → toast.error().
- src/app/(dashboard)/error.tsx: branded error boundary with retry +
back-to-dashboard, replacing Next.js's default uncaught-error UI.
- GDPR export modal: refetchInterval was a flat 5s while the modal was
open. Switched to a function that only polls (every 15s) when a job
is actually pending/building; settled exports stop polling entirely.
- client-yachts-tab empty state gains a CTA wired to the existing
Add-yacht dialog, instead of just saying "No yachts".
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-06 14:59:27 +02:00
|
|
|
|
<EmptyState
|
|
|
|
|
|
title="No yachts yet"
|
|
|
|
|
|
description="Track every yacht this client owns or charters here. Linked yachts pre-fill EOIs and surface in the recommender."
|
|
|
|
|
|
action={{ label: 'Add yacht', onClick: () => setCreateOpen(true) }}
|
|
|
|
|
|
/>
|
2026-04-24 14:36:34 +02:00
|
|
|
|
) : (
|
|
|
|
|
|
<div className="rounded-md border">
|
|
|
|
|
|
<Table>
|
|
|
|
|
|
<TableHeader>
|
|
|
|
|
|
<TableRow>
|
|
|
|
|
|
<TableHead>Name</TableHead>
|
|
|
|
|
|
<TableHead>Dimensions</TableHead>
|
|
|
|
|
|
<TableHead>Hull Number</TableHead>
|
|
|
|
|
|
<TableHead>Status</TableHead>
|
|
|
|
|
|
</TableRow>
|
|
|
|
|
|
</TableHeader>
|
|
|
|
|
|
<TableBody>
|
|
|
|
|
|
{yachts.map((y) => (
|
|
|
|
|
|
<TableRow key={y.id}>
|
|
|
|
|
|
<TableCell>
|
|
|
|
|
|
<Link
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
|
|
href={`/${portSlug}/yachts/${y.id}` as any}
|
|
|
|
|
|
className="text-primary hover:underline"
|
|
|
|
|
|
>
|
|
|
|
|
|
{y.name}
|
|
|
|
|
|
</Link>
|
|
|
|
|
|
</TableCell>
|
|
|
|
|
|
<TableCell>
|
2026-05-04 22:57:01 +02:00
|
|
|
|
{y.lengthFt && y.widthFt ? `${y.lengthFt} × ${y.widthFt} ft` : '-'}
|
2026-04-24 14:36:34 +02:00
|
|
|
|
</TableCell>
|
2026-05-04 22:57:01 +02:00
|
|
|
|
<TableCell>{y.hullNumber ?? '-'}</TableCell>
|
2026-04-24 14:36:34 +02:00
|
|
|
|
<TableCell className="capitalize">{y.status.replace('_', ' ')}</TableCell>
|
|
|
|
|
|
</TableRow>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</TableBody>
|
|
|
|
|
|
</Table>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
fix(audit): backlog sweep — partial archived indexes, custom-fields per-entity gate, polish
Wave through the 2026-05-07 backlog of small/concrete audit-final-deferred
items (deferring the Documenso Phases 2-7 build and items needing design
decisions or live external instances).
DB schema:
- Migration 0046 converts 5 composite (port_id, archived_at) indexes to
partial WHERE archived_at IS NULL — clients, interests, yachts, and
both residential tables. Smaller, faster planner choice for the
dominant list-query shape.
Multi-tenant isolation:
- document_sends now verifies recipient.interestId belongs to the port
before landing on the audit row (the surrounding clientId check was
already port-scoped; interestId pollution was the gap).
Routes / API:
- /api/v1/custom-fields/[entityId] requires entityType query param and
gates on the matching resource permission (clients/interests/berths/
yachts/companies). Fixes the cross-resource gap where a user with
clients.view could read company custom-field values.
- Admin user list trash button wrapped in PermissionGate (edit was
already gated; remove was not).
Service polish:
- berth-recommender accepts string-shaped JSONB booleans
('true'/'false') so admin UIs that wrap values as strings don't
silently fall through to defaults.
- expense-pdf renderReceiptHeader anchors all text positions to a
captured baseY rather than reading mutating doc.y after rect+stroke.
Headers no longer drift on the first receipt page after a soft page
break.
- berth-pdf apply: collect non-finite numeric coercion drops + warn-log
them so partial silent drops are observable (was invisible because
the no-fields-supplied check only fires when ALL drop).
- Storage cache fingerprint comment documenting the encrypted-secret
invariant + the explicit invalidation hook.
UI polish:
- invoice-detail typed: replaced two `any` casts with a proper
InvoiceDetailData / LineItem / LinkedExpense interface set.
- YachtForm now accepts initialOwner prop. Wired through:
- client-yachts-tab passes { type: 'client', id: clientId }
- interest-form passes { type: 'client', id: selectedClientId }
- Interest-form yacht picker now includes company-owned yachts where
the selected client is a member (fetches client.companies and feeds
YachtPicker an array filter). Plus an inline "Add new" button that
opens YachtForm pre-bound to the client.
- YachtPicker accepts ownerFilter as single OR array for "match any"
semantics.
BACKLOG.md updated with what landed vs what's still deferred (and why
each deferred item is genuinely larger than this push warrants).
Tests: 1185/1185 vitest, tsc clean.
2026-05-07 21:45:42 +02:00
|
|
|
|
{createOpen && (
|
|
|
|
|
|
<YachtForm
|
|
|
|
|
|
open={createOpen}
|
|
|
|
|
|
onOpenChange={setCreateOpen}
|
|
|
|
|
|
initialOwner={{ type: 'client', id: clientId }}
|
|
|
|
|
|
/>
|
|
|
|
|
|
)}
|
2026-04-24 14:36:34 +02:00
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|