feat: add editorial approval and account guards
This commit is contained in:
1 parent
a8d4e54ffb
commit
3584b4a7a7
9 files changed
+878
-1
No files matched your search
@@ -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>
|
||||
);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
import { eq } from "drizzle-orm";
|
||||
import { headers } from "next/headers";
|
||||
|
||||
import { db } from "@/db/client";
|
||||
import { billingAddressVersions, editorialAccounts } from "@/db/schema";
|
||||
import { requireActiveEditorial } from "@/modules/auth/principal";
|
||||
|
||||
export default async function EditorialProfilePage() {
|
||||
const principal = await requireActiveEditorial(new Headers(await headers()));
|
||||
const [editorial] = await db
|
||||
.select({
|
||||
name: editorialAccounts.name,
|
||||
contactName: editorialAccounts.contactName,
|
||||
loginEmail: editorialAccounts.loginEmail,
|
||||
addressLine1: billingAddressVersions.addressLine1,
|
||||
addressLine2: billingAddressVersions.addressLine2,
|
||||
postalCode: billingAddressVersions.postalCode,
|
||||
city: billingAddressVersions.city,
|
||||
countryCode: billingAddressVersions.countryCode,
|
||||
})
|
||||
.from(editorialAccounts)
|
||||
.leftJoin(
|
||||
billingAddressVersions,
|
||||
eq(editorialAccounts.currentBillingAddressVersionId, billingAddressVersions.id),
|
||||
)
|
||||
.where(eq(editorialAccounts.id, principal.editorialId))
|
||||
.limit(1);
|
||||
|
||||
return (
|
||||
<main className="portal-shell">
|
||||
<section className="content-section" aria-labelledby="profile-title">
|
||||
<p className="eyebrow">Redaktionskonto</p>
|
||||
<h1 id="profile-title">Profil</h1>
|
||||
<dl>
|
||||
<dt>Redaktion</dt>
|
||||
<dd>{editorial?.name}</dd>
|
||||
<dt>Ansprechperson</dt>
|
||||
<dd>{editorial?.contactName}</dd>
|
||||
<dt>Anmelde-E-Mail</dt>
|
||||
<dd>{editorial?.loginEmail}</dd>
|
||||
<dt>Rechnungsadresse</dt>
|
||||
<dd>
|
||||
{editorial?.addressLine1 ? (
|
||||
<address>
|
||||
{editorial.addressLine1}
|
||||
{editorial.addressLine2 ? <br /> : null}
|
||||
{editorial.addressLine2}
|
||||
<br />
|
||||
{editorial.postalCode} {editorial.city}
|
||||
<br />
|
||||
{editorial.countryCode}
|
||||
</address>
|
||||
) : (
|
||||
"Keine Rechnungsadresse hinterlegt."
|
||||
)}
|
||||
</dd>
|
||||
</dl>
|
||||
</section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user