78 lines
2.7 KiB
TypeScript
78 lines
2.7 KiB
TypeScript
import { desc } from "drizzle-orm";
|
|
|
|
import { PageHeader } from "@/components/ui/page-header";
|
|
|
|
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,
|
|
archivedAt: editorialAccounts.archivedAt,
|
|
})
|
|
.from(editorialAccounts)
|
|
.orderBy(desc(editorialAccounts.createdAt));
|
|
|
|
const activeEditorials = editorials.filter((e) => !e.archivedAt);
|
|
const archivedEditorials = editorials.filter((e) => e.archivedAt);
|
|
|
|
return (
|
|
<section className="content-section" aria-labelledby="editorials-title">
|
|
<PageHeader
|
|
kicker="Kontoverwaltung"
|
|
title="Redaktionen"
|
|
titleId="editorials-title"
|
|
/>
|
|
{activeEditorials.length === 0 ? (
|
|
<p>Noch keine aktiven Redaktionen registriert.</p>
|
|
) : (
|
|
<ul>
|
|
{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>
|
|
))}
|
|
</ul>
|
|
)}
|
|
|
|
{archivedEditorials.length > 0 && (
|
|
<details className="mt-8">
|
|
<summary className="cursor-pointer text-sm font-semibold text-gray-500 uppercase tracking-widest">
|
|
Archivierte Redaktionen ({archivedEditorials.length})
|
|
</summary>
|
|
<ul className="mt-4 opacity-75">
|
|
{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>
|
|
))}
|
|
</ul>
|
|
</details>
|
|
)}
|
|
</section>
|
|
);
|
|
}
|
|
|
|
function formatCents(cents: number): string {
|
|
return new Intl.NumberFormat("de-DE", { style: "currency", currency: "EUR" }).format(cents / 100);
|
|
}
|