Release 2.3.0: calendar categories, reservations, month view, dashboard

- Admin-managed event categories (name + one of Sakani's 8 calendar
  colors) at /admin/kalender/kategorien; events pick a category.
- Calendar as Sakani MonthCalendar with a German header and a color
  legend, for editorials and admins.
- "Zu meinen Alben hinzufügen" replaces RSVP: grants the event album at
  once when it exists, otherwise reserves it; the auto-rule scheduler
  grants pending reservations once the album appears. Editorials see when
  an auto rule already covers the event. event_responses is dropped.
- New admin dashboard: to-dos, next events, 30-day figures, activity.
- Photo grid reads left to right in uniform 3:2 tiles.
- Release notes 2.3.0 seeded (migration 0008).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Leon TonhäuserandClaude Opus 5.5 committed 2026-11-30 23:45:59 +01:00
1 parent 4fb6f2d373
commit 2775b406bf
39 files changed
+9754 -701

No files matched your search

@@ -13,10 +13,12 @@ export function CalendarEventForm({
action,
defaultEventDate,
albums,
categories,
}: Readonly<{
action: (state: CalendarActionResult, formData: FormData) => Promise<CalendarActionResult>;
defaultEventDate: string;
albums: Array<{ id: string; albumName: string }>;
categories: Array<{ id: string; name: string }>;
}>) {
const titleId = useId();
const dateId = useId();
@@ -49,6 +51,16 @@ export function CalendarEventForm({
value={title}
/>
<div className="flex flex-col gap-4 sm:flex-row">
<div className="sm:w-64">
<FormSelect
label="Kategorie"
name="categoryId"
options={[
{ label: "Ohne Kategorie", value: "" },
...categories.map((category) => ({ label: category.name, value: category.id })),
]}
/>
</div>
<div className="sm:w-48">
<Input defaultValue={defaultEventDate} id={dateId} label="Datum" name="eventDate" required type="date" />
</div>
+6 -4
View File
@@ -19,6 +19,7 @@ export async function createCalendarEventAction(
const title = formData.get("title");
const eventDate = formData.get("eventDate");
const immichAlbumId = formData.get("immichAlbumId");
const categoryId = formData.get("categoryId");
if (typeof title !== "string" || typeof eventDate !== "string") {
return { ok: false, message: "Bitte Titel und Datum ausfüllen." };
@@ -29,6 +30,7 @@ export async function createCalendarEventAction(
title,
eventDate,
immichAlbumId: typeof immichAlbumId === "string" && immichAlbumId ? immichAlbumId : null,
categoryId: typeof categoryId === "string" && categoryId ? categoryId : null,
adminUserId: principal.userId,
});
} catch (error) {
@@ -40,7 +42,7 @@ export async function createCalendarEventAction(
return {
ok: true,
message:
"Termin angelegt. Sobald ein passendes Album in Immich erscheint, können Redaktionen es selbst freischalten.",
"Termin angelegt. Redaktionen können ihn sofort vormerken; das Album wird freigeschaltet, sobald es in Immich erscheint.",
};
}
@@ -72,13 +74,13 @@ function calendarErrorMessage(error: unknown): string {
INVALID_TITLE: "Bitte geben Sie einen Titel mit 1 bis 200 Zeichen ein.",
INVALID_EVENT_DATE: "Bitte wählen Sie ein gültiges Datum.",
INVALID_ALBUM: "Das gewählte Album existiert nicht mehr in Immich.",
INVALID_STATUS: "Ungültige Rückmeldung.",
INVALID_CATEGORY: "Die gewählte Kategorie existiert nicht mehr.",
EVENT_NOT_FOUND: "Dieser Termin existiert nicht mehr.",
EVENT_ALBUM_UNAVAILABLE: "Zu diesem Termin ist noch kein Album verknüpft.",
RESERVATION_NOT_FOUND: "Diese Vormerkung existiert nicht mehr.",
IMMICH_UNAVAILABLE: "Immich ist gerade nicht erreichbar. Bitte später erneut versuchen.",
RATE_LIMITED: "Zu viele Anfragen. Bitte kurz warten.",
};
return messages[error.code] ?? "Der Termin konnte nicht gespeichert werden.";
return messages[error.code];
}
return "Der Termin konnte nicht gespeichert werden.";
}
@@ -0,0 +1,84 @@
"use client";
import { useId, useState, useTransition } from "react";
import { Alert, Input } from "@sakaniui/react";
import { CategoryDot } from "@/components/calendar/category-legend";
import { Button } from "@/components/ui/button";
import { Card } from "@/components/ui/sakani";
import { CATEGORY_COLOR_LABELS, CATEGORY_COLORS, type CategoryColor } from "@/modules/calendar/colors";
import type { CategoryActionResult } from "./actions";
export function CategoryForm({
action,
}: Readonly<{ action: (state: CategoryActionResult, formData: FormData) => Promise<CategoryActionResult> }>) {
const nameId = useId();
const [name, setName] = useState("");
const [color, setColor] = useState<CategoryColor>("blue");
const [state, setState] = useState<CategoryActionResult>({ ok: true, message: "" });
const [pending, startTransition] = useTransition();
const handleSubmit = (formData: FormData) => {
startTransition(async () => {
const result = await action({ ok: true, message: "" }, formData);
setState(result);
if (result.ok) setName("");
});
};
return (
<Card title="Neue Kategorie">
<form action={handleSubmit} className="flex flex-col gap-4">
<div className="sm:max-w-md">
<Input
id={nameId}
label="Name"
maxLength={80}
name="name"
onChange={(event) => setName(event.target.value)}
placeholder="z. B. Fußball - 1. Bundesliga"
required
value={name}
/>
</div>
<fieldset className="flex flex-col gap-2">
<legend className="mb-2 text-sm font-medium text-[var(--color-fg-default)]">Farbe</legend>
<div className="flex flex-wrap gap-2">
{CATEGORY_COLORS.map((option) => (
<label
className={`flex min-h-10 cursor-pointer items-center gap-2 rounded-full border px-3 text-sm transition-colors has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 ${
color === option
? "border-[var(--color-fg-default)] bg-[var(--color-bg-subtle)] font-medium"
: "border-[var(--color-border-subtle)] text-[var(--color-fg-muted)] hover:bg-[var(--color-bg-subtle)]"
}`}
key={option}
>
<input
checked={color === option}
className="sr-only"
name="color"
onChange={() => setColor(option)}
type="radio"
value={option}
/>
<CategoryDot color={option} />
{CATEGORY_COLOR_LABELS[option]}
</label>
))}
</div>
</fieldset>
<div>
<Button type="submit" disabled={pending}>
{pending ? "Wird gespeichert …" : "Kategorie speichern"}
</Button>
</div>
{state.message ? (
<div aria-live="polite">
<Alert color={state.ok ? "success" : "danger"} description={state.message} />
</div>
) : null}
</form>
</Card>
);
}
@@ -0,0 +1,46 @@
"use client";
import { useState, useTransition } from "react";
import { Button } from "@/components/ui/button";
import type { CategoryActionResult } from "./actions";
export function DeleteCategoryButton({
action,
categoryId,
inUse,
}: Readonly<{
action: (state: CategoryActionResult, formData: FormData) => Promise<CategoryActionResult>;
categoryId: string;
inUse: boolean;
}>) {
const [state, setState] = useState<CategoryActionResult>({ ok: true, message: "" });
const [pending, startTransition] = useTransition();
const handleClick = () => {
const formData = new FormData();
formData.set("categoryId", categoryId);
startTransition(async () => setState(await action({ ok: true, message: "" }, formData)));
};
return (
<div className="flex flex-col items-end gap-1">
<Button
disabled={pending || inUse}
onClick={handleClick}
size="sm"
title={inUse ? "Wird noch von Terminen genutzt" : undefined}
type="button"
variant="outline"
>
{pending ? "…" : "Löschen"}
</Button>
{state.ok ? null : (
<p className="text-xs text-[var(--color-danger-fg)]" role="alert">
{state.message}
</p>
)}
</div>
);
}
@@ -0,0 +1,65 @@
"use server";
import { revalidatePath } from "next/cache";
import { headers } from "next/headers";
import { requireAdmin } from "@/modules/auth/principal";
import { CategoryServiceError, categoryService } from "@/modules/calendar/categories";
export type CategoryActionResult = { ok: boolean; message: string };
const MESSAGES: Record<CategoryServiceError["code"], string> = {
INVALID_NAME: "Bitte geben Sie einen Namen mit 1 bis 80 Zeichen ein.",
INVALID_COLOR: "Bitte wählen Sie eine Farbe aus der Liste.",
DUPLICATE_NAME: "Diese Kategorie gibt es schon.",
CATEGORY_IN_USE: "Die Kategorie wird noch von Terminen genutzt und kann nicht gelöscht werden.",
CATEGORY_NOT_FOUND: "Diese Kategorie existiert nicht mehr.",
};
function errorMessage(error: unknown, fallback: string): string {
return error instanceof CategoryServiceError ? MESSAGES[error.code] : fallback;
}
function revalidate() {
revalidatePath("/admin/kalender/kategorien");
revalidatePath("/admin/kalender");
revalidatePath("/redaktion/kalender");
}
export async function createCategoryAction(
_prevState: CategoryActionResult,
formData: FormData,
): Promise<CategoryActionResult> {
const principal = await requireAdmin(new Headers(await headers()));
const name = formData.get("name");
const color = formData.get("color");
try {
await categoryService.createCategory({
name: typeof name === "string" ? name : "",
color: typeof color === "string" ? color : "",
adminUserId: principal.userId,
});
} catch (error) {
return { ok: false, message: errorMessage(error, "Die Kategorie konnte nicht gespeichert werden.") };
}
revalidate();
return { ok: true, message: "Kategorie gespeichert." };
}
export async function deleteCategoryAction(
_prevState: CategoryActionResult,
formData: FormData,
): Promise<CategoryActionResult> {
const principal = await requireAdmin(new Headers(await headers()));
const id = formData.get("categoryId");
if (typeof id !== "string" || id.length === 0) {
return { ok: false, message: "Ungültige Kennung." };
}
try {
await categoryService.deleteCategory({ id, adminUserId: principal.userId });
} catch (error) {
return { ok: false, message: errorMessage(error, "Die Kategorie konnte nicht gelöscht werden.") };
}
revalidate();
return { ok: true, message: "" };
}
@@ -0,0 +1,62 @@
import Link from "next/link";
import { CategoryDot } from "@/components/calendar/category-legend";
import { Button } from "@/components/ui/button";
import { PageHeader } from "@/components/ui/page-header";
import { Card, EmptyState } from "@/components/ui/sakani";
import { categoryService } from "@/modules/calendar/categories";
import { CATEGORY_COLOR_LABELS } from "@/modules/calendar/colors";
import { requireAdminPage } from "../../access";
import { CategoryForm } from "./CategoryForm";
import { DeleteCategoryButton } from "./DeleteCategoryButton";
import { createCategoryAction, deleteCategoryAction } from "./actions";
export default async function AdminCategoriesPage() {
await requireAdminPage();
const categories = await categoryService.listCategories();
return (
<section className="flex flex-col gap-6">
<PageHeader
kicker="Planung · Kalender"
title="Kategorien"
description="Sportarten und Ligen für den Kalender. Die Farbe erscheint bei den Terminen und in der Legende."
>
<Button asChild variant="outline">
<Link href="/admin/kalender">Zum Kalender</Link>
</Button>
</PageHeader>
<CategoryForm action={createCategoryAction} />
<Card title="Gespeicherte Kategorien">
{categories.length === 0 ? (
<EmptyState title="Noch keine Kategorien" description="Legen Sie oben die erste Kategorie an." />
) : (
<ul className="flex flex-col divide-y divide-[var(--color-border-subtle)]">
{categories.map((category) => (
<li className="flex items-center justify-between gap-4 py-3" key={category.id}>
<div className="flex min-w-0 items-center gap-3">
<CategoryDot color={category.color} />
<div className="min-w-0">
<p className="font-medium break-words">{category.name}</p>
<p className="text-xs text-[var(--color-fg-muted)]">
{CATEGORY_COLOR_LABELS[category.color]} ·{" "}
{category.eventCount === 1 ? "1 Termin" : `${category.eventCount} Termine`}
</p>
</div>
</div>
<DeleteCategoryButton
action={deleteCategoryAction}
categoryId={category.id}
inUse={category.eventCount > 0}
/>
</li>
))}
</ul>
)}
</Card>
</section>
);
}
+71 -51
View File
@@ -1,97 +1,118 @@
import Link from "next/link";
import { CategoryDot, CategoryLegend } from "@/components/calendar/category-legend";
import { EventMonth } from "@/components/calendar/event-month";
import { Button } from "@/components/ui/button";
import { PageHeader } from "@/components/ui/page-header";
import { Alert, Badge, Card, EmptyState } from "@/components/ui/sakani";
import { formatIsoDateGerman, isoDateInBerlin } from "@/modules/announcements/service";
import { categoryService } from "@/modules/calendar/categories";
import { calendarService } from "@/modules/calendar/service";
import { immichClient } from "@/modules/immich/client";
import { requireAdminPage } from "../access";
import { CalendarEventForm } from "./CalendarEventForm";
import { DeleteCalendarEventButton } from "./DeleteCalendarEventButton";
import { createCalendarEventAction, deleteCalendarEventAction } from "./actions";
export default async function AdminCalendarPage() {
const [{ events, immichUnavailable }, albums] = await Promise.all([
await requireAdminPage();
const [{ events, immichUnavailable }, albums, categories] = await Promise.all([
calendarService.listAdminEvents(),
immichClient.listAlbums().catch(() => []),
categoryService.listCategories(),
]);
const today = isoDateInBerlin(new Date());
return (
<div className="space-y-8 max-w-7xl animate-in fade-in slide-in-from-bottom-4 duration-500">
<section className="flex flex-col gap-6">
<PageHeader
kicker="Planung"
title="Kalender"
description="Termine für Redaktionen, z. B. kommende Spiele. Redaktionen melden zurück, ob sie da sind, und können das verknüpfte Album selbst freischalten. Alben ohne Kalender-Termin bleiben unsichtbar; automatische Zuweisungsregeln gelten unabhängig davon."
/>
description="Termine für Redaktionen, z. B. kommende Spiele. Redaktionen merken Termine vor und bekommen das verknüpfte Album automatisch, sobald es da ist. Alben ohne Termin bleiben unsichtbar; automatische Zuweisungsregeln gelten unabhängig davon."
>
<Button asChild variant="outline">
<Link href="/admin/kalender/kategorien">Kategorien verwalten</Link>
</Button>
</PageHeader>
<CalendarEventForm
action={createCalendarEventAction}
defaultEventDate={today}
albums={albums.map((album) => ({ id: album.id, albumName: album.albumName }))}
categories={categories.map((category) => ({ id: category.id, name: category.name }))}
defaultEventDate={today}
/>
{immichUnavailable ? (
<p className="bg-muted p-4 rounded-md text-sm" role="status">
Immich ist gerade nicht erreichbar. Verknüpfte Alben werden angezeigt, sobald die Verbindung wieder steht.
</p>
<Alert
color="warning"
description="Immich ist gerade nicht erreichbar. Verknüpfte Alben werden angezeigt, sobald die Verbindung wieder steht."
/>
) : null}
<section className="space-y-4" aria-labelledby="calendar-list-title">
<Card title="Monatsübersicht">
<EventMonth
events={events.map((event) => ({
id: event.id,
title: event.title,
eventDate: event.eventDate,
color: event.category?.color ?? null,
}))}
/>
<CategoryLegend categories={categories} showUncategorized={events.some((event) => !event.category)} />
</Card>
<section aria-labelledby="calendar-list-title" className="flex flex-col gap-4">
<div className="flex items-baseline justify-between">
<h2 id="calendar-list-title" className="text-xl font-semibold">
<h2 className="text-xl font-semibold" id="calendar-list-title">
Alle Termine
</h2>
<p className="text-sm text-muted-foreground">{events.length} insgesamt</p>
<p className="text-sm text-[var(--color-fg-muted)]">{events.length} insgesamt</p>
</div>
{events.length === 0 ? (
<p className="text-muted-foreground py-8 text-center">
Noch keine Termine vorhanden. Legen Sie oben den ersten Termin an.
</p>
<EmptyState title="Noch keine Termine" description="Legen Sie oben den ersten Termin an." />
) : (
<ul className="space-y-3">
<ul className="flex flex-col gap-3">
{events.map((event) => {
const attending = event.responses.filter((response) => response.status === "attending");
const notAttending = event.responses.filter((response) => response.status === "not_attending");
const granted = event.reservations.filter((row) => row.grantedAt).length;
return (
<li
className="flex flex-col justify-between gap-4 rounded-xl border border-[var(--color-border-subtle)] bg-[var(--color-bg-surface)] p-4 outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-border-focus)] sm:flex-row sm:items-start"
id={`termin-${event.id}`}
key={event.id}
className="bg-card p-4 rounded-xl border border-border shadow-sm flex flex-col sm:flex-row sm:items-start gap-4 justify-between"
tabIndex={-1}
>
<div className="space-y-2 min-w-0">
<p className="font-semibold">
<div className="flex min-w-0 flex-col gap-2">
<p className="flex flex-wrap items-center gap-2 font-semibold">
{event.title}
{event.eventDate < today ? (
<span className="ml-2 text-xs font-normal text-muted-foreground">vorbei</span>
{event.eventDate < today ? <Badge>vorbei</Badge> : null}
</p>
<p className="flex flex-wrap items-center gap-x-2 gap-y-1 text-xs text-[var(--color-fg-muted)]">
<span>{formatIsoDateGerman(event.eventDate)}</span>
{event.category ? (
<span className="flex items-center gap-1.5">
· <CategoryDot color={event.category.color} /> {event.category.name}
</span>
) : null}
<span>· {event.album ? `Album: ${event.album.albumName}` : "Noch kein Album verknüpft"}</span>
</p>
<p className="text-xs text-muted-foreground">
{formatIsoDateGerman(event.eventDate)} ·{" "}
{event.album ? (
<span>Album: {event.album.albumName}</span>
) : (
<span>Noch kein Album verknüpft</span>
)}
</p>
{event.responses.length > 0 ? (
<div className="flex flex-wrap gap-1.5 text-xs">
{attending.map((response) => (
<span
key={response.editorialId}
className="rounded-full bg-green-600/10 px-2.5 py-1 font-medium text-green-700 dark:text-green-400"
>
{response.editorialName}: da
</span>
))}
{notAttending.map((response) => (
<span
key={response.editorialId}
className="rounded-full bg-muted px-2.5 py-1 text-muted-foreground"
>
{response.editorialName}: nicht da
</span>
))}
{event.reservations.length > 0 ? (
<div className="flex flex-col gap-1.5">
<p className="text-xs text-[var(--color-fg-muted)]">
{event.reservations.length === 1 ? "1 Vormerkung" : `${event.reservations.length} Vormerkungen`}
{granted > 0 ? `, ${granted} freigeschaltet` : ""}
</p>
<div className="flex flex-wrap gap-1.5">
{event.reservations.map((row) => (
<Badge key={row.editorialId} variant={row.grantedAt ? "success" : "neutral"}>
{row.editorialName}: {row.grantedAt ? "freigeschaltet" : "vorgemerkt"}
</Badge>
))}
</div>
</div>
) : (
<p className="text-xs text-muted-foreground">Noch keine Rückmeldungen.</p>
<p className="text-xs text-[var(--color-fg-muted)]">Noch keine Vormerkungen.</p>
)}
</div>
<DeleteCalendarEventButton action={deleteCalendarEventAction} eventId={event.id} />
@@ -101,7 +122,6 @@ export default async function AdminCalendarPage() {
</ul>
)}
</section>
</div>
</section>
);
}