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:
2026-05-25 15:29:22 +02:00
parent 3a48150d13
commit e4daa482de
8 changed files with 93 additions and 24 deletions

View File

@@ -12,6 +12,10 @@ interface PortContextValue {
currentPort: Port | null;
currentPortId: 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>({
@@ -19,15 +23,22 @@ const PortContext = createContext<PortContextValue>({
currentPort: null,
currentPortId: null,
currentPortSlug: null,
tenanciesModuleByPort: {},
});
interface PortProviderProps {
children: ReactNode;
ports: Port[];
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 portSlugFromUrl = params?.portSlug as string | undefined;
@@ -75,6 +86,7 @@ export function PortProvider({ children, ports, defaultPortId }: PortProviderPro
currentPort: currentPort ?? null,
currentPortId: currentPort?.id ?? null,
currentPortSlug: currentPort?.slug ?? null,
tenanciesModuleByPort,
}}
>
{children}
@@ -85,3 +97,12 @@ export function PortProvider({ children, ports, defaultPortId }: PortProviderPro
export function usePortContext(): PortContextValue {
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;
}