Files
maaz519 a3798b3059 feat: show tenancy scope (Org → Chapter) in chapter & member portals
Surface where the logged-in user sits in the hierarchy via a ScopeCard
in the sidebar, below the brand mark.

API:
- Enrich chapter login/me responses with tenantName + organization
  (LoginResponse.admin, AdminProfile types updated)
- Add GET /my/scope returning member's chapter + organization

Web:
- ScopeCard component (Organisation row + Chapter row, themed icons)
- Chapter portal: scope from auth context, blue accent
- Member portal: scope fetched server-side in layout, emerald accent
- PortalShell gains a `scope` slot rendered under the brand

Org and admin portals intentionally omit it — org IS the scope, admin is
platform-wide.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-20 18:27:23 +05:30

43 lines
1.6 KiB
TypeScript

'use client';
import { useEffect } from 'react';
import { usePathname, useRouter } from 'next/navigation';
import { useAuth } from '@/app/_lib/auth-context';
import { PortalShell } from '@/app/_components/portal-shell';
import { ScopeCard } from '@/app/_components/scope-card';
import { Search, Users, Inbox, FileText, SlidersHorizontal, Bot } from 'lucide-react';
const NAV = [
{ href: '/search', label: 'Search', icon: <Search /> },
{ href: '/groups', label: 'Groups & Routes', icon: <Users /> },
{ href: '/messages/pending', label: 'Pending', icon: <Inbox /> },
{ href: '/drafts', label: 'AI Drafts', icon: <FileText /> },
{ href: '/settings/rules', label: 'Rules', icon: <SlidersHorizontal /> },
{ href: '/settings/bot', label: 'Bot', icon: <Bot /> },
];
export default function ChapterLayout({ children }: { children: React.ReactNode }) {
const { admin, loading, logout } = useAuth();
const router = useRouter();
const pathname = usePathname();
useEffect(() => {
if (!loading && !admin) router.replace(`/login?next=${encodeURIComponent(pathname)}`);
}, [admin, loading, pathname, router]);
return (
<PortalShell
portalName="Chapter"
theme="blue"
navItems={NAV}
loading={loading}
authed={!!admin}
user={admin ? { email: admin.email, name: admin.name, role: admin.role, subtitle: admin.tenantName } : undefined}
scope={admin ? <ScopeCard accent="text-blue-600" organization={admin.organization} chapter={admin.tenantName ? { name: admin.tenantName } : null} /> : undefined}
onLogout={() => { void logout(); router.replace('/login'); }}
>
{children}
</PortalShell>
);
}