feat: isolate all four portals with route groups + polished design system

Fix blank /org/login (and /admin/login): the guarded portal layout was
wrapping its own login route, rendering null when unauthenticated. Move
each portal's authed pages into a (authed)/(chapter) route group so login
pages live outside the guard.

Structure:
- app/(chapter)/* — chapter admin pages + guarded layout (was root-level)
- app/org/(authed)/* — org pages + guarded layout; /org/login now free
- app/admin/(authed)/* — admin pages + guarded layout; /admin/login free
- Root layout slimmed to providers only (no shared sidebar)
- Convert moved files' relative imports to @/app alias

Design system:
- PortalShell: shared sidebar shell (brand mark, themed active nav with
  accent bar, avatar dropdown user menu, loading skeletons)
- portal-theme.ts: per-portal theme tokens (violet/slate/blue/emerald)
- PortalLoginShell redesigned: two-column with gradient branding panel,
  dotted pattern, value-prop highlights, built-in back link
- New shadcn components: Avatar, DropdownMenu, Skeleton
- Move shared DraftCard to _components/draft-card.tsx (used by 2 portals)
- Portal selector: remove Super Admin card, icon tiles, hover lift
- All 4 login pages use react-hook-form + Zod + themed shell
- Member nav restored to full 11-section list with icons

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-20 18:20:06 +05:30
parent d7b5988858
commit 205418fc4e
50 changed files with 619 additions and 360 deletions
@@ -1,7 +1,7 @@
'use client';
import { useCallback, useEffect, useRef, useState } from 'react';
import { useSuperAdmin } from '../../_lib/super-admin-context';
import { useSuperAdmin } from '@/app/_lib/super-admin-context';
import { useRouter } from 'next/navigation';
export default function BotsPage() {
@@ -1,7 +1,7 @@
import { apiFetch } from '../../_lib/api';
import { apiFetch } from '@/app/_lib/api';
import { redirect } from 'next/navigation';
import { getToken } from '../../_lib/api';
import { DraftCard } from './DraftCard';
import { getToken } from '@/app/_lib/api';
import { DraftCard } from '@/app/_components/draft-card';
import Link from 'next/link';
type DraftType = 'EVENT' | 'SEVA_TASK' | 'FAQ_ITEM';
+38
View File
@@ -0,0 +1,38 @@
'use client';
import { useEffect } from 'react';
import { useRouter } from 'next/navigation';
import { useSuperAdmin } from '@/app/_lib/super-admin-context';
import { PortalShell } from '@/app/_components/portal-shell';
import { LayoutDashboard, Building2, Network, Server, FileText } from 'lucide-react';
const NAV = [
{ href: '/admin', label: 'Dashboard', icon: <LayoutDashboard /> },
{ href: '/admin/orgs', label: 'Organisations', icon: <Network /> },
{ href: '/admin/tenants', label: 'Chapters', icon: <Building2 /> },
{ href: '/admin/bots', label: 'Bot Pool', icon: <Server /> },
{ href: '/admin/drafts', label: 'AI Drafts', icon: <FileText /> },
];
export default function AdminAuthedLayout({ children }: { children: React.ReactNode }) {
const { admin, loading, logout } = useSuperAdmin();
const router = useRouter();
useEffect(() => {
if (!loading && !admin) router.replace('/admin/login');
}, [admin, loading, router]);
return (
<PortalShell
portalName="Super Admin"
theme="slate"
navItems={NAV}
loading={loading}
authed={!!admin}
user={admin ? { email: admin.email, name: admin.name, role: 'Super Admin' } : undefined}
onLogout={() => { void logout(); router.replace('/admin/login'); }}
>
{children}
</PortalShell>
);
}
@@ -2,7 +2,7 @@
import { use, useEffect, useState } from 'react';
import { useRouter } from 'next/navigation';
import { useSuperAdmin } from '../../../_lib/super-admin-context';
import { useSuperAdmin } from '@/app/_lib/super-admin-context';
export default function AdminOrgDetailPage({ params }: { params: Promise<{ id: string }> }) {
const { id } = use(params);
@@ -1,7 +1,7 @@
'use client';
import { useEffect, useState } from 'react';
import { useSuperAdmin } from '../../_lib/super-admin-context';
import { useSuperAdmin } from '@/app/_lib/super-admin-context';
import { useRouter } from 'next/navigation';
import Link from 'next/link';
@@ -1,7 +1,7 @@
'use client';
import { useEffect, useState } from 'react';
import { useSuperAdmin } from '../_lib/super-admin-context';
import { useSuperAdmin } from '@/app/_lib/super-admin-context';
import { useRouter } from 'next/navigation';
import Link from 'next/link';
@@ -1,7 +1,7 @@
'use client';
import { useEffect, useState } from 'react';
import { useSuperAdmin } from '../../../_lib/super-admin-context';
import { useSuperAdmin } from '@/app/_lib/super-admin-context';
import { useRouter, useParams } from 'next/navigation';
export default function TenantDetailPage() {
@@ -1,7 +1,7 @@
'use client';
import { useEffect, useState } from 'react';
import { useSuperAdmin } from '../../_lib/super-admin-context';
import { useSuperAdmin } from '@/app/_lib/super-admin-context';
import { useRouter } from 'next/navigation';
import Link from 'next/link';
-137
View File
@@ -1,137 +0,0 @@
'use client';
import { useState } from 'react';
import { useRouter } from 'next/navigation';
interface SourceMessage {
id: string;
content: string;
senderName: string | null;
createdAt: string;
}
interface Draft {
id: string;
type: 'EVENT' | 'SEVA_TASK' | 'FAQ_ITEM';
status: string;
proposedJson: Record<string, any>;
confidence: number | null;
createdAt: string;
sourceMessage: SourceMessage;
}
const TYPE_LABEL: Record<Draft['type'], string> = {
EVENT: 'Event',
SEVA_TASK: 'Seva Task',
FAQ_ITEM: 'FAQ',
};
const TYPE_COLOR: Record<Draft['type'], string> = {
EVENT: 'bg-indigo-50 text-indigo-700 border-indigo-200',
SEVA_TASK: 'bg-green-50 text-green-700 border-green-200',
FAQ_ITEM: 'bg-amber-50 text-amber-700 border-amber-200',
};
function ProposedPreview({ type, data }: { type: Draft['type']; data: Record<string, any> }) {
if (type === 'EVENT') {
return (
<div className="space-y-1 text-sm">
<p><span className="font-medium text-gray-700">Title:</span> {data.title ?? '—'}</p>
{data.date && <p><span className="font-medium text-gray-700">Date:</span> {data.date} {data.time ?? ''}</p>}
{data.location && <p><span className="font-medium text-gray-700">Location:</span> {data.location}</p>}
{data.description && <p><span className="font-medium text-gray-700">Description:</span> {data.description}</p>}
{data.rsvpNeeded && <p className="text-indigo-600 text-xs">RSVP required</p>}
{data.sevaActionItems?.length > 0 && (
<p className="text-green-700 text-xs">+{data.sevaActionItems.length} seva task(s) will also be created</p>
)}
</div>
);
}
if (type === 'SEVA_TASK') {
return (
<div className="space-y-1 text-sm">
<p><span className="font-medium text-gray-700">Title:</span> {data.title ?? '—'}</p>
{data.parentEventTitle && <p><span className="font-medium text-gray-700">Event:</span> {data.parentEventTitle}</p>}
{data.slots && <p><span className="font-medium text-gray-700">Slots:</span> {data.slots}</p>}
{data.skills?.length > 0 && <p><span className="font-medium text-gray-700">Skills:</span> {data.skills.join(', ')}</p>}
</div>
);
}
return (
<div className="space-y-1 text-sm">
<p><span className="font-medium text-gray-700">Q:</span> {data.question ?? '—'}</p>
<p><span className="font-medium text-gray-700">A:</span> {data.answer ?? '—'}</p>
{data.tags?.length > 0 && (
<div className="flex gap-1 flex-wrap mt-1">
{data.tags.map((t: string) => (
<span key={t} className="text-xs bg-gray-100 text-gray-600 px-2 py-0.5 rounded-full">{t}</span>
))}
</div>
)}
</div>
);
}
export function DraftCard({ draft }: { draft: Draft }) {
const router = useRouter();
const [loading, setLoading] = useState<'approve' | 'reject' | null>(null);
async function act(action: 'approve' | 'reject') {
setLoading(action);
try {
await fetch(`/api/admin/drafts/${draft.id}/${action}`, { method: 'POST' });
router.refresh();
} finally {
setLoading(null);
}
}
const confidence = draft.confidence != null ? Math.round(draft.confidence * 100) : null;
return (
<div className="bg-white border border-gray-200 rounded-xl p-5 space-y-4">
<div className="flex items-start justify-between gap-3">
<span className={`text-xs font-semibold px-2.5 py-1 rounded-full border ${TYPE_COLOR[draft.type]}`}>
{TYPE_LABEL[draft.type]}
</span>
{confidence != null && (
<span className="text-xs text-gray-400">{confidence}% confidence</span>
)}
</div>
{/* Source message */}
<div className="bg-gray-50 rounded-lg p-3 border border-gray-100">
<p className="text-xs font-medium text-gray-500 mb-1">
Source message{draft.sourceMessage.senderName ? `${draft.sourceMessage.senderName}` : ''}
</p>
<p className="text-sm text-gray-700 line-clamp-3">{draft.sourceMessage.content}</p>
</div>
{/* AI proposed content */}
<div>
<p className="text-xs font-medium text-gray-500 mb-2">AI proposed</p>
<ProposedPreview type={draft.type} data={draft.proposedJson} />
</div>
{/* Actions */}
<div className="flex gap-2 pt-1">
<button
onClick={() => act('approve')}
disabled={loading !== null}
className="flex-1 py-2 text-sm font-medium rounded-lg bg-indigo-600 text-white hover:bg-indigo-700 disabled:opacity-50 transition-colors"
>
{loading === 'approve' ? 'Approving…' : 'Approve'}
</button>
<button
onClick={() => act('reject')}
disabled={loading !== null}
className="flex-1 py-2 text-sm font-medium rounded-lg border border-gray-200 text-gray-600 hover:bg-gray-50 disabled:opacity-50 transition-colors"
>
{loading === 'reject' ? 'Rejecting…' : 'Reject'}
</button>
</div>
</div>
);
}
-47
View File
@@ -1,47 +0,0 @@
'use client';
import { useEffect } from 'react';
import { useRouter } from 'next/navigation';
import { useSuperAdmin } from '../_lib/super-admin-context';
import { PortalNav } from '../_components/portal-nav';
import { LayoutDashboard, Building2, Server, FileText } from 'lucide-react';
const NAV = [
{ href: '/admin', label: 'Dashboard', icon: <LayoutDashboard /> },
{ href: '/admin/orgs', label: 'Organisations', icon: <Building2 /> },
{ href: '/admin/tenants', label: 'Chapters', icon: <Building2 /> },
{ href: '/admin/bots', label: 'Bot Pool', icon: <Server /> },
{ href: '/admin/drafts', label: 'AI Drafts', icon: <FileText /> },
];
export default function AdminLayout({ children }: { children: React.ReactNode }) {
const { admin, loading, logout } = useSuperAdmin();
const router = useRouter();
useEffect(() => {
if (!loading && !admin) router.replace('/admin/login');
}, [admin, loading, router]);
if (loading) {
return (
<div className="flex h-screen -m-6">
<div className="w-56 shrink-0 border-r bg-sidebar animate-pulse" />
<div className="flex-1" />
</div>
);
}
if (!admin) return null;
return (
<div className="flex h-screen overflow-hidden -m-6">
<PortalNav
portalName="Admin"
navItems={NAV}
accentClass="text-slate-900"
user={{ email: admin.email, name: admin.name ?? undefined, role: 'Super Admin' }}
onLogout={() => { void logout(); router.replace('/admin/login'); }}
/>
<main className="flex-1 overflow-auto bg-muted/30 p-6">{children}</main>
</div>
);
}
+2 -3
View File
@@ -9,7 +9,6 @@ import { PortalLoginShell } from '../../_components/portal-login-shell';
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '../../_components/ui/form';
import { Input } from '../../_components/ui/input';
import { Button } from '../../_components/ui/button';
import Link from 'next/link';
const schema = z.object({
email: z.string().email('Enter a valid email'),
@@ -36,8 +35,8 @@ export default function SuperAdminLoginPage() {
<PortalLoginShell
title="Super Admin"
subtitle="Platform-wide administration access."
accentClass="bg-slate-900"
footer={<Link href="/" className="hover:text-foreground transition-colors"> Back to portal selector</Link>}
theme="slate"
highlights={['Manage organisations & chapters', 'Provision and pair WhatsApp bots', 'Oversee the entire platform']}
>
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">