feat(tenancies-p6): module-gate entity tabs (berth / client / yacht)
- PortProvider exposes tenanciesModuleByPort + a useTenanciesModuleEnabled() hook that returns the flag for the currently-active port. Synchronous read off context (server-resolved in the dashboard layout), so no fetch latency / hydration flicker when the rep flips ports. - buildBerthTabs / getClientTabs / getYachtTabs gain a tenanciesModuleEnabled option. When false, the Tenancies tab is filtered out entirely. When true, it slots into the entity-specific position (after Interests on berth + yacht; after Companies on client). - BerthDetail / ClientDetail / YachtDetail pass the hook value through. Hook call ordered above the early-return so React's rules-of-hooks stays satisfied. Existing read-only tab content (Active tenancy card + History + the berth-side BerthReserveDialog "Create tenancy" CTA from P2) stays untouched — it just becomes visible when the module is on. Deferred (separate ship): generic TenancyCreateDialog that pre-fills clientId / yachtId from the parent entity context, so client / yacht tabs can mint a tenancy without bouncing through the berth detail page. Today client/yacht Tenancies tabs are read-only (the create entry-point is the berth tab); the generic dialog will land alongside the Edit / Renew / Transfer / End dialogs (design § P6 sub-tasks). Verified: tsc clean, 1493/1493 vitest. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -91,7 +91,11 @@ export default async function DashboardLayout({ children }: { children: React.Re
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<QueryProvider>
|
<QueryProvider>
|
||||||
<PortProvider ports={ports} defaultPortId={ports[0]?.id ?? null}>
|
<PortProvider
|
||||||
|
ports={ports}
|
||||||
|
defaultPortId={ports[0]?.id ?? null}
|
||||||
|
tenanciesModuleByPort={tenanciesModuleByPort}
|
||||||
|
>
|
||||||
<PermissionsProvider>
|
<PermissionsProvider>
|
||||||
<SocketProvider>
|
<SocketProvider>
|
||||||
<RealtimeToasts />
|
<RealtimeToasts />
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { DetailLayout } from '@/components/shared/detail-layout';
|
|||||||
import { DetailNotFound } from '@/components/shared/detail-not-found';
|
import { DetailNotFound } from '@/components/shared/detail-not-found';
|
||||||
import { useMobileChrome } from '@/components/layout/mobile/mobile-layout-provider';
|
import { useMobileChrome } from '@/components/layout/mobile/mobile-layout-provider';
|
||||||
import { apiFetch } from '@/lib/api/client';
|
import { apiFetch } from '@/lib/api/client';
|
||||||
|
import { useTenanciesModuleEnabled } from '@/providers/port-provider';
|
||||||
import { useRealtimeInvalidation } from '@/hooks/use-realtime-invalidation';
|
import { useRealtimeInvalidation } from '@/hooks/use-realtime-invalidation';
|
||||||
import { BerthDetailHeader, type BerthDetailData } from './berth-detail-header';
|
import { BerthDetailHeader, type BerthDetailData } from './berth-detail-header';
|
||||||
import { BerthForm } from './berth-form';
|
import { BerthForm } from './berth-form';
|
||||||
@@ -20,6 +21,7 @@ interface BerthDetailProps {
|
|||||||
export function BerthDetail({ berthId }: BerthDetailProps) {
|
export function BerthDetail({ berthId }: BerthDetailProps) {
|
||||||
const params = useParams<{ portSlug: string }>();
|
const params = useParams<{ portSlug: string }>();
|
||||||
const portSlug = params?.portSlug ?? '';
|
const portSlug = params?.portSlug ?? '';
|
||||||
|
const tenanciesModuleEnabled = useTenanciesModuleEnabled();
|
||||||
|
|
||||||
const { data, isLoading, error } = useQuery<BerthDetailData>({
|
const { data, isLoading, error } = useQuery<BerthDetailData>({
|
||||||
queryKey: ['berth', berthId],
|
queryKey: ['berth', berthId],
|
||||||
@@ -84,7 +86,7 @@ export function BerthDetail({ berthId }: BerthDetailProps) {
|
|||||||
<DetailLayout
|
<DetailLayout
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
header={berth ? <BerthDetailHeader berth={berth} /> : null}
|
header={berth ? <BerthDetailHeader berth={berth} /> : null}
|
||||||
tabs={berth ? buildBerthTabs(berth) : []}
|
tabs={berth ? buildBerthTabs(berth, { tenanciesModuleEnabled }) : []}
|
||||||
defaultTab="overview"
|
defaultTab="overview"
|
||||||
/>
|
/>
|
||||||
{berth ? <BerthForm berth={berth} open={editOpen} onOpenChange={setEditOpen} /> : null}
|
{berth ? <BerthForm berth={berth} open={editOpen} onOpenChange={setEditOpen} /> : null}
|
||||||
|
|||||||
@@ -419,8 +419,11 @@ function OverviewTab({ berth }: { berth: BerthData }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function buildBerthTabs(berth: BerthData): DetailTab[] {
|
export function buildBerthTabs(
|
||||||
return [
|
berth: BerthData,
|
||||||
|
opts: { tenanciesModuleEnabled: boolean } = { tenanciesModuleEnabled: false },
|
||||||
|
): DetailTab[] {
|
||||||
|
const tabs: DetailTab[] = [
|
||||||
{
|
{
|
||||||
id: 'overview',
|
id: 'overview',
|
||||||
label: 'Overview',
|
label: 'Overview',
|
||||||
@@ -431,11 +434,20 @@ export function buildBerthTabs(berth: BerthData): DetailTab[] {
|
|||||||
label: 'Interests',
|
label: 'Interests',
|
||||||
content: <BerthInterestsTab berthId={berth.id} />,
|
content: <BerthInterestsTab berthId={berth.id} />,
|
||||||
},
|
},
|
||||||
{
|
];
|
||||||
|
if (opts.tenanciesModuleEnabled) {
|
||||||
|
tabs.push({
|
||||||
id: 'tenancies',
|
id: 'tenancies',
|
||||||
label: 'Tenancies',
|
label: 'Tenancies',
|
||||||
content: <BerthTenanciesTab berthId={berth.id} />,
|
content: <BerthTenanciesTab berthId={berth.id} />,
|
||||||
},
|
});
|
||||||
|
}
|
||||||
|
tabs.push(...buildBerthDetailRemainder(berth));
|
||||||
|
return tabs;
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildBerthDetailRemainder(berth: BerthData): DetailTab[] {
|
||||||
|
return [
|
||||||
{
|
{
|
||||||
id: 'spec',
|
id: 'spec',
|
||||||
label: 'Spec',
|
label: 'Spec',
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { DetailNotFound } from '@/components/shared/detail-not-found';
|
|||||||
import { useMobileChrome } from '@/components/layout/mobile/mobile-layout-provider';
|
import { useMobileChrome } from '@/components/layout/mobile/mobile-layout-provider';
|
||||||
import { ClientDetailHeader } from '@/components/clients/client-detail-header';
|
import { ClientDetailHeader } from '@/components/clients/client-detail-header';
|
||||||
import { getClientTabs } from '@/components/clients/client-tabs';
|
import { getClientTabs } from '@/components/clients/client-tabs';
|
||||||
|
import { useTenanciesModuleEnabled } from '@/providers/port-provider';
|
||||||
import { useRealtimeInvalidation } from '@/hooks/use-realtime-invalidation';
|
import { useRealtimeInvalidation } from '@/hooks/use-realtime-invalidation';
|
||||||
import { useBreadcrumbHint } from '@/hooks/use-breadcrumb-hint';
|
import { useBreadcrumbHint } from '@/hooks/use-breadcrumb-hint';
|
||||||
import { apiFetch } from '@/lib/api/client';
|
import { apiFetch } from '@/lib/api/client';
|
||||||
@@ -118,6 +119,8 @@ export function ClientDetail({ clientId, currentUserId }: ClientDetailProps) {
|
|||||||
'berth_tenancy:cancelled': [['clients', clientId]],
|
'berth_tenancy:cancelled': [['clients', clientId]],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const tenanciesModuleEnabled = useTenanciesModuleEnabled();
|
||||||
|
|
||||||
if (error && !isLoading) {
|
if (error && !isLoading) {
|
||||||
const status = (error as { status?: number } | null | undefined)?.status;
|
const status = (error as { status?: number } | null | undefined)?.status;
|
||||||
return (
|
return (
|
||||||
@@ -130,7 +133,9 @@ export function ClientDetail({ clientId, currentUserId }: ClientDetailProps) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const tabs = data ? getClientTabs({ clientId, currentUserId, client: data }) : [];
|
const tabs = data
|
||||||
|
? getClientTabs({ clientId, currentUserId, client: data, tenanciesModuleEnabled })
|
||||||
|
: [];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DetailLayout
|
<DetailLayout
|
||||||
|
|||||||
@@ -250,8 +250,13 @@ function OverviewTab({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getClientTabs({ clientId, currentUserId, client }: ClientTabsOptions): DetailTab[] {
|
export function getClientTabs({
|
||||||
return [
|
clientId,
|
||||||
|
currentUserId,
|
||||||
|
client,
|
||||||
|
tenanciesModuleEnabled = false,
|
||||||
|
}: ClientTabsOptions & { tenanciesModuleEnabled?: boolean }): DetailTab[] {
|
||||||
|
const tabs: DetailTab[] = [
|
||||||
{
|
{
|
||||||
id: 'overview',
|
id: 'overview',
|
||||||
label: 'Overview',
|
label: 'Overview',
|
||||||
@@ -275,12 +280,6 @@ export function getClientTabs({ clientId, currentUserId, client }: ClientTabsOpt
|
|||||||
badge: client.companies.length,
|
badge: client.companies.length,
|
||||||
content: <ClientCompaniesTab clientId={clientId} companies={client.companies} />,
|
content: <ClientCompaniesTab clientId={clientId} companies={client.companies} />,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
id: 'tenancies',
|
|
||||||
label: 'Tenancies',
|
|
||||||
badge: client.activeTenancies.length,
|
|
||||||
content: <ClientTenanciesTab clientId={clientId} activeTenancies={client.activeTenancies} />,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
id: 'addresses',
|
id: 'addresses',
|
||||||
label: 'Addresses',
|
label: 'Addresses',
|
||||||
@@ -323,4 +322,15 @@ export function getClientTabs({ clientId, currentUserId, client }: ClientTabsOpt
|
|||||||
),
|
),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
if (tenanciesModuleEnabled) {
|
||||||
|
// Insert the Tenancies tab after Companies (index 4) so the entity
|
||||||
|
// ordering reads: Overview → Interests → Yachts → Companies → Tenancies.
|
||||||
|
tabs.splice(4, 0, {
|
||||||
|
id: 'tenancies',
|
||||||
|
label: 'Tenancies',
|
||||||
|
badge: client.activeTenancies.length,
|
||||||
|
content: <ClientTenanciesTab clientId={clientId} activeTenancies={client.activeTenancies} />,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return tabs;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { DetailNotFound } from '@/components/shared/detail-not-found';
|
|||||||
import { useMobileChrome } from '@/components/layout/mobile/mobile-layout-provider';
|
import { useMobileChrome } from '@/components/layout/mobile/mobile-layout-provider';
|
||||||
import { YachtDetailHeader } from '@/components/yachts/yacht-detail-header';
|
import { YachtDetailHeader } from '@/components/yachts/yacht-detail-header';
|
||||||
import { getYachtTabs } from '@/components/yachts/yacht-tabs';
|
import { getYachtTabs } from '@/components/yachts/yacht-tabs';
|
||||||
|
import { useTenanciesModuleEnabled } from '@/providers/port-provider';
|
||||||
import { useRealtimeInvalidation } from '@/hooks/use-realtime-invalidation';
|
import { useRealtimeInvalidation } from '@/hooks/use-realtime-invalidation';
|
||||||
import { useBreadcrumbHint } from '@/hooks/use-breadcrumb-hint';
|
import { useBreadcrumbHint } from '@/hooks/use-breadcrumb-hint';
|
||||||
import { apiFetch } from '@/lib/api/client';
|
import { apiFetch } from '@/lib/api/client';
|
||||||
@@ -79,6 +80,8 @@ export function YachtDetail({ yachtId, currentUserId }: YachtDetailProps) {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const tenanciesModuleEnabled = useTenanciesModuleEnabled();
|
||||||
|
|
||||||
if (error && !isLoading) {
|
if (error && !isLoading) {
|
||||||
const status = (error as { status?: number } | null | undefined)?.status;
|
const status = (error as { status?: number } | null | undefined)?.status;
|
||||||
return (
|
return (
|
||||||
@@ -91,7 +94,9 @@ export function YachtDetail({ yachtId, currentUserId }: YachtDetailProps) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const tabs = data ? getYachtTabs({ yachtId, currentUserId, yacht: data }) : [];
|
const tabs = data
|
||||||
|
? getYachtTabs({ yachtId, currentUserId, yacht: data, tenanciesModuleEnabled })
|
||||||
|
: [];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DetailLayout
|
<DetailLayout
|
||||||
|
|||||||
@@ -355,8 +355,13 @@ function YachtTenanciesTab({ yachtId }: { yachtId: string }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getYachtTabs({ yachtId, currentUserId, yacht }: YachtTabsOptions): DetailTab[] {
|
export function getYachtTabs({
|
||||||
return [
|
yachtId,
|
||||||
|
currentUserId,
|
||||||
|
yacht,
|
||||||
|
tenanciesModuleEnabled = false,
|
||||||
|
}: YachtTabsOptions & { tenanciesModuleEnabled?: boolean }): DetailTab[] {
|
||||||
|
const tabs: DetailTab[] = [
|
||||||
{
|
{
|
||||||
id: 'overview',
|
id: 'overview',
|
||||||
label: 'Overview',
|
label: 'Overview',
|
||||||
@@ -372,11 +377,6 @@ export function getYachtTabs({ yachtId, currentUserId, yacht }: YachtTabsOptions
|
|||||||
label: 'Interests',
|
label: 'Interests',
|
||||||
content: <YachtInterestsTab yachtId={yachtId} />,
|
content: <YachtInterestsTab yachtId={yachtId} />,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
id: 'tenancies',
|
|
||||||
label: 'Tenancies',
|
|
||||||
content: <YachtTenanciesTab yachtId={yachtId} />,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
id: 'notes',
|
id: 'notes',
|
||||||
label: 'Notes',
|
label: 'Notes',
|
||||||
@@ -401,4 +401,14 @@ export function getYachtTabs({ yachtId, currentUserId, yacht }: YachtTabsOptions
|
|||||||
),
|
),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
if (tenanciesModuleEnabled) {
|
||||||
|
// Insert after Interests (index 3) so the ordering reads:
|
||||||
|
// Overview → Ownership History → Interests → Tenancies.
|
||||||
|
tabs.splice(3, 0, {
|
||||||
|
id: 'tenancies',
|
||||||
|
label: 'Tenancies',
|
||||||
|
content: <YachtTenanciesTab yachtId={yachtId} />,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return tabs;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ interface PortContextValue {
|
|||||||
currentPort: Port | null;
|
currentPort: Port | null;
|
||||||
currentPortId: string | null;
|
currentPortId: string | null;
|
||||||
currentPortSlug: string | null;
|
currentPortSlug: string | null;
|
||||||
|
/** Per-port feature-flag map — currently just the Tenancies module.
|
||||||
|
* Resolved server-side in the dashboard layout. Consumers read via
|
||||||
|
* `useTenanciesModuleEnabled()`. */
|
||||||
|
tenanciesModuleByPort: Record<string, boolean>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const PortContext = createContext<PortContextValue>({
|
const PortContext = createContext<PortContextValue>({
|
||||||
@@ -19,15 +23,22 @@ const PortContext = createContext<PortContextValue>({
|
|||||||
currentPort: null,
|
currentPort: null,
|
||||||
currentPortId: null,
|
currentPortId: null,
|
||||||
currentPortSlug: null,
|
currentPortSlug: null,
|
||||||
|
tenanciesModuleByPort: {},
|
||||||
});
|
});
|
||||||
|
|
||||||
interface PortProviderProps {
|
interface PortProviderProps {
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
ports: Port[];
|
ports: Port[];
|
||||||
defaultPortId: string | null;
|
defaultPortId: string | null;
|
||||||
|
tenanciesModuleByPort?: Record<string, boolean>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function PortProvider({ children, ports, defaultPortId }: PortProviderProps) {
|
export function PortProvider({
|
||||||
|
children,
|
||||||
|
ports,
|
||||||
|
defaultPortId,
|
||||||
|
tenanciesModuleByPort = {},
|
||||||
|
}: PortProviderProps) {
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
const portSlugFromUrl = params?.portSlug as string | undefined;
|
const portSlugFromUrl = params?.portSlug as string | undefined;
|
||||||
|
|
||||||
@@ -75,6 +86,7 @@ export function PortProvider({ children, ports, defaultPortId }: PortProviderPro
|
|||||||
currentPort: currentPort ?? null,
|
currentPort: currentPort ?? null,
|
||||||
currentPortId: currentPort?.id ?? null,
|
currentPortId: currentPort?.id ?? null,
|
||||||
currentPortSlug: currentPort?.slug ?? null,
|
currentPortSlug: currentPort?.slug ?? null,
|
||||||
|
tenanciesModuleByPort,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
@@ -85,3 +97,12 @@ export function PortProvider({ children, ports, defaultPortId }: PortProviderPro
|
|||||||
export function usePortContext(): PortContextValue {
|
export function usePortContext(): PortContextValue {
|
||||||
return useContext(PortContext);
|
return useContext(PortContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Read the tenancies-module-enabled flag for the currently-active port.
|
||||||
|
* Server-side resolved in the dashboard layout, so this is a synchronous
|
||||||
|
* read with no fetch latency or hydration flicker. */
|
||||||
|
export function useTenanciesModuleEnabled(): boolean {
|
||||||
|
const { currentPortId, tenanciesModuleByPort } = useContext(PortContext);
|
||||||
|
if (!currentPortId) return false;
|
||||||
|
return tenanciesModuleByPort[currentPortId] ?? false;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user