Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SvuGvHpbAQ4syfuLuRvutL
69 lines
4.6 KiB
TypeScript
69 lines
4.6 KiB
TypeScript
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 (
|
|
<div className="ad-wrap">
|
|
<PageHead title={page?.title ?? "Neue Seite"} back={{ href: "/admin/seiten", label: "Seiten" }}>
|
|
{page && <a className="sm-btn sm-btn--secondary" href={`/seite/${page.slug}`} target="_blank">Ansehen</a>}
|
|
</PageHead>
|
|
<AdminForm action={savePage} extraActions={page && <ConfirmButton inForm action={deletePage} confirm="Seite löschen?">Löschen</ConfirmButton>}>
|
|
{page && <input type="hidden" name="id" value={page.id} />}
|
|
<div className="ad-grid ad-grid--2-1">
|
|
<Card title="Inhalt">
|
|
<Field label="Titel" name="title" defaultValue={page?.title} required />
|
|
<TextareaField label="Text" name="content" defaultValue={page?.content} rows={22} style={{ fontFamily: "var(--font-sans)", minHeight: 420 }} />
|
|
</Card>
|
|
<div>
|
|
{(template || gaps.length > 0) && (
|
|
<Card title="Rechtstext-Vorlage" lead="Aus deinen Shop-Einstellungen zusammengestellt: Firma, Zahlungsarten, DHL, Login und Newsletter.">
|
|
{outdated && <div className="ad-alert body-sm" style={{ marginBottom: "var(--space-4)" }}>Es gibt eine neuere Vorlage (Stand {fmtVersion(LEGAL_TEMPLATES_VERSION)}). Deine Seite basiert auf dem Stand vom {fmtVersion(loadedVersion!)}.</div>}
|
|
{gaps.length > 0 && <div className="ad-alert body-sm" style={{ marginBottom: "var(--space-4)" }}>Im Text fehlt noch: {gaps.join(", ")}.</div>}
|
|
<TemplatePicker options={LEGAL_TEMPLATES.map(({ key, title, description }) => ({ key, title, description }))} initial={template?.key ?? ""} isNew={!page} version={fmtVersion(LEGAL_TEMPLATES_VERSION)} />
|
|
<p className="body-sm ad-muted" style={{ margin: "var(--space-4) 0 0" }}>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.</p>
|
|
</Card>
|
|
)}
|
|
<Card title="Einstellungen">
|
|
<Switch name="published" label="Veröffentlicht" defaultChecked={page?.published ?? true} />
|
|
<SelectField label="Im Fußbereich zeigen" name="showInFooter" defaultValue={page?.showInFooter ?? ""}>
|
|
<option value="">Nicht zeigen</option>
|
|
<option value="service">Spalte „Service“</option>
|
|
<option value="company">Spalte „Über uns“</option>
|
|
<option value="legal">Unterste Zeile (Rechtliches)</option>
|
|
</SelectField>
|
|
<Field label="Web-Adresse" name="slug" defaultValue={page?.slug} hint="Leer lassen für automatisch." />
|
|
<Field label="Reihenfolge" name="sort" type="number" defaultValue={page?.sort ?? 0} />
|
|
</Card>
|
|
<Card title="So formatierst du">
|
|
<div className="ad-help">
|
|
Leerzeile = neuer Absatz<br />
|
|
<code>## Überschrift</code><br />
|
|
<code>- Listenpunkt</code><br />
|
|
<code>**fett**</code><br />
|
|
<code>[Linktext](https://…)</code>
|
|
</div>
|
|
</Card>
|
|
</div>
|
|
</div>
|
|
</AdminForm>
|
|
</div>
|
|
);
|
|
}
|