import Link from "next/link"; import type { Metadata } from "next"; import { AlertTriangle, ArrowRight, Building2, CheckCircle2, Clock, Lock, MailWarning, Users, } from "lucide-react"; import { UserRole } from "@prisma/client"; import { requireRole } from "@/lib/auth-utils"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import { getGlobalAdminHealth, getKitaOverviewRows, roleOrder, } from "./_lib/data"; import { KitaDeleteDialog } from "./_components/kita-delete-dialog"; export const metadata: Metadata = { title: "Superadmin · Kita-Planer", }; const numberFormat = new Intl.NumberFormat("de-DE"); function formatDate(date: Date | null) { if (!date) return "Nie"; return new Intl.DateTimeFormat("de-DE", { dateStyle: "medium", timeStyle: "short", }).format(date); } export default async function AdminPage() { await requireRole([UserRole.SUPERADMIN]); const [health, kitas] = await Promise.all([ getGlobalAdminHealth(), getKitaOverviewRows(), ]); const totalUsers = kitas.reduce((sum, kita) => sum + kita.counts.users, 0); const totalChildren = kitas.reduce( (sum, kita) => sum + kita.counts.activeChildren, 0, ); const needsAttention = health.lockedTenantUsers + health.missingConsent + health.openInvitations + health.orphanTenantUsers; return (

Kita-Verwaltung

Systemweite Übersicht, read-only Diagnose und Support-Aktionen.

0} /> 0} />
{health.orphanTenantUsers > 0 && (
{health.orphanTenantUsers} tenant-lose Nicht-Superadmin-Benutzer

Diese Konten sind keiner Kita zugeordnet und sollten separat bereinigt werden. V1 verwaltet nur tenant-gebundene Benutzer.

)} Alle Kitas Diagnose-Links sind read-only; Löschungen benötigen eine exakte Namensbestätigung. {kitas.length === 0 ? (
Noch keine Kitas angelegt.
) : ( Kita Status Counts Rollen Letzter Login Aktionen {kitas.map((kita) => { const warnings = kita.counts.lockedUsers + kita.counts.missingConsent + kita.counts.openInvitations + kita.counts.familiesWithoutUsers; return (
{kita.name}
{kita.slug}
{warnings === 0 ? ( Unauffällig ) : ( {warnings} Hinweise )} {kita.counts.lockedUsers > 0 && ( {kita.counts.lockedUsers} gesperrt )} {kita.counts.openInvitations > 0 && ( {kita.counts.openInvitations} Einladungen )}
{kita.counts.users} Benutzer {kita.counts.families} Familien {kita.counts.activeChildren} Kinder {kita.counts.termine} Termine
{roleOrder.map((role) => kita.roleCounts[role] > 0 ? ( {role}: {kita.roleCounts[role]} ) : null, )}
{formatDate(kita.lastLoginAt)}
); })}
)}
); } function MetricCard({ icon: Icon, label, value, description, attention = false, }: { icon: typeof Building2; label: string; value: number; description: string; attention?: boolean; }) { return (
{label}
{numberFormat.format(value)}

{description}

); }