Merge branch 'codex/immich-redaktionsportal' into main

This commit is contained in:
Leon Tonhäuser committed 2026-08-11 11:19:30 +02:00
commit 64147a3282
13 files changed
+909 -106

No files matched your search

+80
View File
@@ -0,0 +1,80 @@
"use client";
import { useTheme } from "next-themes";
import {
Bar,
BarChart,
ResponsiveContainer,
Tooltip,
XAxis,
YAxis,
CartesianGrid,
} from "recharts";
type DownloadsChartProps = {
data: { date: string; downloads: number }[];
};
export function DownloadsChart({ data }: DownloadsChartProps) {
const { theme } = useTheme();
// Indigo primary color variables
const primaryColor = theme === "dark" ? "#6366f1" : "#4f46e5"; // indigo-500 : indigo-600
return (
<div className="h-[300px] w-full mt-4">
{data.length === 0 ? (
<div className="flex h-full items-center justify-center text-muted-foreground">
Keine Download-Daten in den letzten 30 Tagen verfügbar.
</div>
) : (
<ResponsiveContainer width="100%" height="100%">
<BarChart data={data} margin={{ top: 10, right: 10, left: -20, bottom: 0 }}>
<CartesianGrid strokeDasharray="3 3" vertical={false} stroke={theme === "dark" ? "#333" : "#e5e5e5"} />
<XAxis
dataKey="date"
stroke="#888888"
fontSize={12}
tickLine={false}
axisLine={false}
tickFormatter={(value) => {
const date = new Date(value);
return date.toLocaleDateString("de-DE", { day: "2-digit", month: "short" });
}}
/>
<YAxis
stroke="#888888"
fontSize={12}
tickLine={false}
axisLine={false}
tickFormatter={(value) => `${value}`}
allowDecimals={false}
/>
<Tooltip
cursor={{ fill: theme === "dark" ? "#ffffff10" : "#00000005" }}
contentStyle={{
backgroundColor: theme === "dark" ? "#1f2937" : "#ffffff",
borderColor: theme === "dark" ? "#374151" : "#e5e7eb",
borderRadius: "8px",
color: theme === "dark" ? "#f3f4f6" : "#111827",
boxShadow: "0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1)",
}}
labelFormatter={(label: any) => {
const date = new Date(label as string);
return date.toLocaleDateString("de-DE", { weekday: 'long', day: '2-digit', month: 'long', year: 'numeric' });
}}
formatter={(value: any) => [value as number, "Downloads"]}
/>
<Bar
dataKey="downloads"
fill={primaryColor}
radius={[4, 4, 0, 0]}
maxBarSize={40}
animationDuration={1000}
/>
</BarChart>
</ResponsiveContainer>
)}
</div>
);
}
+38
View File
@@ -7,6 +7,7 @@ import Link from "next/link";
import { PageHeader } from "@/components/ui/page-header";
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/card";
import { Button } from "@/components/ui/button";
import { DownloadsChart } from "./downloads-chart";
export default async function AdminDashboardPage() {
await requireAdmin(new Headers(await headers()));
@@ -48,6 +49,33 @@ export default async function AdminDashboardPage() {
.orderBy(desc(sql`COUNT(${usages.id})`))
.limit(5);
// 4. Time-series data for the last 30 days
const thirtyDaysAgo = new Date();
thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30);
const dailyDownloads = await db
.select({
date: sql<string>`DATE_TRUNC('day', ${usages.createdAt})::date::text`,
downloads: sql<number>`COUNT(${usages.id})::int`,
})
.from(usages)
.where(gte(usages.createdAt, thirtyDaysAgo))
.groupBy(sql`DATE_TRUNC('day', ${usages.createdAt})`)
.orderBy(sql`DATE_TRUNC('day', ${usages.createdAt})`);
// Fill in missing days
const chartData = [];
for (let i = 29; i >= 0; i--) {
const d = new Date();
d.setDate(d.getDate() - i);
const dateStr = d.toISOString().split('T')[0];
const record = dailyDownloads.find(r => r.date === dateStr);
chartData.push({
date: dateStr,
downloads: record ? record.downloads : 0,
});
}
const formatter = new Intl.NumberFormat("de-DE", { style: "currency", currency: "EUR" });
return (
@@ -83,6 +111,16 @@ export default async function AdminDashboardPage() {
</Card>
</div>
<Card>
<CardHeader>
<CardTitle>Downloads der letzten 30 Tage</CardTitle>
<CardDescription>Tägliche Nutzung des Bildarchivs über alle Redaktionen hinweg.</CardDescription>
</CardHeader>
<CardContent>
<DownloadsChart data={chartData} />
</CardContent>
</Card>
<div className="grid grid-cols-1 lg:grid-cols-2 gap-8">
<Card>
<CardHeader>
+68 -31
View File
@@ -1,9 +1,9 @@
import { desc } from "drizzle-orm";
import { PageHeader } from "@/components/ui/page-header";
import Link from "next/link";
import { db } from "@/db/client";
import { editorialAccounts } from "@/db/schema";
import { PageHeader } from "@/components/ui/page-header";
import { Card, CardContent } from "@/components/ui/card";
export default async function EditorialsPage() {
const editorials = await db
@@ -24,51 +24,88 @@ export default async function EditorialsPage() {
const archivedEditorials = editorials.filter((e) => e.archivedAt);
return (
<section className="content-section" aria-labelledby="editorials-title">
<div className="space-y-8 animate-in fade-in slide-in-from-bottom-4 duration-500 max-w-7xl">
<PageHeader
kicker="Kontoverwaltung"
title="Redaktionen"
titleId="editorials-title"
description="Verwalte hier alle registrierten und archivierten Redaktionszugänge."
/>
{activeEditorials.length === 0 ? (
<p>Noch keine aktiven Redaktionen registriert.</p>
<p className="text-muted-foreground">Noch keine aktiven Redaktionen registriert.</p>
) : (
<ul>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
{activeEditorials.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>
<Link key={editorial.id} href={`/admin/redaktionen/${editorial.id}`} className="block group">
<Card className="h-full transition-all duration-300 hover:shadow-md hover:border-primary-500/50 hover:-translate-y-1">
<CardContent className="p-6 flex flex-col h-full justify-between">
<div>
<h3 className="text-xl font-semibold mb-2 group-hover:text-primary-600 dark:group-hover:text-primary-400 transition-colors">
{editorial.name}
</h3>
<div className="space-y-1 text-sm text-muted-foreground">
<p className="flex items-center gap-2">
<span className="font-medium text-foreground">Kontakt:</span> {editorial.contactName}
</p>
<p className="flex items-center gap-2">
<span className="font-medium text-foreground">E-Mail:</span> {editorial.loginEmail}
</p>
<p className="flex items-center gap-2">
<span className="font-medium text-foreground">Status:</span>
<span className={`px-2 py-0.5 rounded-full text-xs font-medium ${
editorial.status === "active" ? "bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400" :
editorial.status === "pending_approval" ? "bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400" :
"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400"
}`}>
{editorial.status === "active" ? "Aktiv" : editorial.status === "pending_approval" ? "Ausstehend" : "Gesperrt"}
</span>
</p>
</div>
</div>
<div className="mt-6 pt-4 border-t border-border">
<p className="text-sm font-medium">
{editorial.currentPriceCents === null
? "Preis noch nicht festgelegt"
: `Netto ${formatCents(editorial.currentPriceCents)}`}
</p>
</div>
</CardContent>
</Card>
</Link>
))}
</ul>
</div>
)}
{archivedEditorials.length > 0 && (
<details className="mt-8">
<summary className="cursor-pointer text-sm font-semibold text-gray-500 uppercase tracking-widest">
<details className="mt-12 group">
<summary className="cursor-pointer flex items-center gap-2 text-sm font-semibold uppercase tracking-widest text-muted-foreground hover:text-foreground transition-colors mb-6 list-none">
<span className="bg-muted p-1 rounded-sm group-open:rotate-90 transition-transform">
▶
</span>
Archivierte Redaktionen ({archivedEditorials.length})
</summary>
<ul className="mt-4 opacity-75">
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 opacity-75 grayscale hover:grayscale-0 transition-all duration-500">
{archivedEditorials.map((editorial) => (
<li key={editorial.id}>
<a href={`/admin/redaktionen/${editorial.id}`} className="text-gray-600">
{editorial.name}
</a>
<p className="text-gray-500">
{editorial.contactName} · {editorial.loginEmail} · Archiviert am:{" "}
{editorial.archivedAt?.toLocaleDateString("de-DE")}
</p>
</li>
<Link key={editorial.id} href={`/admin/redaktionen/${editorial.id}`} className="block group">
<Card className="h-full transition-all duration-300 hover:shadow-sm">
<CardContent className="p-6">
<h3 className="text-lg font-semibold mb-2 text-muted-foreground group-hover:text-foreground transition-colors">
{editorial.name}
</h3>
<div className="space-y-1 text-sm text-muted-foreground">
<p>{editorial.contactName} · {editorial.loginEmail}</p>
<p className="pt-2">
Archiviert am: {editorial.archivedAt?.toLocaleDateString("de-DE")}
</p>
</div>
</CardContent>
</Card>
</Link>
))}
</ul>
</div>
</details>
)}
</section>
</div>
);
}