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
+128 -88
View File
@@ -1,13 +1,14 @@
"use client";
import Link from "next/link";
import { useMemo, useTransition } from "react";
import { useMemo, useState, useTransition } from "react";
import { AbsenceReason } from "@prisma/client";
import { Baby, CalendarX2, Check, ChevronRight, Loader2 } from "lucide-react";
import { reasonColor, reasonLabel } from "@/lib/absence-utils";
import { toast } from "sonner";
import { reportAbsence } from "@/actions/absences";
import { AbsenceManagementActions } from "@/components/absence-management-actions";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import {
@@ -40,6 +41,7 @@ type AbsenceListItem = {
note: string | null;
startDate: string;
endDate: string;
updatedAt: string;
};
export function AbsenceCard({
@@ -47,10 +49,11 @@ export function AbsenceCard({
today,
}: {
childOptions: ChildOption[];
absences: AbsenceListItem[];
today: string;
}) {
const [isPending, startTransition] = useTransition();
const [startDate, setStartDate] = useState(today);
const [endDate, setEndDate] = useState(today);
const defaultChildId = childOptions[0]?.id;
const hasChildren = childOptions.length > 0;
@@ -92,92 +95,113 @@ export function AbsenceCard({
<CardContent>
{hasChildren ? (
<form action={handleSubmit}>
<div className="grid gap-4 md:grid-cols-2">
<FieldLabel label="Welches Kind?">
<Select name="childId" defaultValue={defaultChildId} required>
<SelectTrigger>
<SelectValue placeholder="Kind auswählen" />
</SelectTrigger>
<SelectContent>
{childOptions.map((child) => (
<SelectItem key={child.id} value={child.id}>
{child.name}
<form
onReset={() => {
setStartDate(today);
setEndDate(today);
}}
onSubmit={(event) => {
event.preventDefault();
handleSubmit(new FormData(event.currentTarget));
}}
>
<fieldset disabled={isPending}>
<div className="grid gap-4 md:grid-cols-2">
<FieldLabel label="Welches Kind?">
<Select name="childId" defaultValue={defaultChildId} required>
<SelectTrigger>
<SelectValue placeholder="Kind auswählen" />
</SelectTrigger>
<SelectContent>
{childOptions.map((child) => (
<SelectItem key={child.id} value={child.id}>
{child.name}
</SelectItem>
))}
</SelectContent>
</Select>
</FieldLabel>
<FieldLabel label="Grund">
<Select
name="reason"
defaultValue={AbsenceReason.ILLNESS}
required
>
<SelectTrigger>
<SelectValue placeholder="Grund auswählen" />
</SelectTrigger>
<SelectContent>
<SelectItem value={AbsenceReason.ILLNESS}>
Krank
</SelectItem>
))}
</SelectContent>
</Select>
</FieldLabel>
<SelectItem value={AbsenceReason.VACATION}>
Urlaub
</SelectItem>
<SelectItem value={AbsenceReason.OTHER}>
Sonstiges
</SelectItem>
</SelectContent>
</Select>
</FieldLabel>
<FieldLabel label="Grund">
<Select
name="reason"
defaultValue={AbsenceReason.ILLNESS}
required
>
<SelectTrigger>
<SelectValue placeholder="Grund auswählen" />
</SelectTrigger>
<SelectContent>
<SelectItem value={AbsenceReason.ILLNESS}>Krank</SelectItem>
<SelectItem value={AbsenceReason.VACATION}>
Urlaub
</SelectItem>
<SelectItem value={AbsenceReason.OTHER}>
Sonstiges
</SelectItem>
</SelectContent>
</Select>
</FieldLabel>
<FieldLabel label="Von" htmlFor="absence-startDate">
<Input
id="absence-startDate"
name="startDate"
type="date"
value={startDate}
min={today}
onChange={(event) => {
const date = event.target.value;
setStartDate(date);
if (date > endDate) setEndDate(date);
}}
required
/>
</FieldLabel>
<FieldLabel label="Von" htmlFor="absence-startDate">
<Input
id="absence-startDate"
name="startDate"
type="date"
defaultValue={today}
required
/>
</FieldLabel>
<FieldLabel label="Bis" htmlFor="absence-endDate">
<Input
id="absence-endDate"
name="endDate"
type="date"
value={endDate}
min={startDate}
onChange={(event) => setEndDate(event.target.value)}
required
/>
</FieldLabel>
<FieldLabel label="Bis" htmlFor="absence-endDate">
<Input
id="absence-endDate"
name="endDate"
type="date"
defaultValue={today}
required
/>
</FieldLabel>
<div className="grid gap-2 md:col-span-2">
<Label
htmlFor="absence-note"
className="text-xs font-semibold text-[var(--ink-soft)]"
>
Bemerkung{" "}
<span className="font-medium text-[var(--ink-faint)]">
optional
</span>
</Label>
<Textarea
id="absence-note"
name="note"
rows={4}
placeholder="z. B. voraussichtlich wieder da am Freitag."
/>
<div className="grid gap-2 md:col-span-2">
<Label
htmlFor="absence-note"
className="text-xs font-semibold text-[var(--ink-soft)]"
>
Bemerkung{" "}
<span className="font-medium text-[var(--ink-faint)]">
optional
</span>
</Label>
<Textarea
id="absence-note"
name="note"
rows={4}
placeholder="z. B. voraussichtlich wieder da am Freitag."
/>
</div>
</div>
</div>
<div className="mt-7 flex items-center justify-between border-t border-[var(--hairline-soft)] pt-5">
<Button type="reset" variant="ghost">
Zurücksetzen
</Button>
<Button type="submit" disabled={isPending}>
{isPending ? <Loader2 className="animate-spin" /> : <Check />}
Abwesenheit melden
</Button>
</div>
<div className="mt-7 flex items-center justify-between border-t border-[var(--hairline-soft)] pt-5">
<Button type="reset" variant="ghost">
Zurücksetzen
</Button>
<Button type="submit" disabled={isPending}>
{isPending ? <Loader2 className="animate-spin" /> : <Check />}
Abwesenheit melden
</Button>
</div>
</fieldset>
</form>
) : (
<div className="flex min-h-72 flex-col items-center justify-center rounded-[14px] border border-dashed border-[var(--hairline)] bg-[var(--surface-2)] p-6 text-center">
@@ -201,8 +225,12 @@ export function AbsenceCard({
export function UpcomingAbsencesCard({
absences,
today,
team = false,
}: {
absences: AbsenceListItem[];
today: string;
team?: boolean;
}) {
return (
<Card>
@@ -233,16 +261,21 @@ export function UpcomingAbsencesCard({
) : (
<div className="divide-y divide-[var(--hairline-soft)]">
{absences.map((absence) => (
<AbsenceRow key={absence.id} absence={absence} />
<AbsenceRow
key={`${absence.id}-${absence.updatedAt}`}
absence={absence}
today={today}
team={team}
/>
))}
</div>
)}
<Link
href="/dashboard/admin/abwesenheiten"
href="/dashboard/abwesenheiten"
className="mt-4 inline-flex items-center gap-1 text-[13px] font-semibold text-[var(--accent-deep)] transition hover:gap-2 focus-visible:outline-none focus-visible:ring-[3px] focus-visible:ring-[var(--focus-ring)]"
>
Alle Abwesenheiten
Meine Abwesenheiten
<ChevronRight className="h-3.5 w-3.5" />
</Link>
</CardContent>
@@ -272,7 +305,15 @@ function FieldLabel({
);
}
function AbsenceRow({ absence }: { absence: AbsenceListItem }) {
function AbsenceRow({
absence,
today,
team,
}: {
absence: AbsenceListItem;
today: string;
team: boolean;
}) {
const { day, month, detail } = useMemo(() => {
const start = new Date(`${absence.startDate}T00:00:00`);
const end = new Date(`${absence.endDate}T00:00:00`);
@@ -327,9 +368,8 @@ function AbsenceRow({ absence }: { absence: AbsenceListItem }) {
{absence.note}
</p>
) : null}
<AbsenceManagementActions absence={absence} today={today} team={team} />
</div>
</div>
);
}