feat(platform): residential module + admin UI + reliability fixes
Residential platform - New schema: residentialClients, residentialInterests (separate from marina/yacht clients) with migration 0010 - Service layer with CRUD + audit + sockets + per-port portal toggle - v1 + public API routes (/api/v1/residential/*, /api/public/residential-inquiries) - List + detail pages with inline editing for clients and interests - Per-user residentialAccess toggle on userPortRoles (migration 0011) - Permission keys: residential_clients, residential_interests - Sidebar nav + role form integration - Smoke spec covering page loads, UI create flow, public endpoint Admin & shared UI - Admin → Forms (form templates CRUD) with validators + service - Notification preferences page (in-app + email per type) - Email composition + accounts list + threads view - Branded auth shell shared across CRM + portal auth surfaces - Inline editing extended to yacht/company/interest detail pages - InlineTagEditor + per-entity tags endpoints (yachts, companies) - Notes service polymorphic across clients/interests/yachts/companies - Client list columns: yachtCount + companyCount badges - Reservation file-download via presigned URL (replaces stale <a href>) Route handler refactor - Extracted yachts/companies/berths reservation handlers to sibling handlers.ts files (Next.js 15 route.ts only allows specific exports) Reliability fixes - apiFetch double-stringify bug fixed across 13 components (apiFetch already JSON.stringifies its body; passing a stringified body produced double-encoded JSON which failed zod validation) - SocketProvider gated behind useSyncExternalStore-based mount check to avoid useSession() SSR crashes under React 19 + Next 15 - apiFetch falls back to URL-pathname → port-id resolution when the Zustand store hasn't hydrated yet (fresh contexts, e2e tests) - CRM invite flow (schema, service, route, email, dev script) - Dashboard route → [portSlug]/dashboard/page.tsx + redirect - Document the dev-server restart-after-migration gotcha in CLAUDE.md Tests - 5-case residential smoke spec - Integration test updates for new service signatures Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,9 +1,31 @@
|
||||
'use client';
|
||||
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
|
||||
import type { DetailTab } from '@/components/shared/detail-layout';
|
||||
import { EmptyState } from '@/components/shared/empty-state';
|
||||
import { InlineEditableField } from '@/components/shared/inline-editable-field';
|
||||
import { InlineTagEditor } from '@/components/shared/inline-tag-editor';
|
||||
import { NotesList } from '@/components/shared/notes-list';
|
||||
import { CompanyMembersTab } from '@/components/companies/company-members-tab';
|
||||
import { CompanyOwnedYachtsTab } from '@/components/companies/company-owned-yachts-tab';
|
||||
import { apiFetch } from '@/lib/api/client';
|
||||
|
||||
type CompanyPatchField =
|
||||
| 'name'
|
||||
| 'legalName'
|
||||
| 'taxId'
|
||||
| 'registrationNumber'
|
||||
| 'incorporationCountry'
|
||||
| 'incorporationDate'
|
||||
| 'status'
|
||||
| 'billingEmail'
|
||||
| 'notes';
|
||||
|
||||
const STATUS_OPTIONS = [
|
||||
{ value: 'active', label: 'Active' },
|
||||
{ value: 'dissolved', label: 'Dissolved' },
|
||||
];
|
||||
|
||||
interface CompanyTabsCompany {
|
||||
id: string;
|
||||
@@ -16,6 +38,7 @@ interface CompanyTabsCompany {
|
||||
status: string;
|
||||
billingEmail: string | null;
|
||||
notes: string | null;
|
||||
tags?: Array<{ id: string; name: string; color: string }>;
|
||||
}
|
||||
|
||||
interface CompanyTabsOptions {
|
||||
@@ -25,30 +48,34 @@ interface CompanyTabsOptions {
|
||||
company: CompanyTabsCompany;
|
||||
}
|
||||
|
||||
const STATUS_LABELS: Record<string, string> = {
|
||||
active: 'Active',
|
||||
dissolved: 'Dissolved',
|
||||
};
|
||||
function useCompanyPatch(companyId: string) {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async (patch: Partial<Record<CompanyPatchField, string | null>>) =>
|
||||
apiFetch(`/api/v1/companies/${companyId}`, {
|
||||
method: 'PATCH',
|
||||
body: patch,
|
||||
}),
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries({ queryKey: ['companies', companyId] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function InfoRow({ label, value }: { label: string; value?: string | number | null }) {
|
||||
if (value === null || value === undefined || value === '') return null;
|
||||
function EditableRow({ label, children }: { label: string; children: React.ReactNode }) {
|
||||
return (
|
||||
<div className="flex gap-2 py-1.5 border-b last:border-0">
|
||||
<div className="flex gap-2 py-1.5 border-b last:border-0 items-center">
|
||||
<dt className="w-40 shrink-0 text-sm text-muted-foreground">{label}</dt>
|
||||
<dd className="text-sm">{value}</dd>
|
||||
<dd className="flex-1 min-w-0">{children}</dd>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function formatDate(value: string | null): string | null {
|
||||
if (!value) return null;
|
||||
const date = new Date(value);
|
||||
if (Number.isNaN(date.getTime())) return value;
|
||||
return date.toLocaleDateString();
|
||||
}
|
||||
|
||||
function OverviewTab({ company }: { company: CompanyTabsCompany }) {
|
||||
const incorporationDate = formatDate(company.incorporationDate);
|
||||
function OverviewTab({ companyId, company }: { companyId: string; company: CompanyTabsCompany }) {
|
||||
const mutation = useCompanyPatch(companyId);
|
||||
const save = (field: CompanyPatchField) => async (next: string | null) => {
|
||||
await mutation.mutateAsync({ [field]: next });
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
@@ -56,47 +83,82 @@ function OverviewTab({ company }: { company: CompanyTabsCompany }) {
|
||||
<div className="space-y-1">
|
||||
<h3 className="text-sm font-medium mb-2">Identity</h3>
|
||||
<dl>
|
||||
<InfoRow label="Name" value={company.name} />
|
||||
<InfoRow label="Legal Name" value={company.legalName} />
|
||||
<InfoRow label="Status" value={STATUS_LABELS[company.status] ?? company.status} />
|
||||
<EditableRow label="Name">
|
||||
<InlineEditableField value={company.name} onSave={save('name')} />
|
||||
</EditableRow>
|
||||
<EditableRow label="Legal Name">
|
||||
<InlineEditableField value={company.legalName} onSave={save('legalName')} />
|
||||
</EditableRow>
|
||||
<EditableRow label="Status">
|
||||
<InlineEditableField
|
||||
variant="select"
|
||||
options={STATUS_OPTIONS}
|
||||
value={company.status}
|
||||
onSave={save('status')}
|
||||
/>
|
||||
</EditableRow>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
{/* Registration */}
|
||||
{(company.taxId ||
|
||||
company.registrationNumber ||
|
||||
company.incorporationCountry ||
|
||||
incorporationDate) && (
|
||||
<div className="space-y-1">
|
||||
<h3 className="text-sm font-medium mb-2">Registration</h3>
|
||||
<dl>
|
||||
<InfoRow label="Tax ID" value={company.taxId} />
|
||||
<InfoRow label="Registration Number" value={company.registrationNumber} />
|
||||
<InfoRow label="Incorporation Country" value={company.incorporationCountry} />
|
||||
<InfoRow label="Incorporation Date" value={incorporationDate} />
|
||||
</dl>
|
||||
</div>
|
||||
)}
|
||||
<div className="space-y-1">
|
||||
<h3 className="text-sm font-medium mb-2">Registration</h3>
|
||||
<dl>
|
||||
<EditableRow label="Tax ID">
|
||||
<InlineEditableField value={company.taxId} onSave={save('taxId')} />
|
||||
</EditableRow>
|
||||
<EditableRow label="Registration Number">
|
||||
<InlineEditableField
|
||||
value={company.registrationNumber}
|
||||
onSave={save('registrationNumber')}
|
||||
/>
|
||||
</EditableRow>
|
||||
<EditableRow label="Incorporation Country">
|
||||
<InlineEditableField
|
||||
value={company.incorporationCountry}
|
||||
onSave={save('incorporationCountry')}
|
||||
/>
|
||||
</EditableRow>
|
||||
<EditableRow label="Incorporation Date">
|
||||
<InlineEditableField
|
||||
value={company.incorporationDate}
|
||||
placeholder="YYYY-MM-DD"
|
||||
onSave={save('incorporationDate')}
|
||||
/>
|
||||
</EditableRow>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
{/* Contact */}
|
||||
{company.billingEmail && (
|
||||
<div className="space-y-1">
|
||||
<h3 className="text-sm font-medium mb-2">Contact</h3>
|
||||
<dl>
|
||||
<InfoRow label="Billing Email" value={company.billingEmail} />
|
||||
</dl>
|
||||
</div>
|
||||
)}
|
||||
<div className="space-y-1">
|
||||
<h3 className="text-sm font-medium mb-2">Contact</h3>
|
||||
<dl>
|
||||
<EditableRow label="Billing Email">
|
||||
<InlineEditableField value={company.billingEmail} onSave={save('billingEmail')} />
|
||||
</EditableRow>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
{/* Notes */}
|
||||
{company.notes && (
|
||||
<div className="space-y-1 md:col-span-2">
|
||||
<h3 className="text-sm font-medium mb-2">Notes</h3>
|
||||
<p className="text-sm whitespace-pre-wrap rounded-md border bg-muted/30 p-3">
|
||||
{company.notes}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
<div className="space-y-1 md:col-span-2">
|
||||
<h3 className="text-sm font-medium mb-2">Notes</h3>
|
||||
<InlineEditableField
|
||||
variant="textarea"
|
||||
value={company.notes}
|
||||
onSave={save('notes')}
|
||||
emptyText="No notes — click to add"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Tags */}
|
||||
<div className="space-y-1 md:col-span-2">
|
||||
<h3 className="text-sm font-medium mb-2">Tags</h3>
|
||||
<InlineTagEditor
|
||||
endpoint={`/api/v1/companies/${companyId}/tags`}
|
||||
currentTags={company.tags ?? []}
|
||||
invalidateKey={['companies', companyId]}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -104,17 +166,14 @@ function OverviewTab({ company }: { company: CompanyTabsCompany }) {
|
||||
export function getCompanyTabs({
|
||||
companyId,
|
||||
portSlug,
|
||||
// currentUserId reserved for when NotesList supports entityType='companies'.
|
||||
currentUserId: _currentUserId,
|
||||
currentUserId,
|
||||
company,
|
||||
}: CompanyTabsOptions): DetailTab[] {
|
||||
void _currentUserId;
|
||||
|
||||
return [
|
||||
{
|
||||
id: 'overview',
|
||||
label: 'Overview',
|
||||
content: <OverviewTab company={company} />,
|
||||
content: <OverviewTab companyId={companyId} company={company} />,
|
||||
},
|
||||
{
|
||||
id: 'members',
|
||||
@@ -129,7 +188,6 @@ export function getCompanyTabs({
|
||||
{
|
||||
id: 'addresses',
|
||||
label: 'Addresses',
|
||||
// TODO: wire to future company-addresses endpoint (see company-addresses schema).
|
||||
content: (
|
||||
<EmptyState
|
||||
title="Addresses"
|
||||
@@ -145,22 +203,8 @@ export function getCompanyTabs({
|
||||
{
|
||||
id: 'notes',
|
||||
label: 'Notes',
|
||||
// TODO: NotesList currently supports entityType 'clients' | 'interests'.
|
||||
// Extend NotesList (or swap to a company-notes endpoint) in a follow-up.
|
||||
content: (
|
||||
<EmptyState
|
||||
title="Notes"
|
||||
description="Company notes coming soon — the notes endpoint is pending wiring."
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'tags',
|
||||
label: 'Tags',
|
||||
// TODO: replace with an inline tag editor once one exists; company tags
|
||||
// can be edited via the Edit form in the meantime.
|
||||
content: (
|
||||
<EmptyState title="Tags" description="Manage tags from the Edit company form for now." />
|
||||
<NotesList entityType="companies" entityId={companyId} currentUserId={currentUserId} />
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user