Address the CRITICAL and high-leverage HIGH items from the onboarding-auditor report: **C1 — checklist auto-checks were reading the wrong setting keys** A port that had actually been configured still showed three steps as incomplete, permanently capping the checklist at < 70 %. - email step: `sales_email_smtp_host` → `smtp_host_override` (the key the email admin page actually persists). - documenso step: `documenso_api_url` → compound gate `documenso_api_url_override` + `documenso_developer_email` + `documenso_approver_email` + `documenso_eoi_template_id`. All four are required for `buildDocumensoPayload` not to error out; checking only the URL falsely greenlit the step until a rep tried to send an EOI and Documenso 404'd. - settings step: `recommender_top_n_default` → `heat_weight_recency`. The defaults are layered (port > global > built-in), so a port using the built-ins never writes the `top_n_default` row — old key was an unreachable green. heat_weight_recency genuinely means "admin tuned the recommender". **C2 — forms step href was broken** `STEPS[8].href = '../'` resolved through the Link template to the dashboard, not `/admin/forms`. Fixed to `'forms'`. **C3 — EOI signer-identity gate** Folded into the new compound-gate logic on the documenso step (see C1). Now matches what the EOI pipeline actually requires before it can send. **C4 — ensureSystemRoots failure mode poisoned port creation** `ports.service.createPort` awaited `ensureSystemRoots` after the port row had committed, so a throw bubbled out as a 500 even though the inline comment said "non-fatal if this throws". Wrap in try/catch + logger.warn — the row stays live, the next admin action self-heals via `ensureEntityFolder`, and the operator doesn't retry into a 409. **H5 — berth-list empty-state copy misleads fresh ports** "Berths are imported from external sources. Adjust your filters..." implied data existed but was hidden. Branch on whether any filter is active: with none, suggest running `import-berths-from-nocodb.ts`; with filters, the original "adjust filters" message. **M4 — admin-sections-browser description was wrong** "Setup checklist for fresh ports (read-only references)" implied the page was read-only when it has working manual-completion checkboxes and discouraged clicking in. Reworded. Additionally, the OnboardingStep type gains an optional `autoCheckSettingKeysAll` field for compound gates (used by the documenso step), and the auto-detected hint shows all keys when the gate is compound. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
149 lines
5.5 KiB
TypeScript
149 lines
5.5 KiB
TypeScript
'use client';
|
|
|
|
import { useRouter, useParams } from 'next/navigation';
|
|
import { Anchor } from 'lucide-react';
|
|
|
|
import { DataTable } from '@/components/shared/data-table';
|
|
import { FilterBar } from '@/components/shared/filter-bar';
|
|
import { PageHeader } from '@/components/shared/page-header';
|
|
import { SavedViewsDropdown } from '@/components/shared/saved-views-dropdown';
|
|
import { ColumnPicker } from '@/components/shared/column-picker';
|
|
import { Input } from '@/components/ui/input';
|
|
import { EmptyState } from '@/components/shared/empty-state';
|
|
import { usePaginatedQuery } from '@/hooks/use-paginated-query';
|
|
import { useRealtimeInvalidation } from '@/hooks/use-realtime-invalidation';
|
|
import { useTablePreferences } from '@/hooks/use-table-preferences';
|
|
import { BerthCard } from './berth-card';
|
|
import {
|
|
berthColumns,
|
|
BERTH_COLUMN_OPTIONS,
|
|
BERTH_DEFAULT_HIDDEN,
|
|
type BerthRow,
|
|
} from './berth-columns';
|
|
import { berthFilterDefinitions } from './berth-filters';
|
|
import { mooringLetterTone } from './mooring-letter-tone';
|
|
|
|
export function BerthList() {
|
|
const router = useRouter();
|
|
const params = useParams<{ portSlug: string }>();
|
|
|
|
const {
|
|
data,
|
|
pagination,
|
|
isLoading,
|
|
sort,
|
|
setSort,
|
|
filters,
|
|
setFilter,
|
|
clearFilters,
|
|
setPage,
|
|
setPageSize,
|
|
} = usePaginatedQuery<BerthRow>({
|
|
queryKey: ['berths'],
|
|
endpoint: '/api/v1/berths',
|
|
filterDefinitions: berthFilterDefinitions,
|
|
});
|
|
|
|
useRealtimeInvalidation({
|
|
'berth:updated': [['berths']],
|
|
'berth:statusChanged': [['berths']],
|
|
});
|
|
|
|
// Persisted column visibility — same pattern as ClientList / InterestList.
|
|
const { hidden, setHidden } = useTablePreferences('berths', BERTH_DEFAULT_HIDDEN);
|
|
const columnVisibility = Object.fromEntries(hidden.map((id) => [id, false]));
|
|
|
|
return (
|
|
<div className="space-y-6">
|
|
<PageHeader
|
|
title="Berths"
|
|
description="View and manage berth allocations"
|
|
variant="gradient"
|
|
// No "New" button - berths are import-only
|
|
/>
|
|
|
|
<div className="flex items-center gap-2 flex-wrap">
|
|
<FilterBar
|
|
// Search is hoisted out of the popover into the inline input
|
|
// below — keeps the daily "find by mooring/area" lookup one
|
|
// tap away instead of buried behind the Filters dropdown.
|
|
filters={berthFilterDefinitions.filter((d) => d.key !== 'search')}
|
|
values={filters}
|
|
onChange={setFilter}
|
|
onClear={clearFilters}
|
|
/>
|
|
<Input
|
|
type="search"
|
|
inputMode="search"
|
|
placeholder="Search mooring or area…"
|
|
aria-label="Search berths"
|
|
value={(filters.search as string | undefined) ?? ''}
|
|
onChange={(e) => setFilter('search', e.target.value || undefined)}
|
|
// flex-1 + min-w-0 lets the input expand to fill the row's
|
|
// remaining width on mobile (where space is at a premium).
|
|
// sm:max-w-xs caps it at 320px on desktop so it doesn't grow
|
|
// absurdly wide on a 2k monitor.
|
|
className="h-8 min-w-0 flex-1 sm:max-w-xs"
|
|
/>
|
|
<div className="ml-auto flex items-center gap-2">
|
|
<SavedViewsDropdown
|
|
entityType="berths"
|
|
onApplyView={(savedFilters, _savedSort) => {
|
|
clearFilters();
|
|
Object.entries(savedFilters).forEach(([key, value]) => setFilter(key, value));
|
|
}}
|
|
/>
|
|
<ColumnPicker columns={BERTH_COLUMN_OPTIONS} hidden={hidden} onChange={setHidden} />
|
|
</div>
|
|
</div>
|
|
|
|
<DataTable<BerthRow>
|
|
columns={berthColumns}
|
|
columnVisibility={columnVisibility}
|
|
data={data}
|
|
isLoading={isLoading}
|
|
pagination={{
|
|
page: pagination.page,
|
|
pageSize: pagination.pageSize,
|
|
total: pagination.total,
|
|
totalPages: pagination.totalPages,
|
|
}}
|
|
onPaginationChange={(page, pageSize) => {
|
|
setPage(page);
|
|
setPageSize(pageSize);
|
|
}}
|
|
sort={sort}
|
|
onSortChange={setSort}
|
|
getRowId={(row) => row.id}
|
|
onRowClick={(row) => router.push(`/${params.portSlug}/berths/${row.id}`)}
|
|
getRowClassName={(row) => mooringLetterTone(row.mooringNumber)}
|
|
cardRender={(row) => <BerthCard berth={row.original} />}
|
|
// Group adjacent cards by dock letter (area) on mobile — adds a
|
|
// dim divider + uppercased label above the first card of each
|
|
// group. Data is already sorted by mooringNumber (A1, A2, …, B1,
|
|
// B2, …) so consecutive rows naturally share dock letters.
|
|
mobileGroupBy={(row) => row.area ?? 'Unassigned'}
|
|
emptyState={
|
|
// Distinguish "no data at all" (fresh port, run the importer)
|
|
// from "no rows after filtering" (adjust filters). The original
|
|
// copy implied data existed but was hidden, which misled fresh-
|
|
// port admins for whom there is literally nothing yet.
|
|
Object.values(filters).every((v) => v === undefined || v === '') ? (
|
|
<EmptyState
|
|
icon={Anchor}
|
|
title="No berths yet"
|
|
description="Berths are imported from external sources. Run the importer once the source data is ready: pnpm tsx scripts/import-berths-from-nocodb.ts --apply --port-slug <slug>."
|
|
/>
|
|
) : (
|
|
<EmptyState
|
|
icon={Anchor}
|
|
title="No berths match these filters"
|
|
description="Adjust your filters or clear them to see every berth."
|
|
/>
|
|
)
|
|
}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|