feat: add editorial approval and account guards

This commit is contained in:
Leon Tonhäuser committed 2026-08-09 21:15:30 +02:00
1 parent a8d4e54ffb
commit 3584b4a7a7
9 files changed
+878 -1

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
import type { ReactNode } from "react";
import { headers } from "next/headers";
import Link from "next/link";
import { requireAdmin } from "@/modules/auth/principal";
export default async function AdminLayout({ children }: Readonly<{ children: ReactNode }>) {
await requireAdmin(new Headers(await headers()));
return (
<main className="portal-shell">
<header className="masthead">
<Link className="wordmark" href="/admin">
Leon Tonhäuser
</Link>
<span className="section-label">Administration</span>
</header>
<nav aria-label="Administration">
<Link href="/admin/redaktionen">Redaktionen</Link>
</nav>
{children}
</main>
);
}
+74
View File
@@ -0,0 +1,74 @@
import { and, eq, isNull } from "drizzle-orm";
import { notFound } from "next/navigation";
import { db } from "@/db/client";
import { albumGrants, editorialAccounts } from "@/db/schema";
export default async function EditorialDetailPage({
params,
}: Readonly<{ params: Promise<{ id: string }> }>) {
const { id } = await params;
const [editorial] = await db
.select({
id: editorialAccounts.id,
name: editorialAccounts.name,
contactName: editorialAccounts.contactName,
loginEmail: editorialAccounts.loginEmail,
status: editorialAccounts.status,
emailVerifiedAt: editorialAccounts.emailVerifiedAt,
currentPriceCents: editorialAccounts.currentPriceCents,
})
.from(editorialAccounts)
.where(eq(editorialAccounts.id, id))
.limit(1);
if (!editorial) {
notFound();
}
const [grant] = await db
.select({ id: albumGrants.id })
.from(albumGrants)
.where(
and(eq(albumGrants.editorialAccountId, editorial.id), isNull(albumGrants.revokedAt)),
)
.limit(1);
return (
<section className="content-section" aria-labelledby="editorial-title">
<p className="eyebrow">Redaktion</p>
<h1 id="editorial-title">{editorial.name}</h1>
<dl>
<dt>Ansprechperson</dt>
<dd>{editorial.contactName}</dd>
<dt>Anmelde-E-Mail</dt>
<dd>{editorial.loginEmail}</dd>
<dt>Status</dt>
<dd>{editorial.status}</dd>
<dt>E-Mail bestätigt</dt>
<dd>{editorial.emailVerifiedAt ? "Ja" : "Nein"}</dd>
<dt>Individueller Nettopreis</dt>
<dd>
{editorial.currentPriceCents === null
? "Noch nicht festgelegt"
: formatCents(editorial.currentPriceCents)}
</dd>
</dl>
<section aria-labelledby="approval-title">
<h2 id="approval-title">Freigabe</h2>
<button type="button" disabled aria-describedby="approval-help">
Redaktion freigeben
</button>
<p id="approval-help">
{grant
? "Die Freigabe bleibt bis zur Verwaltungsoberfläche für Albumrechte deaktiviert."
: "Eine Freigabe ist erst möglich, wenn mindestens ein aktives Albumrecht zugewiesen wurde. Die Verwaltung der Albumrechte folgt im nächsten Schritt."}
</p>
</section>
</section>
);
}
function formatCents(cents: number): string {
return new Intl.NumberFormat("de-DE", { style: "currency", currency: "EUR" }).format(cents / 100);
}
+47
View File
@@ -0,0 +1,47 @@
import { desc } from "drizzle-orm";
import { db } from "@/db/client";
import { editorialAccounts } from "@/db/schema";
export default async function EditorialsPage() {
const editorials = await db
.select({
id: editorialAccounts.id,
name: editorialAccounts.name,
contactName: editorialAccounts.contactName,
loginEmail: editorialAccounts.loginEmail,
status: editorialAccounts.status,
currentPriceCents: editorialAccounts.currentPriceCents,
createdAt: editorialAccounts.createdAt,
})
.from(editorialAccounts)
.orderBy(desc(editorialAccounts.createdAt));
return (
<section className="content-section" aria-labelledby="editorials-title">
<p className="eyebrow">Kontoverwaltung</p>
<h1 id="editorials-title">Redaktionen</h1>
{editorials.length === 0 ? (
<p>Noch keine Redaktionen registriert.</p>
) : (
<ul>
{editorials.map((editorial) => (
<li key={editorial.id}>
<a href={`/admin/redaktionen/${editorial.id}`}>{editorial.name}</a>
<p>
{editorial.contactName} · {editorial.loginEmail} · Status: {editorial.status}
{editorial.currentPriceCents === null
? " · Preis noch nicht festgelegt"
: ` · Netto ${formatCents(editorial.currentPriceCents)}`}
</p>
</li>
))}
</ul>
)}
</section>
);
}
function formatCents(cents: number): string {
return new Intl.NumberFormat("de-DE", { style: "currency", currency: "EUR" }).format(cents / 100);
}