import Link from "next/link"; import type { ComponentType } from "react"; import { format } from "date-fns"; import { de } from "date-fns/locale"; import { CalendarCheck2, CalendarClock, ChevronRight, Clock3, ListTodo, Users, type LucideProps, } from "lucide-react"; import { UserRole } from "@prisma/client"; import { requireKitaSession } from "@/lib/auth-utils"; import { getTargetMonthData } from "@/lib/date-utils"; import { prisma } from "@/lib/prisma"; import { Stat } from "@/components/ui/stat"; import { OnboardingDialog } from "@/components/OnboardingDialog"; import { AbsenceCard, UpcomingAbsencesCard } from "./absence-card"; export const metadata = { title: "Übersicht · Kita-Planer" }; export default async function DashboardPage() { const session = await requireKitaSession(); const now = new Date(); const today = new Date(now); today.setHours(0, 0, 0, 0); const targetData = getTargetMonthData(); const targetMonthStart = new Date( Date.UTC(targetData.targetYear, targetData.targetMonth - 1, 1), ); const targetMonthEnd = new Date( Date.UTC(targetData.targetYear, targetData.targetMonth, 1), ); const kita = await prisma.kita.findUniqueOrThrow({ where: { id: session.user.kitaId }, select: { name: true, notdienstModuleEnabled: true, notdienstMinPerChildPerMonth: true, terminModuleEnabled: true, adressbuchModuleEnabled: true, }, }); const [ familyCount, childCount, todayAbsenceCount, notdienstAvailabilityCount, onboardingUser, absenceChildren, upcomingAbsences, ] = await Promise.all([ prisma.family.count({ where: { kitaId: session.user.kitaId }, }), prisma.child.count({ where: { kitaId: session.user.kitaId, active: true }, }), prisma.absence.count({ where: { kitaId: session.user.kitaId, startDate: { lte: today }, endDate: { gte: today }, }, }), prisma.notdienstAvailability.count({ where: { kitaId: session.user.kitaId, date: { gte: targetMonthStart, lt: targetMonthEnd, }, }, }), prisma.user.findFirstOrThrow({ where: { id: session.user.id, kitaId: session.user.kitaId, }, select: { phone: true, street: true, postalCode: true, city: true, familyId: true, role: true, family: { select: { _count: { select: { children: true, }, }, }, }, }, }), session.user.familyId ? prisma.child.findMany({ where: { kitaId: session.user.kitaId, familyId: session.user.familyId, active: true, }, select: { id: true, firstName: true, lastName: true, }, orderBy: [{ lastName: "asc" }, { firstName: "asc" }], }) : Promise.resolve([]), session.user.familyId ? prisma.absence.findMany({ where: { kitaId: session.user.kitaId, endDate: { gte: today }, child: { familyId: session.user.familyId, }, }, select: { id: true, reason: true, note: true, startDate: true, endDate: true, child: { select: { firstName: true, lastName: true, }, }, }, orderBy: [{ startDate: "asc" }], take: 6, }) : Promise.resolve([]), ]); const canReportAbsences = session.user.role !== UserRole.ERZIEHER; const requiredNotdienstDays = Math.max( childCount * kita.notdienstMinPerChildPerMonth, 1, ); const openNotdienstDays = Math.max( requiredNotdienstDays - notdienstAvailabilityCount, 0, ); const todayPresentCount = Math.max(childCount - todayAbsenceCount, 0); const firstName = session.user.name?.split(" ")[0] ?? session.user.email?.split("@")[0] ?? "zusammen"; return (

ÜBERSICHT · {kita.name}

Willkommen{" "} zurück , {firstName}.

Heute, {format(now, "EEEE, d. MMMM yyyy", { locale: de })}. Hier siehst du auf einen Blick, was bei {kita.name} ansteht und kannst dein Kind schnell für Abwesenheiten melden.

{format(now, "EEE, d. MMM yyyy", { locale: de })}
{canReportAbsences ? ( ({ id: child.id, name: `${child.firstName} ${child.lastName}`, }))} absences={upcomingAbsences.map((absence) => ({ id: absence.id, childName: `${absence.child.firstName} ${absence.child.lastName}`, reason: absence.reason, note: absence.note, startDate: format(absence.startDate, "yyyy-MM-dd"), endDate: format(absence.endDate, "yyyy-MM-dd"), }))} /> ) : null}

Schnellstart

Häufige Aktionen für Vorstand und Koordination.

{kita.terminModuleEnabled ? ( ) : null} {kita.notdienstModuleEnabled ? ( ) : null} {kita.adressbuchModuleEnabled ? ( ) : null}
); } function QuickCard({ href, icon: Icon, title, sub, }: { href: string; icon: ComponentType; title: string; sub: string; }) { return (

{title}

{sub}

); }