import { notFound } from "next/navigation"; import { db } from "@/lib/db"; import { requireAdmin } from "@/lib/auth"; import { Field, SelectField, TextareaField } from "@/components/Field"; import { AdminForm, ConfirmButton } from "@/components/admin/AdminForm"; import { Card, PageHead, Switch } from "@/components/admin/ui"; import { deletePage, savePage } from "../actions"; import { TemplatePicker } from "@/components/admin/TemplatePicker"; import { getLoadedVersions, LEGAL_TEMPLATES, LEGAL_TEMPLATES_VERSION, PLACEHOLDER_RE, templateForSlug } from "@/lib/legal-templates"; const fmtVersion = (v: string) => new Intl.DateTimeFormat("de-DE", { dateStyle: "long" }).format(new Date(v)); export default async function EditPage({ params, searchParams }: { params: Promise<{ id: string }>; searchParams: Promise<{ vorlage?: string }> }) { await requireAdmin("content.edit"); const { id } = await params; const { vorlage } = await searchParams; const page = id === "neu" ? null : await db.page.findUnique({ where: { id } }); if (id !== "neu" && !page) notFound(); const template = page ? templateForSlug(page.slug) : (LEGAL_TEMPLATES.find((t) => t.key === vorlage) ?? null); const loadedVersion = page ? (await getLoadedVersions())[page.id] : undefined; const outdated = Boolean(template && loadedVersion && loadedVersion < LEGAL_TEMPLATES_VERSION); const gaps = page ? [...new Set([...page.content.matchAll(PLACEHOLDER_RE)].map((m) => m[1]))] : []; return (
{page && Ansehen} Löschen}> {page && }
{(template || gaps.length > 0) && ( {outdated &&
Es gibt eine neuere Vorlage (Stand {fmtVersion(LEGAL_TEMPLATES_VERSION)}). Deine Seite basiert auf dem Stand vom {fmtVersion(loadedVersion!)}.
} {gaps.length > 0 &&
Im Text fehlt noch: {gaps.join(", ")}.
} ({ key, title, description }))} initial={template?.key ?? ""} isNew={!page} version={fmtVersion(LEGAL_TEMPLATES_VERSION)} />

Die Vorlagen sind sorgfältig erstellte Entwürfe, aber keine Rechtsberatung. Lass sie vor dem Veröffentlichen von einer Anwältin, einem Anwalt oder einem Händlerbund prüfen.

)}
Leerzeile = neuer Absatz
## Überschrift
- Listenpunkt
**fett**
[Linktext](https://…)
); }