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:
@@ -8,6 +8,7 @@ import { DetailLayout } from '@/components/shared/detail-layout';
|
||||
import { DetailNotFound } from '@/components/shared/detail-not-found';
|
||||
import { useMobileChrome } from '@/components/layout/mobile/mobile-layout-provider';
|
||||
import { apiFetch } from '@/lib/api/client';
|
||||
import { useTenanciesModuleEnabled } from '@/providers/port-provider';
|
||||
import { useRealtimeInvalidation } from '@/hooks/use-realtime-invalidation';
|
||||
import { BerthDetailHeader, type BerthDetailData } from './berth-detail-header';
|
||||
import { BerthForm } from './berth-form';
|
||||
@@ -20,6 +21,7 @@ interface BerthDetailProps {
|
||||
export function BerthDetail({ berthId }: BerthDetailProps) {
|
||||
const params = useParams<{ portSlug: string }>();
|
||||
const portSlug = params?.portSlug ?? '';
|
||||
const tenanciesModuleEnabled = useTenanciesModuleEnabled();
|
||||
|
||||
const { data, isLoading, error } = useQuery<BerthDetailData>({
|
||||
queryKey: ['berth', berthId],
|
||||
@@ -84,7 +86,7 @@ export function BerthDetail({ berthId }: BerthDetailProps) {
|
||||
<DetailLayout
|
||||
isLoading={isLoading}
|
||||
header={berth ? <BerthDetailHeader berth={berth} /> : null}
|
||||
tabs={berth ? buildBerthTabs(berth) : []}
|
||||
tabs={berth ? buildBerthTabs(berth, { tenanciesModuleEnabled }) : []}
|
||||
defaultTab="overview"
|
||||
/>
|
||||
{berth ? <BerthForm berth={berth} open={editOpen} onOpenChange={setEditOpen} /> : null}
|
||||
|
||||
@@ -419,8 +419,11 @@ function OverviewTab({ berth }: { berth: BerthData }) {
|
||||
);
|
||||
}
|
||||
|
||||
export function buildBerthTabs(berth: BerthData): DetailTab[] {
|
||||
return [
|
||||
export function buildBerthTabs(
|
||||
berth: BerthData,
|
||||
opts: { tenanciesModuleEnabled: boolean } = { tenanciesModuleEnabled: false },
|
||||
): DetailTab[] {
|
||||
const tabs: DetailTab[] = [
|
||||
{
|
||||
id: 'overview',
|
||||
label: 'Overview',
|
||||
@@ -431,11 +434,20 @@ export function buildBerthTabs(berth: BerthData): DetailTab[] {
|
||||
label: 'Interests',
|
||||
content: <BerthInterestsTab berthId={berth.id} />,
|
||||
},
|
||||
{
|
||||
];
|
||||
if (opts.tenanciesModuleEnabled) {
|
||||
tabs.push({
|
||||
id: 'tenancies',
|
||||
label: 'Tenancies',
|
||||
content: <BerthTenanciesTab berthId={berth.id} />,
|
||||
},
|
||||
});
|
||||
}
|
||||
tabs.push(...buildBerthDetailRemainder(berth));
|
||||
return tabs;
|
||||
}
|
||||
|
||||
function buildBerthDetailRemainder(berth: BerthData): DetailTab[] {
|
||||
return [
|
||||
{
|
||||
id: 'spec',
|
||||
label: 'Spec',
|
||||
|
||||
Reference in New Issue
Block a user