2026-04-24 13:44:15 +02:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
|
|
import { useState } from 'react';
|
|
|
|
|
import { useParams } from 'next/navigation';
|
2026-05-06 14:58:34 +02:00
|
|
|
import { Plus, Archive, Tag as TagIcon, TagsIcon } from 'lucide-react';
|
2026-04-24 13:44:15 +02:00
|
|
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
|
|
|
|
|
|
|
|
import { Button } from '@/components/ui/button';
|
|
|
|
|
import { DataTable } from '@/components/shared/data-table';
|
|
|
|
|
import { FilterBar } from '@/components/shared/filter-bar';
|
|
|
|
|
import { SavedViewsDropdown } from '@/components/shared/saved-views-dropdown';
|
|
|
|
|
import { PageHeader } from '@/components/shared/page-header';
|
|
|
|
|
import { EmptyState } from '@/components/shared/empty-state';
|
|
|
|
|
import { TableSkeleton } from '@/components/shared/loading-skeleton';
|
|
|
|
|
import { ArchiveConfirmDialog } from '@/components/shared/archive-confirm-dialog';
|
|
|
|
|
import { PermissionGate } from '@/components/shared/permission-gate';
|
2026-05-06 14:58:34 +02:00
|
|
|
import { TagPicker } from '@/components/shared/tag-picker';
|
|
|
|
|
import {
|
|
|
|
|
Dialog,
|
|
|
|
|
DialogContent,
|
|
|
|
|
DialogDescription,
|
|
|
|
|
DialogFooter,
|
|
|
|
|
DialogHeader,
|
|
|
|
|
DialogTitle,
|
|
|
|
|
} from '@/components/ui/dialog';
|
feat(mobile): mobile cards for yachts, companies, berths, invoices, expenses
Five new <EntityCard> files using the shared <ListCard> shell, wired
into each list page's <DataTable> via cardRender. Desktop view
(lg+) is unchanged.
- YachtCard: Ship icon, owner subtitle (User/Building2 icon by
ownerType), dimensions in meters preferred, hull #,
status pill. No accent bar (status is free-text).
- CompanyCard: Building2 icon, legalName subtitle, country (MapPin)
+ tax id (Hash) meta, member/yacht count line.
- BerthCard: Anchor icon, area subtitle (MapPin), dimensions
meta, status pill. Status-encoded accent bar
(emerald=available, amber=under_offer, slate=sold).
- InvoiceCard: FileText icon, client subtitle, due date (Calendar)
meta, prominent currency-formatted amount. Status
accent bar (emerald=paid, orange=overdue, ...).
- ExpenseCard: Receipt icon, category subtitle, expense date meta,
prominent amount, payment-status pill, "Possible
duplicate" pill when duplicateOf is set. Accent bar
by paymentStatus, overridden to amber when flagged
as duplicate.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-01 15:34:04 +02:00
|
|
|
import { YachtCard } from '@/components/yachts/yacht-card';
|
2026-04-24 13:44:15 +02:00
|
|
|
import { YachtForm } from '@/components/yachts/yacht-form';
|
|
|
|
|
import { yachtFilterDefinitions } from '@/components/yachts/yacht-filters';
|
|
|
|
|
import { getYachtColumns, type YachtRow } from '@/components/yachts/yacht-columns';
|
|
|
|
|
import { usePaginatedQuery } from '@/hooks/use-paginated-query';
|
|
|
|
|
import { useRealtimeInvalidation } from '@/hooks/use-realtime-invalidation';
|
|
|
|
|
import { apiFetch } from '@/lib/api/client';
|
|
|
|
|
|
|
|
|
|
export function YachtList() {
|
|
|
|
|
const params = useParams<{ portSlug: string }>();
|
|
|
|
|
const portSlug = params?.portSlug ?? '';
|
|
|
|
|
const queryClient = useQueryClient();
|
|
|
|
|
|
|
|
|
|
const [createOpen, setCreateOpen] = useState(false);
|
|
|
|
|
const [editYacht, setEditYacht] = useState<YachtRow | null>(null);
|
|
|
|
|
const [archiveYacht, setArchiveYacht] = useState<YachtRow | null>(null);
|
2026-05-06 14:58:34 +02:00
|
|
|
const [tagDialog, setTagDialog] = useState<{ ids: string[]; mode: 'add' | 'remove' } | null>(
|
|
|
|
|
null,
|
|
|
|
|
);
|
|
|
|
|
const [tagChoice, setTagChoice] = useState<string[]>([]);
|
|
|
|
|
|
|
|
|
|
const bulkMutation = useMutation({
|
|
|
|
|
mutationFn: async (
|
|
|
|
|
payload:
|
|
|
|
|
| { action: 'archive'; ids: string[] }
|
|
|
|
|
| { action: 'add_tag'; ids: string[]; tagId: string }
|
|
|
|
|
| { action: 'remove_tag'; ids: string[]; tagId: string },
|
|
|
|
|
) =>
|
|
|
|
|
apiFetch<{ data: { summary: { total: number; succeeded: number; failed: number } } }>(
|
|
|
|
|
'/api/v1/yachts/bulk',
|
|
|
|
|
{ method: 'POST', body: payload },
|
|
|
|
|
),
|
|
|
|
|
onSuccess: (res) => {
|
|
|
|
|
queryClient.invalidateQueries({ queryKey: ['yachts'] });
|
|
|
|
|
const s = res.data.summary;
|
|
|
|
|
if (s.failed > 0) {
|
|
|
|
|
alert(`${s.succeeded} of ${s.total} succeeded. ${s.failed} failed.`);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
});
|
2026-04-24 13:44:15 +02:00
|
|
|
|
|
|
|
|
const {
|
|
|
|
|
data,
|
|
|
|
|
pagination,
|
|
|
|
|
isLoading,
|
|
|
|
|
isFetching,
|
|
|
|
|
sort,
|
|
|
|
|
setSort,
|
|
|
|
|
setPage,
|
|
|
|
|
setPageSize,
|
|
|
|
|
filters,
|
|
|
|
|
setFilter,
|
|
|
|
|
clearFilters,
|
|
|
|
|
} = usePaginatedQuery<YachtRow>({
|
|
|
|
|
queryKey: ['yachts'],
|
|
|
|
|
endpoint: '/api/v1/yachts',
|
|
|
|
|
filterDefinitions: yachtFilterDefinitions,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
useRealtimeInvalidation({
|
|
|
|
|
'yacht:created': [['yachts']],
|
|
|
|
|
'yacht:updated': [['yachts']],
|
|
|
|
|
'yacht:archived': [['yachts']],
|
|
|
|
|
'yacht:ownership_transferred': [['yachts']],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const archiveMutation = useMutation({
|
|
|
|
|
mutationFn: (id: string) => apiFetch(`/api/v1/yachts/${id}`, { method: 'DELETE' }),
|
|
|
|
|
onSuccess: () => {
|
|
|
|
|
queryClient.invalidateQueries({ queryKey: ['yachts'] });
|
|
|
|
|
setArchiveYacht(null);
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const columns = getYachtColumns({
|
|
|
|
|
portSlug,
|
|
|
|
|
onEdit: (yacht) => setEditYacht(yacht),
|
|
|
|
|
onArchive: (yacht) => setArchiveYacht(yacht),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="space-y-4">
|
|
|
|
|
<PageHeader
|
|
|
|
|
title="Yachts"
|
|
|
|
|
description="Manage yacht records"
|
2026-04-28 02:52:17 +02:00
|
|
|
variant="gradient"
|
2026-04-24 13:44:15 +02:00
|
|
|
actions={
|
|
|
|
|
<PermissionGate resource="yachts" action="create">
|
|
|
|
|
<Button size="sm" onClick={() => setCreateOpen(true)}>
|
|
|
|
|
<Plus className="mr-1.5 h-4 w-4" />
|
|
|
|
|
New Yacht
|
|
|
|
|
</Button>
|
|
|
|
|
</PermissionGate>
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<FilterBar
|
|
|
|
|
filters={yachtFilterDefinitions}
|
|
|
|
|
values={filters}
|
|
|
|
|
onChange={setFilter}
|
|
|
|
|
onClear={clearFilters}
|
|
|
|
|
/>
|
|
|
|
|
<SavedViewsDropdown
|
|
|
|
|
entityType="yachts"
|
|
|
|
|
currentFilters={filters}
|
|
|
|
|
currentSort={sort}
|
|
|
|
|
onApplyView={(savedFilters, _savedSort) => {
|
|
|
|
|
clearFilters();
|
|
|
|
|
Object.entries(savedFilters).forEach(([key, val]) => setFilter(key, val));
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{isLoading ? (
|
|
|
|
|
<TableSkeleton />
|
|
|
|
|
) : !data.length ? (
|
|
|
|
|
<EmptyState
|
|
|
|
|
title="No yachts found"
|
|
|
|
|
description="Get started by adding your first yacht."
|
|
|
|
|
action={{ label: 'New Yacht', onClick: () => setCreateOpen(true) }}
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<DataTable
|
|
|
|
|
columns={columns}
|
|
|
|
|
data={data}
|
|
|
|
|
pagination={pagination}
|
|
|
|
|
onPaginationChange={(p, ps) => {
|
|
|
|
|
setPage(p);
|
|
|
|
|
setPageSize(ps);
|
|
|
|
|
}}
|
|
|
|
|
sort={sort}
|
|
|
|
|
onSortChange={setSort}
|
|
|
|
|
isLoading={isFetching && !isLoading}
|
|
|
|
|
getRowId={(row) => row.id}
|
2026-05-06 14:58:34 +02:00
|
|
|
bulkActions={[
|
|
|
|
|
{
|
|
|
|
|
label: 'Add tag',
|
|
|
|
|
icon: TagIcon,
|
|
|
|
|
onClick: (ids) => {
|
|
|
|
|
if (ids.length === 0) return;
|
|
|
|
|
setTagChoice([]);
|
|
|
|
|
setTagDialog({ ids, mode: 'add' });
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'Remove tag',
|
|
|
|
|
icon: TagsIcon,
|
|
|
|
|
onClick: (ids) => {
|
|
|
|
|
if (ids.length === 0) return;
|
|
|
|
|
setTagChoice([]);
|
|
|
|
|
setTagDialog({ ids, mode: 'remove' });
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'Archive',
|
|
|
|
|
icon: Archive,
|
|
|
|
|
variant: 'destructive',
|
|
|
|
|
onClick: (ids) => {
|
|
|
|
|
if (ids.length === 0) return;
|
|
|
|
|
if (
|
|
|
|
|
!window.confirm(
|
|
|
|
|
`Archive ${ids.length} yacht${ids.length === 1 ? '' : 's'}? This can be undone from the archived list.`,
|
|
|
|
|
)
|
|
|
|
|
) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
bulkMutation.mutate({ action: 'archive', ids });
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
]}
|
feat(mobile): mobile cards for yachts, companies, berths, invoices, expenses
Five new <EntityCard> files using the shared <ListCard> shell, wired
into each list page's <DataTable> via cardRender. Desktop view
(lg+) is unchanged.
- YachtCard: Ship icon, owner subtitle (User/Building2 icon by
ownerType), dimensions in meters preferred, hull #,
status pill. No accent bar (status is free-text).
- CompanyCard: Building2 icon, legalName subtitle, country (MapPin)
+ tax id (Hash) meta, member/yacht count line.
- BerthCard: Anchor icon, area subtitle (MapPin), dimensions
meta, status pill. Status-encoded accent bar
(emerald=available, amber=under_offer, slate=sold).
- InvoiceCard: FileText icon, client subtitle, due date (Calendar)
meta, prominent currency-formatted amount. Status
accent bar (emerald=paid, orange=overdue, ...).
- ExpenseCard: Receipt icon, category subtitle, expense date meta,
prominent amount, payment-status pill, "Possible
duplicate" pill when duplicateOf is set. Accent bar
by paymentStatus, overridden to amber when flagged
as duplicate.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-01 15:34:04 +02:00
|
|
|
cardRender={(row) => (
|
|
|
|
|
<YachtCard
|
|
|
|
|
yacht={row.original}
|
|
|
|
|
portSlug={portSlug}
|
|
|
|
|
onEdit={setEditYacht}
|
|
|
|
|
onArchive={setArchiveYacht}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2026-04-24 13:44:15 +02:00
|
|
|
emptyState={
|
|
|
|
|
<EmptyState
|
|
|
|
|
title="No yachts found"
|
|
|
|
|
description="Get started by adding your first yacht."
|
|
|
|
|
action={{ label: 'New Yacht', onClick: () => setCreateOpen(true) }}
|
|
|
|
|
/>
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
|
2026-05-06 14:58:34 +02:00
|
|
|
<Dialog open={!!tagDialog} onOpenChange={(o) => !o && setTagDialog(null)}>
|
|
|
|
|
<DialogContent>
|
|
|
|
|
<DialogHeader>
|
|
|
|
|
<DialogTitle>{tagDialog?.mode === 'add' ? 'Add tag' : 'Remove tag'}</DialogTitle>
|
|
|
|
|
<DialogDescription>
|
|
|
|
|
{tagDialog?.mode === 'add'
|
|
|
|
|
? `Add a tag to ${tagDialog?.ids.length ?? 0} selected yacht${tagDialog?.ids.length === 1 ? '' : 's'}.`
|
|
|
|
|
: `Remove a tag from ${tagDialog?.ids.length ?? 0} selected yacht${tagDialog?.ids.length === 1 ? '' : 's'}. Yachts without the tag are unchanged.`}
|
|
|
|
|
</DialogDescription>
|
|
|
|
|
</DialogHeader>
|
|
|
|
|
<div className="py-2">
|
|
|
|
|
<TagPicker
|
|
|
|
|
selectedIds={tagChoice}
|
|
|
|
|
onChange={(ids) => setTagChoice(ids.slice(-1))}
|
|
|
|
|
placeholder="Pick one tag…"
|
|
|
|
|
/>
|
|
|
|
|
<p className="text-xs text-muted-foreground mt-2">
|
|
|
|
|
Pick a single tag. To apply multiple tags, run the action once per tag.
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
<DialogFooter>
|
|
|
|
|
<Button variant="outline" onClick={() => setTagDialog(null)}>
|
|
|
|
|
Cancel
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
disabled={bulkMutation.isPending || tagChoice.length === 0}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
if (!tagDialog || tagChoice.length === 0) return;
|
|
|
|
|
const tagId = tagChoice[0];
|
|
|
|
|
if (!tagId) return;
|
|
|
|
|
bulkMutation.mutate(
|
|
|
|
|
{
|
|
|
|
|
action: tagDialog.mode === 'add' ? 'add_tag' : 'remove_tag',
|
|
|
|
|
ids: tagDialog.ids,
|
|
|
|
|
tagId,
|
|
|
|
|
},
|
|
|
|
|
{ onSettled: () => setTagDialog(null) },
|
|
|
|
|
);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
Apply
|
|
|
|
|
</Button>
|
|
|
|
|
</DialogFooter>
|
|
|
|
|
</DialogContent>
|
|
|
|
|
</Dialog>
|
|
|
|
|
|
2026-04-24 13:44:15 +02:00
|
|
|
<YachtForm open={createOpen} onOpenChange={setCreateOpen} />
|
|
|
|
|
|
|
|
|
|
{editYacht && (
|
|
|
|
|
<YachtForm
|
|
|
|
|
open={!!editYacht}
|
|
|
|
|
onOpenChange={(open) => !open && setEditYacht(null)}
|
|
|
|
|
yacht={{
|
|
|
|
|
id: editYacht.id,
|
|
|
|
|
name: editYacht.name,
|
|
|
|
|
hullNumber: editYacht.hullNumber,
|
|
|
|
|
registration: editYacht.registration,
|
|
|
|
|
lengthFt: editYacht.lengthFt,
|
|
|
|
|
widthFt: editYacht.widthFt,
|
|
|
|
|
draftFt: editYacht.draftFt,
|
|
|
|
|
lengthM: editYacht.lengthM,
|
|
|
|
|
widthM: editYacht.widthM,
|
|
|
|
|
currentOwnerType: editYacht.currentOwnerType,
|
|
|
|
|
currentOwnerId: editYacht.currentOwnerId,
|
|
|
|
|
status: editYacht.status,
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
<ArchiveConfirmDialog
|
|
|
|
|
open={!!archiveYacht}
|
|
|
|
|
onOpenChange={(open) => !open && setArchiveYacht(null)}
|
|
|
|
|
entityName={archiveYacht?.name ?? ''}
|
|
|
|
|
entityType="Yacht"
|
|
|
|
|
isArchived={false}
|
|
|
|
|
onConfirm={() => archiveYacht && archiveMutation.mutate(archiveYacht.id)}
|
|
|
|
|
isLoading={archiveMutation.isPending}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|