Improve family invitations and absence management flows

This commit is contained in:
t.indorf
2026-10-09 22:59:36 +02:00
parent 4702bf5abb
commit 8915fe7df6
29 changed files with 2803 additions and 617 deletions
+11 -17
View File
@@ -1,9 +1,9 @@
import { differenceInCalendarDays, format, isWeekend } from "date-fns";
import { TerminStatus, TerminType, UserRole } from "@prisma/client";
import { getDailyAbsences } from "@/actions/absences";
import { requireRole } from "@/lib/auth-utils";
import { prisma } from "@/lib/prisma";
import { absenceDate, absenceToday, isAbsenceDate } from "@/lib/absence-policy";
import { AbsencesClient } from "./_components/absences-client";
import { type AbsenceTableItem } from "./absence-table";
@@ -21,9 +21,10 @@ export default async function AdminAbwesenheitenPage({
]);
const resolvedSearchParams = await searchParams;
const kitaId = session.user.kitaId!;
const today = startOfLocalDay(new Date());
const todayKey = absenceToday();
const today = absenceDate(todayKey);
const selectedDate = parseDateParam(resolvedSearchParams.date, today);
const dateKey = format(selectedDate, "yyyy-MM-dd");
const dateKey = selectedDate.toISOString().slice(0, 10);
const result = await getDailyAbsences({ date: dateKey });
const absences = result.absences ?? [];
const childCount = await prisma.child.count({
@@ -46,9 +47,9 @@ export default async function AdminAbwesenheitenPage({
select: { title: true, type: true },
orderBy: { startDate: "asc" },
});
const isToday = dateKey === format(today, "yyyy-MM-dd");
const isTooFarFuture = differenceInCalendarDays(selectedDate, today) > 30;
const isClosedDay = isWeekend(selectedDate) || !!closure;
const isToday = dateKey === todayKey;
const isTooFarFuture = (selectedDate.getTime() - today.getTime()) / 86_400_000 > 30;
const isClosedDay = [0, 6].includes(selectedDate.getUTCDay()) || !!closure;
const tableItems: AbsenceTableItem[] = absences.map((absence) => ({
id: absence.id,
childName: absence.childName,
@@ -57,6 +58,7 @@ export default async function AdminAbwesenheitenPage({
note: absence.note,
startDate: absence.startDate,
endDate: absence.endDate,
updatedAt: absence.updatedAt,
}));
return (
@@ -67,11 +69,11 @@ export default async function AdminAbwesenheitenPage({
upcomingAbsenceCount={upcomingAbsenceCount}
closure={closure}
dateKey={dateKey}
selectedDateStr={selectedDate.toISOString()}
selectedDateStr={dateKey}
isToday={isToday}
isTooFarFuture={isTooFarFuture}
isClosedDay={isClosedDay}
todayStr={today.toISOString()}
todayStr={todayKey}
error={result.error ?? null}
/>
</div>
@@ -79,13 +81,5 @@ export default async function AdminAbwesenheitenPage({
}
function parseDateParam(value: string | undefined, fallback: Date) {
if (!value) return fallback;
const parsed = new Date(`${value}T00:00:00`);
return Number.isNaN(parsed.getTime()) ? fallback : parsed;
}
function startOfLocalDay(date: Date) {
const nextDate = new Date(date);
nextDate.setHours(0, 0, 0, 0);
return nextDate;
return value && isAbsenceDate(value) ? absenceDate(value) : fallback;
}