Files
immich-redaktions-plugin/src/app/admin/redaktionen/page.tsx
T
Leon TonhäuserandClaude Opus 5.5 9e938e4d07 feat: redesign portal UI with Sakani UI and add release notes
Replace the hand-rolled Tailwind/shadcn look with Sakani UI across the
editorial area, the admin area and all signed-out pages.

- AppShell (Sakani Sidebar + TopBar) for /redaktion and /admin, with a
  mobile drawer, theme toggle, sign-out, legal links and a "Was ist neu"
  button; PublicShell for login, registration, password, 2FA and errors.
- Shared primitives (Button, Card, Input, PageHeader) now render Sakani;
  components/ui/sakani.tsx is the client boundary for Server Components
  (Sakani ships no "use client") and adds FormSelect (native form value)
  and DataTable (element cells from the server).
- Legacy CSS variables map onto Sakani tokens; globals.css shrinks from
  ~2200 to ~700 lines. Geist replaces Inter. recharts/lucide-react dropped
  (charts via Sakani BarChart).
- Release notes popup per area, shown once per version (localStorage) and
  reopenable from the sidebar; native <dialog> for focus trapping.
- Fixes found while testing: TOTP field reused the typed password in
  clear text, modal dialogs sat top-left, invisible unchecked checkboxes
  in dark mode.
- Parallel run: compose.parallel.yaml, AUTO_RULE_SYNC_DISABLED switch and
  docs/operations.md §8 (start, rollback, cutover).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 18:24:05 +01:00

132 lines
6.1 KiB
TypeScript

import { desc, inArray, sql } from "drizzle-orm";
import Link from "next/link";
import { db } from "@/db/client";
import { editorialAccounts, usages } from "@/db/schema";
import { PageHeader } from "@/components/ui/page-header";
import { IconChevronRight } from "@sakaniui/react/icons";
import { Badge, Card, EmptyState } from "@/components/ui/sakani";
export default async function EditorialsPage() {
const [editorials, openUsageTotals] = await Promise.all([
db
.select({
id: editorialAccounts.id,
name: editorialAccounts.name,
contactName: editorialAccounts.contactName,
loginEmail: editorialAccounts.loginEmail,
status: editorialAccounts.status,
currentPriceCents: editorialAccounts.currentPriceCents,
createdAt: editorialAccounts.createdAt,
archivedAt: editorialAccounts.archivedAt,
})
.from(editorialAccounts)
.orderBy(desc(editorialAccounts.createdAt)),
// Nicht abgerechnete Nutzungen je Redaktion — dieselben Status, die auch
// in der Abrechnung wählbar sind (voided zählt nicht).
db
.select({
editorialId: usages.editorialAccountId,
openCents: sql<number>`COALESCE(SUM(${usages.priceCents}), 0)::int`,
})
.from(usages)
.where(inArray(usages.billingStatus, ["open", "reopened"]))
.groupBy(usages.editorialAccountId),
]);
const openCentsByEditorial = new Map(
openUsageTotals.map((total) => [total.editorialId, total.openCents]),
);
const activeEditorials = editorials.filter((e) => !e.archivedAt);
const archivedEditorials = editorials.filter((e) => e.archivedAt);
return (
<section className="flex flex-col gap-6">
<PageHeader
kicker="Kontoverwaltung"
title="Redaktionen"
description="Verwalte hier alle registrierten und archivierten Redaktionszugänge."
/>
{activeEditorials.length === 0 ? (
<EmptyState title="Noch keine aktiven Redaktionen registriert." description="Neue Registrierungen erscheinen hier zur Freigabe." />
) : (
<ul className="grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-3">
{activeEditorials.map((editorial) => {
const openCents = openCentsByEditorial.get(editorial.id) ?? 0;
return (
<li key={editorial.id}>
<Link href={`/admin/redaktionen/${editorial.id}`} className={CARD_LINK}>
<Card interactive className="h-full">
<div className="flex items-start justify-between gap-3">
<h2 className="text-base font-semibold text-[var(--color-fg-default)]">{editorial.name}</h2>
<Badge variant={STATUS[editorial.status]?.variant ?? "danger"}>
{STATUS[editorial.status]?.label ?? "Gesperrt"}
</Badge>
</div>
<dl className="grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 text-sm">
<dt className="text-[var(--color-fg-muted)]">Kontakt</dt>
<dd className="truncate">{editorial.contactName}</dd>
<dt className="text-[var(--color-fg-muted)]">E-Mail</dt>
<dd className="truncate">{editorial.loginEmail}</dd>
</dl>
<p className="mt-auto border-t border-[var(--color-border-subtle)] pt-3 text-sm font-medium">
{editorial.currentPriceCents === null
? "Preis noch nicht festgelegt"
: `Netto ${formatCents(editorial.currentPriceCents)}`}
<span
className={`ml-2 ${openCents > 0 ? "text-[var(--color-warning-fg)]" : "text-[var(--color-fg-muted)]"}`}
title="Summe der noch nicht abgerechneten Bildnutzungen"
>
· Offen {formatCents(openCents)}
</span>
</p>
</Card>
</Link>
</li>
);
})}
</ul>
)}
{archivedEditorials.length > 0 && (
<details className="group mt-6">
<summary className="mb-4 flex cursor-pointer list-none items-center gap-2 text-sm font-medium text-[var(--color-fg-muted)] hover:text-[var(--color-fg-default)]">
<IconChevronRight size={16} aria-hidden="true" className="transition-transform group-open:rotate-90" />
Archivierte Redaktionen ({archivedEditorials.length})
</summary>
<ul className="grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-3">
{archivedEditorials.map((editorial) => (
<li key={editorial.id}>
<Link href={`/admin/redaktionen/${editorial.id}`} className={CARD_LINK}>
<Card interactive className="h-full opacity-80">
<div className="flex items-start justify-between gap-3">
<h2 className="text-base font-semibold text-[var(--color-fg-muted)]">{editorial.name}</h2>
<Badge>Archiviert</Badge>
</div>
<p className="text-sm text-[var(--color-fg-muted)]">{editorial.contactName} · {editorial.loginEmail}</p>
<p className="text-sm text-[var(--color-fg-muted)]">
Archiviert am: {editorial.archivedAt ? new Date(editorial.archivedAt).toLocaleDateString("de-DE") : ""}
</p>
</Card>
</Link>
</li>
))}
</ul>
</details>
)}
</section>
);
}
const CARD_LINK =
"block h-full rounded-[var(--radius-xl)] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--color-border-focus)]";
const STATUS: Record<string, { label: string; variant: "success" | "warning" | "danger" }> = {
active: { label: "Aktiv", variant: "success" },
pending_approval: { label: "Ausstehend", variant: "warning" },
};
function formatCents(cents: number): string {
return new Intl.NumberFormat("de-DE", { style: "currency", currency: "EUR" }).format(cents / 100);
}