import Link from 'next/link';
import { CalendarDays, ClipboardList, Users } from 'lucide-react';
import { getSupabaseServerClient } from '@kit/supabase/server-client';
import { Badge } from '@kit/ui/badge';
import { Button } from '@kit/ui/button';
import { Card, CardContent, CardHeader, CardTitle } from '@kit/ui/card';
import { createEventManagementApi } from '@kit/event-management/api';
import { CmsPageShell } from '~/components/cms-page-shell';
import { EmptyState } from '~/components/empty-state';
import { StatsCard } from '~/components/stats-card';
interface PageProps {
params: Promise<{ account: string }>;
}
export default async function EventRegistrationsPage({ params }: PageProps) {
const { account } = await params;
const client = getSupabaseServerClient();
const { data: acct } = await client
.from('accounts')
.select('id')
.eq('slug', account)
.single();
if (!acct) return
Konto nicht gefunden
;
const api = createEventManagementApi(client);
const events = await api.listEvents(acct.id, { page: 1 });
// Load registrations for each event in parallel
const eventsWithRegistrations = await Promise.all(
events.data.map(async (event: Record) => {
const registrations = await api.getRegistrations(String(event.id));
return {
id: String(event.id),
name: String(event.name),
eventDate: event.event_date ? String(event.event_date) : null,
status: String(event.status ?? 'draft'),
capacity: event.capacity != null ? Number(event.capacity) : null,
registrationCount: registrations.length,
};
}),
);
const totalRegistrations = eventsWithRegistrations.reduce(
(sum, e) => sum + e.registrationCount,
0,
);
const eventsWithRegs = eventsWithRegistrations.filter(
(e) => e.registrationCount > 0,
);
return (
{/* Header */}
Anmeldungen
Anmeldungen aller Veranstaltungen im Überblick
{/* Stats */}
}
/>
}
/>
}
/>
{/* Registration Summary Table */}
{eventsWithRegistrations.length === 0 ? (
}
title="Keine Veranstaltungen vorhanden"
description="Erstellen Sie eine Veranstaltung, um Anmeldungen zu erhalten."
actionLabel="Neue Veranstaltung"
actionHref={`/home/${account}/events/new`}
/>
) : (
Übersicht nach Veranstaltung ({eventsWithRegistrations.length})
|
Veranstaltung
|
Datum |
Status |
Kapazität |
Anmeldungen
|
Auslastung |
{eventsWithRegistrations.map((event) => {
const utilization =
event.capacity && event.capacity > 0
? Math.round(
(event.registrationCount / event.capacity) * 100,
)
: null;
return (
|
{event.name}
|
{event.eventDate
? new Date(event.eventDate).toLocaleDateString(
'de-DE',
)
: '—'}
|
{event.status}
|
{event.capacity ?? '—'}
|
{event.registrationCount}
|
{utilization !== null ? (
= 90
? 'destructive'
: utilization >= 70
? 'default'
: 'secondary'
}
>
{utilization}%
) : (
—
)}
|
);
})}
)}
);
}