import { getMemberToken, getApiBaseUrl } from '../_lib/api'; import Link from 'next/link'; interface DashboardData { profile: { id: string; jid: string; displayName: string | null; avatar: string | null; hometown: string | null; currentLocation: string | null; interests: string[]; language: string; digestPreference: string; directoryVisible: boolean; createdAt: string; }; stats: { groupsJoined: number; messagesContributed: number; activeConsents: number; }; groups: Array<{ id: string; name: string; joinedAt: string; consentStatus: string; }>; } async function fetchDashboard(token: string): Promise { const res = await fetch(`${getApiBaseUrl()}/my/dashboard`, { headers: { Authorization: `Bearer ${token}` }, cache: 'no-store', }).catch(() => null); if (!res || !res.ok) return null; return (await res.json()) as DashboardData; } function StatCard({ label, value }: { label: string; value: number }) { return (
{value} {label}
); } export default async function DashboardPage() { const token = await getMemberToken(); if (!token) return null; const data = await fetchDashboard(token); if (!data) { return (

Could not load dashboard

Your session may have expired. Please sign out and onboard again.

); } const { profile, stats, groups } = data; return (
{/* Hero */}
{profile.displayName ? profile.displayName.charAt(0).toUpperCase() : '?'}

{profile.displayName ?? 'Community Member'}

{profile.jid}

{(profile.hometown || profile.currentLocation) && (

{[profile.hometown, profile.currentLocation].filter(Boolean).join(' · ')}

)}
Edit profile
{/* Stats */}
{/* Groups */} {groups.length > 0 && (

Your groups

{groups.map((g) => (

{g.name}

Joined {new Date(g.joinedAt).toLocaleDateString()}

{g.consentStatus === 'GRANTED' ? 'Active' : 'Revoked'}
))}
Manage all groups →
)} {groups.length === 0 && (

No group memberships yet.

An admin will send you an onboarding link when you are added to a group.

)} {/* Interests */} {profile.interests.length > 0 && (

Interests

{profile.interests.map((interest) => ( {interest} ))}
)} {/* Member since */}

Member since {new Date(profile.createdAt).toLocaleDateString('en-IN', { year: 'numeric', month: 'long', day: 'numeric' })}

); }