Add account hierarchy framework with migrations, RLS policies, and UI components

This commit is contained in:
T. Zehetbauer
2026-03-31 22:18:04 +02:00
parent 7e7da0b465
commit 59546ad6d2
262 changed files with 11671 additions and 3927 deletions

View File

@@ -9,13 +9,13 @@ import {
UserPlus,
} from 'lucide-react';
import { createEventManagementApi } from '@kit/event-management/api';
import { formatDate } from '@kit/shared/dates';
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';
@@ -32,7 +32,10 @@ const STATUS_LABEL: Record<string, string> = {
completed: 'Abgeschlossen',
};
const STATUS_VARIANT: Record<string, 'secondary' | 'default' | 'info' | 'outline' | 'destructive'> = {
const STATUS_VARIANT: Record<
string,
'secondary' | 'default' | 'info' | 'outline' | 'destructive'
> = {
draft: 'secondary',
published: 'default',
registration_open: 'info',
@@ -62,7 +65,10 @@ export default async function EventDetailPage({ params }: PageProps) {
<div className="flex items-center justify-between">
<div>
<h1 className="text-2xl font-bold">{String(e.name)}</h1>
<Badge variant={STATUS_VARIANT[String(e.status)] ?? 'secondary'} className="mt-1">
<Badge
variant={STATUS_VARIANT[String(e.status)] ?? 'secondary'}
className="mt-1"
>
{STATUS_LABEL[String(e.status)] ?? String(e.status)}
</Badge>
</div>
@@ -76,22 +82,20 @@ export default async function EventDetailPage({ params }: PageProps) {
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4">
<Card>
<CardContent className="flex items-center gap-3 p-4">
<CalendarDays className="h-5 w-5 text-primary" />
<CalendarDays className="text-primary h-5 w-5" />
<div>
<p className="text-xs text-muted-foreground">Datum</p>
<p className="text-muted-foreground text-xs">Datum</p>
<p className="font-semibold">
{e.event_date
? new Date(String(e.event_date)).toLocaleDateString('de-DE')
: '—'}
{formatDate(e.event_date as string)}
</p>
</div>
</CardContent>
</Card>
<Card>
<CardContent className="flex items-center gap-3 p-4">
<Clock className="h-5 w-5 text-primary" />
<Clock className="text-primary h-5 w-5" />
<div>
<p className="text-xs text-muted-foreground">Uhrzeit</p>
<p className="text-muted-foreground text-xs">Uhrzeit</p>
<p className="font-semibold">
{String(e.start_time ?? '—')} {String(e.end_time ?? '—')}
</p>
@@ -100,18 +104,18 @@ export default async function EventDetailPage({ params }: PageProps) {
</Card>
<Card>
<CardContent className="flex items-center gap-3 p-4">
<MapPin className="h-5 w-5 text-primary" />
<MapPin className="text-primary h-5 w-5" />
<div>
<p className="text-xs text-muted-foreground">Ort</p>
<p className="text-muted-foreground text-xs">Ort</p>
<p className="font-semibold">{String(e.location ?? '—')}</p>
</div>
</CardContent>
</Card>
<Card>
<CardContent className="flex items-center gap-3 p-4">
<Users className="h-5 w-5 text-primary" />
<Users className="text-primary h-5 w-5" />
<div>
<p className="text-xs text-muted-foreground">Anmeldungen</p>
<p className="text-muted-foreground text-xs">Anmeldungen</p>
<p className="font-semibold">
{registrations.length} / {String(e.capacity ?? '∞')}
</p>
@@ -127,7 +131,7 @@ export default async function EventDetailPage({ params }: PageProps) {
<CardTitle>Beschreibung</CardTitle>
</CardHeader>
<CardContent>
<p className="text-sm text-muted-foreground whitespace-pre-wrap">
<p className="text-muted-foreground text-sm whitespace-pre-wrap">
{String(e.description)}
</p>
</CardContent>
@@ -141,14 +145,14 @@ export default async function EventDetailPage({ params }: PageProps) {
</CardHeader>
<CardContent>
{registrations.length === 0 ? (
<p className="py-6 text-center text-sm text-muted-foreground">
<p className="text-muted-foreground py-6 text-center text-sm">
Noch keine Anmeldungen
</p>
) : (
<div className="rounded-md border">
<table className="w-full text-sm">
<thead>
<tr className="border-b bg-muted/50">
<tr className="bg-muted/50 border-b">
<th className="p-3 text-left font-medium">Name</th>
<th className="p-3 text-left font-medium">E-Mail</th>
<th className="p-3 text-left font-medium">Elternteil</th>
@@ -157,16 +161,20 @@ export default async function EventDetailPage({ params }: PageProps) {
</thead>
<tbody>
{registrations.map((reg: Record<string, unknown>) => (
<tr key={String(reg.id)} className="border-b hover:bg-muted/30">
<tr
key={String(reg.id)}
className="hover:bg-muted/30 border-b"
>
<td className="p-3 font-medium">
{String(reg.last_name ?? '')}, {String(reg.first_name ?? '')}
{String(reg.last_name ?? '')},{' '}
{String(reg.first_name ?? '')}
</td>
<td className="p-3">{String(reg.email ?? '—')}</td>
<td className="p-3">{String(reg.parent_name ?? '—')}</td>
<td className="p-3">
{reg.created_at
? new Date(String(reg.created_at)).toLocaleDateString('de-DE')
: '—'}
{String(reg.parent_name ?? '—')}
</td>
<td className="p-3">
{formatDate(reg.created_at as string)}
</td>
</tr>
))}

View File

@@ -1,15 +1,15 @@
import { Ticket, Plus } from 'lucide-react';
import { getTranslations } from 'next-intl/server';
import { createEventManagementApi } from '@kit/event-management/api';
import { formatDate } from '@kit/shared/dates';
import { getSupabaseServerClient } from '@kit/supabase/server-client';
import { Button } from '@kit/ui/button';
import { Card, CardContent, CardHeader, CardTitle } from '@kit/ui/card';
import { createEventManagementApi } from '@kit/event-management/api';
import { AccountNotFound } from '~/components/account-not-found';
import { CmsPageShell } from '~/components/cms-page-shell';
import { EmptyState } from '~/components/empty-state';
import { AccountNotFound } from '~/components/account-not-found';
interface PageProps {
params: Promise<{ account: string }>;
@@ -37,7 +37,9 @@ export default async function HolidayPassesPage({ params }: PageProps) {
<div className="flex items-center justify-between">
<div>
<h1 className="text-2xl font-bold">{t('holidayPasses')}</h1>
<p className="text-muted-foreground">{t('holidayPassesDescription')}</p>
<p className="text-muted-foreground">
{t('holidayPassesDescription')}
</p>
</div>
<Button>
<Plus className="mr-2 h-4 w-4" />
@@ -55,23 +57,34 @@ export default async function HolidayPassesPage({ params }: PageProps) {
) : (
<Card>
<CardHeader>
<CardTitle>{t('allHolidayPasses')} ({passes.length})</CardTitle>
<CardTitle>
{t('allHolidayPasses')} ({passes.length})
</CardTitle>
</CardHeader>
<CardContent>
<div className="rounded-md border">
<table className="w-full text-sm">
<thead>
<tr className="border-b bg-muted/50">
<tr className="bg-muted/50 border-b">
<th className="p-3 text-left font-medium">{t('name')}</th>
<th className="p-3 text-left font-medium">{t('year')}</th>
<th className="p-3 text-right font-medium">{t('price')}</th>
<th className="p-3 text-left font-medium">{t('validFrom')}</th>
<th className="p-3 text-left font-medium">{t('validUntil')}</th>
<th className="p-3 text-right font-medium">
{t('price')}
</th>
<th className="p-3 text-left font-medium">
{t('validFrom')}
</th>
<th className="p-3 text-left font-medium">
{t('validUntil')}
</th>
</tr>
</thead>
<tbody>
{passes.map((pass: Record<string, unknown>) => (
<tr key={String(pass.id)} className="border-b hover:bg-muted/30">
<tr
key={String(pass.id)}
className="hover:bg-muted/30 border-b"
>
<td className="p-3 font-medium">{String(pass.name)}</td>
<td className="p-3">{String(pass.year ?? '—')}</td>
<td className="p-3 text-right">
@@ -80,14 +93,10 @@ export default async function HolidayPassesPage({ params }: PageProps) {
: '—'}
</td>
<td className="p-3">
{pass.valid_from
? new Date(String(pass.valid_from)).toLocaleDateString('de-DE')
: '—'}
{formatDate(pass.valid_from as string)}
</td>
<td className="p-3">
{pass.valid_until
? new Date(String(pass.valid_until)).toLocaleDateString('de-DE')
: '—'}
{formatDate(pass.valid_until as string)}
</td>
</tr>
))}

View File

@@ -1,20 +1,32 @@
import { getTranslations } from 'next-intl/server';
import { getSupabaseServerClient } from '@kit/supabase/server-client';
import { CreateEventForm } from '@kit/event-management/components';
import { CmsPageShell } from '~/components/cms-page-shell';
import { AccountNotFound } from '~/components/account-not-found';
interface Props { params: Promise<{ account: string }> }
import { CreateEventForm } from '@kit/event-management/components';
import { getSupabaseServerClient } from '@kit/supabase/server-client';
import { AccountNotFound } from '~/components/account-not-found';
import { CmsPageShell } from '~/components/cms-page-shell';
interface Props {
params: Promise<{ account: string }>;
}
export default async function NewEventPage({ params }: Props) {
const { account } = await params;
const client = getSupabaseServerClient();
const t = await getTranslations('cms.events');
const { data: acct } = await client.from('accounts').select('id').eq('slug', account).single();
const { data: acct } = await client
.from('accounts')
.select('id')
.eq('slug', account)
.single();
if (!acct) return <AccountNotFound />;
return (
<CmsPageShell account={account} title={t('newEvent')} description={t('newEventDescription')}>
<CmsPageShell
account={account}
title={t('newEvent')}
description={t('newEventDescription')}
>
<CreateEventForm accountId={acct.id} account={account} />
</CmsPageShell>
);

View File

@@ -1,19 +1,26 @@
import Link from 'next/link';
import { CalendarDays, ChevronLeft, ChevronRight, MapPin, Plus, Users } from 'lucide-react';
import {
CalendarDays,
ChevronLeft,
ChevronRight,
MapPin,
Plus,
Users,
} from 'lucide-react';
import { getTranslations } from 'next-intl/server';
import { createEventManagementApi } from '@kit/event-management/api';
import { formatDate } from '@kit/shared/dates';
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 { 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';
import { AccountNotFound } from '~/components/account-not-found';
import { EVENT_STATUS_VARIANT, EVENT_STATUS_LABEL } from '~/lib/status-badges';
interface PageProps {
@@ -40,14 +47,14 @@ export default async function EventsPage({ params, searchParams }: PageProps) {
const events = await api.listEvents(acct.id, { page });
// Fetch registration counts for all events on this page
const eventIds = events.data.map((e: Record<string, unknown>) => String(e.id));
const eventIds = events.data.map((e: Record<string, unknown>) =>
String(e.id),
);
const registrationCounts = await api.getRegistrationCounts(eventIds);
// Pre-compute stats before rendering
const uniqueLocationCount = new Set(
events.data
.map((e: Record<string, unknown>) => e.location)
.filter(Boolean),
events.data.map((e: Record<string, unknown>) => e.location).filter(Boolean),
).size;
const totalCapacity = events.data.reduce(
@@ -63,9 +70,7 @@ export default async function EventsPage({ params, searchParams }: PageProps) {
<div className="flex items-center justify-between">
<div>
<h1 className="text-2xl font-bold">{t('title')}</h1>
<p className="text-muted-foreground">
{t('description')}
</p>
<p className="text-muted-foreground">{t('description')}</p>
</div>
<Link href={`/home/${account}/events/new`}>
@@ -107,19 +112,31 @@ export default async function EventsPage({ params, searchParams }: PageProps) {
) : (
<Card>
<CardHeader>
<CardTitle>{t('allEvents')} ({events.total})</CardTitle>
<CardTitle>
{t('allEvents')} ({events.total})
</CardTitle>
</CardHeader>
<CardContent>
<div className="rounded-md border">
<table className="w-full text-sm">
<thead>
<tr className="border-b bg-muted/50">
<tr className="bg-muted/50 border-b">
<th className="p-3 text-left font-medium">{t('name')}</th>
<th className="p-3 text-left font-medium">{t('eventDate')}</th>
<th className="p-3 text-left font-medium">{t('eventLocation')}</th>
<th className="p-3 text-right font-medium">{t('capacity')}</th>
<th className="p-3 text-left font-medium">{t('status')}</th>
<th className="p-3 text-right font-medium">{t('registrations')}</th>
<th className="p-3 text-left font-medium">
{t('eventDate')}
</th>
<th className="p-3 text-left font-medium">
{t('eventLocation')}
</th>
<th className="p-3 text-right font-medium">
{t('capacity')}
</th>
<th className="p-3 text-left font-medium">
{t('status')}
</th>
<th className="p-3 text-right font-medium">
{t('registrations')}
</th>
</tr>
</thead>
<tbody>
@@ -130,7 +147,7 @@ export default async function EventsPage({ params, searchParams }: PageProps) {
return (
<tr
key={eventId}
className="border-b hover:bg-muted/30"
className="hover:bg-muted/30 border-b"
>
<td className="p-3 font-medium">
<Link
@@ -141,9 +158,7 @@ export default async function EventsPage({ params, searchParams }: PageProps) {
</Link>
</td>
<td className="p-3">
{event.event_date
? new Date(String(event.event_date)).toLocaleDateString('de-DE')
: '—'}
{formatDate(event.event_date as string)}
</td>
<td className="p-3">
{String(event.location ?? '—')}
@@ -156,10 +171,12 @@ export default async function EventsPage({ params, searchParams }: PageProps) {
<td className="p-3">
<Badge
variant={
EVENT_STATUS_VARIANT[String(event.status)] ?? 'secondary'
EVENT_STATUS_VARIANT[String(event.status)] ??
'secondary'
}
>
{EVENT_STATUS_LABEL[String(event.status)] ?? String(event.status)}
{EVENT_STATUS_LABEL[String(event.status)] ??
String(event.status)}
</Badge>
</td>
<td className="p-3 text-right font-medium">
@@ -175,12 +192,17 @@ export default async function EventsPage({ params, searchParams }: PageProps) {
{/* Pagination */}
{events.totalPages > 1 && (
<div className="flex items-center justify-between pt-4">
<span className="text-sm text-muted-foreground">
{t('paginationPage', { page: events.page, totalPages: events.totalPages })}
<span className="text-muted-foreground text-sm">
{t('paginationPage', {
page: events.page,
totalPages: events.totalPages,
})}
</span>
<div className="flex gap-2">
{events.page > 1 && (
<Link href={`/home/${account}/events?page=${events.page - 1}`}>
<Link
href={`/home/${account}/events?page=${events.page - 1}`}
>
<Button variant="outline" size="sm">
<ChevronLeft className="mr-1 h-4 w-4" />
{t('paginationPrevious')}
@@ -188,7 +210,9 @@ export default async function EventsPage({ params, searchParams }: PageProps) {
</Link>
)}
{events.page < events.totalPages && (
<Link href={`/home/${account}/events?page=${events.page + 1}`}>
<Link
href={`/home/${account}/events?page=${events.page + 1}`}
>
<Button variant="outline" size="sm">
{t('paginationNext')}
<ChevronRight className="ml-1 h-4 w-4" />

View File

@@ -1,18 +1,18 @@
import Link from 'next/link';
import { CalendarDays, ClipboardList, Users } from 'lucide-react';
import { getTranslations } from 'next-intl/server';
import { createEventManagementApi } from '@kit/event-management/api';
import { formatDate } from '@kit/shared/dates';
import { getSupabaseServerClient } from '@kit/supabase/server-client';
import { Badge } from '@kit/ui/badge';
import { Card, CardContent, CardHeader, CardTitle } from '@kit/ui/card';
import { createEventManagementApi } from '@kit/event-management/api';
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';
import { AccountNotFound } from '~/components/account-not-found';
import { EVENT_STATUS_VARIANT, EVENT_STATUS_LABEL } from '~/lib/status-badges';
interface PageProps {
@@ -64,9 +64,7 @@ export default async function EventRegistrationsPage({ params }: PageProps) {
{/* Header */}
<div>
<h1 className="text-2xl font-bold">{t('registrations')}</h1>
<p className="text-muted-foreground">
{t('registrationsOverview')}
</p>
<p className="text-muted-foreground">{t('registrationsOverview')}</p>
</div>
{/* Stats */}
@@ -108,17 +106,25 @@ export default async function EventRegistrationsPage({ params }: PageProps) {
<div className="rounded-md border">
<table className="w-full text-sm">
<thead>
<tr className="border-b bg-muted/50">
<tr className="bg-muted/50 border-b">
<th className="p-3 text-left font-medium">
{t('event')}
</th>
<th className="p-3 text-left font-medium">{t('eventDate')}</th>
<th className="p-3 text-left font-medium">{t('status')}</th>
<th className="p-3 text-right font-medium">{t('capacity')}</th>
<th className="p-3 text-left font-medium">
{t('eventDate')}
</th>
<th className="p-3 text-left font-medium">
{t('status')}
</th>
<th className="p-3 text-right font-medium">
{t('capacity')}
</th>
<th className="p-3 text-right font-medium">
{t('registrations')}
</th>
<th className="p-3 text-right font-medium">{t('utilization')}</th>
<th className="p-3 text-right font-medium">
{t('utilization')}
</th>
</tr>
</thead>
<tbody>
@@ -133,7 +139,7 @@ export default async function EventRegistrationsPage({ params }: PageProps) {
return (
<tr
key={event.id}
className="border-b hover:bg-muted/30"
className="hover:bg-muted/30 border-b"
>
<td className="p-3 font-medium">
<Link
@@ -143,17 +149,12 @@ export default async function EventRegistrationsPage({ params }: PageProps) {
{event.name}
</Link>
</td>
<td className="p-3">
{event.eventDate
? new Date(event.eventDate).toLocaleDateString(
'de-DE',
)
: '—'}
</td>
<td className="p-3">{formatDate(event.eventDate)}</td>
<td className="p-3">
<Badge
variant={
EVENT_STATUS_VARIANT[event.status] ?? 'secondary'
EVENT_STATUS_VARIANT[event.status] ??
'secondary'
}
>
{EVENT_STATUS_LABEL[event.status] ?? event.status}