import Link from 'next/link'; import { ArrowRight, FileText, GraduationCap, Mail, Plus, UserCheck, UserPlus, CalendarDays, Activity, BedDouble, } from 'lucide-react'; import { getTranslations } from 'next-intl/server'; import { createBookingManagementApi } from '@kit/booking-management/api'; import { createCourseManagementApi } from '@kit/course-management/api'; import { createEventManagementApi } from '@kit/event-management/api'; import { createFinanceApi } from '@kit/finance/api'; import { createMemberServices } from '@kit/member-management/services'; import { createNewsletterApi } from '@kit/newsletter/api'; import { formatDate } from '@kit/shared/dates'; import { getSupabaseServerClient } from '@kit/supabase/server-client'; import { Badge } from '@kit/ui/badge'; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from '@kit/ui/card'; import { AccountNotFound } from '~/components/account-not-found'; import { CmsPageShell } from '~/components/cms-page-shell'; import { EmptyState } from '~/components/empty-state'; import { StatsCard } from '~/components/stats-card'; interface TeamAccountHomePageProps { params: Promise<{ account: string }>; } export default async function TeamAccountHomePage({ params, }: TeamAccountHomePageProps) { const { account } = await params; const client = getSupabaseServerClient(); const t = await getTranslations('common'); const { data: acct } = await client .from('accounts') .select('id, name') .eq('slug', account) .single(); if (!acct) return ; // Load all stats in parallel with allSettled for resilience const [ memberStatsResult, courseStatsResult, invoicesResult, newslettersResult, bookingsResult, eventsResult, ] = await Promise.allSettled([ createMemberServices(client).query.getStatistics(acct.id), createCourseManagementApi(client).statistics.getQuickStats(acct.id), createFinanceApi(client).listInvoices(acct.id, { status: 'draft' }), createNewsletterApi(client).listNewsletters(acct.id), createBookingManagementApi(client).bookings.list(acct.id, { page: 1 }), createEventManagementApi(client).events.list(acct.id, { page: 1 }), ]); const memberStatsRaw = memberStatsResult.status === 'fulfilled' ? memberStatsResult.value : {}; const memberStats = { total: Object.values(memberStatsRaw).reduce((a, b) => a + b, 0), active: memberStatsRaw.active ?? 0, inactive: memberStatsRaw.inactive ?? 0, pending: memberStatsRaw.pending ?? 0, resigned: memberStatsRaw.resigned ?? 0, }; const courseStats = courseStatsResult.status === 'fulfilled' ? courseStatsResult.value : { totalCourses: 0, openCourses: 0, completedCourses: 0, totalParticipants: 0, }; const openInvoices = invoicesResult.status === 'fulfilled' ? invoicesResult.value.data : []; const newsletters = newslettersResult.status === 'fulfilled' ? newslettersResult.value.data : []; const bookings = bookingsResult.status === 'fulfilled' ? bookingsResult.value : { data: [], total: 0 }; const events = eventsResult.status === 'fulfilled' ? eventsResult.value : { data: [], total: 0 }; const accountName = acct.name ? String(acct.name) : 'Dashboard'; return ( {/* Stats Row */} } description={t('dashboard.membersDescription', { total: memberStats.total, pending: memberStats.pending, })} /> } description={t('dashboard.coursesDescription', { total: courseStats.totalCourses, participants: courseStats.totalParticipants, })} /> } description={t('dashboard.openInvoicesDescription')} /> } description={t('dashboard.newslettersDescription')} /> {/* Recent Activity */} {t('dashboard.recentActivity')} {t('dashboard.recentActivityDescription')} {/* Recent bookings */} {bookings.data .slice(0, 3) .map((booking: Record) => ( {t('dashboard.bookingFrom')}{' '} {booking.check_in ? formatDate(booking.check_in as string) : '—'} {formatDate(booking.check_in as string)} –{' '} {formatDate(booking.check_out as string)} {String(booking.status ?? '—')} ))} {/* Recent events */} {events.data .slice(0, 3) .map((event: Record) => ( {String(event.name)} {formatDate(event.event_date as string)} {String(event.status ?? '—')} ))} {bookings.data.length === 0 && events.data.length === 0 && ( } title={t('dashboard.recentActivityEmpty')} description={t('dashboard.recentActivityEmptyDescription')} /> )} {/* Quick Actions */} {t('dashboard.quickActions')} {t('dashboard.quickActionsDescription')} {t('dashboard.newMember')} {t('dashboard.newCourse')} {t('dashboard.createNewsletter')} {t('dashboard.newBooking')} {t('dashboard.newEvent')} ); }
{formatDate(booking.check_in as string)} –{' '} {formatDate(booking.check_out as string)}
{formatDate(event.event_date as string)}