feat: add cross-album search, auto-rules, album UI redesign, editorial archiving and pdf download

This commit is contained in:
Leon Tonhäuser committed 2026-08-11 02:53:15 +02:00
1 parent 9c0d43b1ec
commit 375e5b8b7d
23 files changed
+1153 -43

No files matched your search

@@ -333,7 +333,16 @@ export function BillingSelection({
</span>
</div>
{report.status === "final" && (
<CancelReportForm reportId={report.id} reportNumber={report.reportNumber} />
<>
<CancelReportForm reportId={report.id} reportNumber={report.reportNumber} />
<a
href={`/api/billing-reports/${encodeURIComponent(report.id)}`}
className="billing-report-download"
download
>
PDF herunterladen
</a>
</>
)}
</li>
))}
+40
View File
@@ -0,0 +1,40 @@
"use server";
import { revalidatePath } from "next/cache";
import { headers } from "next/headers";
import { redirect } from "next/navigation";
import { requireAdmin } from "@/modules/auth/principal";
import { editorialService } from "@/modules/editorials/service";
export async function archiveEditorialAction(editorialId: string): Promise<void> {
const admin = await requireAdmin(new Headers(await headers()));
await editorialService.archiveEditorial({
editorialId,
adminUserId: admin.userId,
});
revalidatePath(`/admin/redaktionen/${editorialId}`);
revalidatePath('/admin/redaktionen');
redirect('/admin/redaktionen');
}
export async function suspendEditorialAction(editorialId: string): Promise<void> {
const admin = await requireAdmin(new Headers(await headers()));
await editorialService.transitionEditorialStatus({
editorialId,
from: 'active',
to: 'suspended',
adminUserId: admin.userId,
});
revalidatePath(`/admin/redaktionen/${editorialId}`);
}
export async function reactivateEditorialAction(editorialId: string): Promise<void> {
const admin = await requireAdmin(new Headers(await headers()));
await editorialService.transitionEditorialStatus({
editorialId,
from: 'suspended',
to: 'active',
adminUserId: admin.userId,
});
revalidatePath(`/admin/redaktionen/${editorialId}`);
}
@@ -0,0 +1,117 @@
"use client";
import { useState, useTransition } from "react";
import Image from "next/image";
type AlbumGridProps = {
albums: Array<{
id: string;
albumName: string;
albumThumbnailAssetId: string | null;
assetCount: number;
isGranted: boolean;
}>;
editorialId: string;
grantAction: (editorialId: string, formData: FormData) => Promise<void>;
revokeAction: (editorialId: string, formData: FormData) => Promise<void>;
};
function AlbumCard({
album,
editorialId,
grantAction,
revokeAction,
}: {
album: AlbumGridProps["albums"][0];
editorialId: string;
grantAction: AlbumGridProps["grantAction"];
revokeAction: AlbumGridProps["revokeAction"];
}) {
const [isPending, startTransition] = useTransition();
const handleAction = (formData: FormData) => {
startTransition(async () => {
if (album.isGranted) {
await revokeAction(editorialId, formData);
} else {
await grantAction(editorialId, formData);
}
});
};
return (
<li className="album-card" data-granted={album.isGranted}>
<div className="album-card-image-container">
{album.albumThumbnailAssetId ? (
<Image
className="album-card-image"
alt={`Titelbild von ${album.albumName}`}
height={120}
src={`/api/assets/${encodeURIComponent(album.albumThumbnailAssetId)}/thumbnail?albumId=${encodeURIComponent(album.id)}`}
width={160}
/>
) : (
<div aria-label="Kein Albumcover verfügbar" className="album-card-placeholder" role="img">
Kein Cover
</div>
)}
</div>
<div className="album-card-body">
<h2 className="album-card-name" id={`album-${album.id}`} title={album.albumName}>
{album.albumName}
</h2>
<p className="album-card-count">{album.assetCount} Fotos</p>
<p className={`album-card-status ${album.isGranted ? "album-card-status--granted" : ""}`}>
{album.isGranted ? "Zugewiesen" : "Nicht zugewiesen"}
</p>
<form action={handleAction}>
<input name="immichAlbumId" type="hidden" value={album.id} />
<button
type="submit"
className={`album-card-action ${album.isGranted ? "album-card-action--revoke" : "album-card-action--grant"}`}
disabled={isPending}
>
{isPending ? "Lädt..." : album.isGranted ? "Zuweisung aufheben" : "Album zuweisen"}
</button>
</form>
</div>
</li>
);
}
export function AlbumGrid({ albums, editorialId, grantAction, revokeAction }: AlbumGridProps) {
const [search, setSearch] = useState("");
const filteredAlbums = albums.filter((album) =>
album.albumName.toLowerCase().includes(search.toLowerCase())
);
return (
<div>
<input
type="search"
className="album-grid-search"
placeholder="Alben suchen..."
value={search}
onChange={(e) => setSearch(e.target.value)}
aria-label="Alben durchsuchen"
/>
{filteredAlbums.length === 0 ? (
<p>Keine Alben gefunden.</p>
) : (
<ul className="album-grid" aria-label="Zuweisbare Immich-Alben">
{filteredAlbums.map((album) => (
<AlbumCard
key={album.id}
album={album}
editorialId={editorialId}
grantAction={grantAction}
revokeAction={revokeAction}
/>
))}
</ul>
)}
</div>
);
}
@@ -14,7 +14,7 @@ const editorial = {
loginEmail: "mara@example.com",
status: "pending_approval" as const,
emailVerifiedAt: null,
currentPriceCents: null,
currentPriceCents: null, archivedAt: null,
};
test("the editorial detail links admins to its album-assignment page", () => {
+9 -34
View File
@@ -9,6 +9,7 @@ import { albumGrantService } from "@/modules/albums/grants";
import { grantAlbumAction, revokeAlbumAction } from "./actions";
import { loadAssignableAlbums } from "./page-content";
import { AlbumGrid } from "./AlbumGrid";
export default async function EditorialAlbumsPage({
params,
@@ -50,45 +51,19 @@ export default async function EditorialAlbumsPage({
</p>
<p>
<Link href={`/admin/redaktionen/${editorial.id}`}>Zurück zur Redaktion</Link>
{" · "}
<Link href={`/admin/redaktionen/${editorial.id}/auto-regeln`}>Auto-Zuweisungsregeln verwalten</Link>
</p>
{albumResult.albums.length === 0 ? (
<p>Derzeit sind keine zuweisbaren Alben vorhanden.</p>
) : (
<ul aria-label="Zuweisbare Immich-Alben">
{albumResult.albums.map((album) => {
const action = album.isGranted ? revokeAlbumAction : grantAlbumAction;
return (
<li key={album.id}>
<article aria-labelledby={`album-${album.id}`}>
{album.albumThumbnailAssetId ? (
<Image
alt={`Titelbild von ${album.albumName}`}
height={120}
src={`/api/assets/${encodeURIComponent(album.albumThumbnailAssetId)}/thumbnail?albumId=${encodeURIComponent(album.id)}`}
width={160}
/>
) : (
<div aria-label="Kein Albumcover verfügbar" role="img">
Kein Cover
</div>
)}
<h2 id={`album-${album.id}`}>{album.albumName}</h2>
<p>{album.assetCount} Fotos</p>
<p>
Status: <strong>{album.isGranted ? "Zugewiesen" : "Nicht zugewiesen"}</strong>
</p>
<form action={action.bind(null, editorial.id)}>
<input name="immichAlbumId" type="hidden" value={album.id} />
<button type="submit">
{album.isGranted ? "Zuweisung aufheben" : "Album zuweisen"}
</button>
</form>
</article>
</li>
);
})}
</ul>
<AlbumGrid
albums={albumResult.albums}
editorialId={editorial.id}
grantAction={grantAlbumAction}
revokeAction={revokeAlbumAction}
/>
)}
</section>
);
@@ -0,0 +1,61 @@
"use server";
import { revalidatePath } from "next/cache";
import { headers } from "next/headers";
import { autoRuleService } from "@/modules/albums/auto-rules";
import { requireAdmin } from "@/modules/auth/principal";
async function getAdminPrincipal() {
return requireAdmin(new Headers(await headers()));
}
function requiredId(value: unknown): string {
if (
typeof value !== "string" ||
!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(value)
) {
throw new Error("INVALID_ID");
}
return value;
}
export async function createAutoRuleAction(editorialId: string, formData: FormData): Promise<void> {
const principal = await getAdminPrincipal();
const safeEditorialId = requiredId(editorialId);
const keyword = formData.get("keyword");
if (typeof keyword !== "string" || !keyword.trim()) {
throw new Error("INVALID_KEYWORD");
}
await autoRuleService.createRule({
editorialId: safeEditorialId,
keyword: keyword.trim(),
adminUserId: principal.userId,
});
revalidatePath(`/admin/redaktionen/${safeEditorialId}/auto-regeln`);
}
export async function deleteAutoRuleAction(editorialId: string, ruleId: string): Promise<void> {
const principal = await getAdminPrincipal();
const safeEditorialId = requiredId(editorialId);
const safeRuleId = requiredId(ruleId);
await autoRuleService.deleteRule({
ruleId: safeRuleId,
adminUserId: principal.userId,
});
revalidatePath(`/admin/redaktionen/${safeEditorialId}/auto-regeln`);
}
export async function applyAutoRulesAction(editorialId: string): Promise<void> {
const principal = await getAdminPrincipal();
const safeEditorialId = requiredId(editorialId);
await autoRuleService.applyRules(safeEditorialId, principal.userId);
revalidatePath(`/admin/redaktionen/${safeEditorialId}/auto-regeln`);
}
@@ -0,0 +1,72 @@
import Link from "next/link";
import { notFound } from "next/navigation";
import { headers } from "next/headers";
import { requireAdmin } from "@/modules/auth/principal";
import { autoRuleService } from "@/modules/albums/auto-rules";
import { db } from "@/db/client";
import { editorialAccounts } from "@/db/schema";
import { eq } from "drizzle-orm";
import { applyAutoRulesAction, createAutoRuleAction, deleteAutoRuleAction } from "./actions";
type AutoRulesPageProps = Readonly<{
params: Promise<{ id: string }>;
}>;
export default async function AutoRulesPage({ params }: AutoRulesPageProps) {
await requireAdmin(new Headers(await headers()));
const { id } = await params;
const [editorial] = await db
.select()
.from(editorialAccounts)
.where(eq(editorialAccounts.id, id));
if (!editorial) {
notFound();
}
const rules = await autoRuleService.listRules(id);
return (
<section className="content-section" aria-labelledby="auto-rules-title">
<p className="eyebrow">Redaktion · Auto-Zuweisungsregeln</p>
<h1 id="auto-rules-title">Auto-Regeln für {editorial.name}</h1>
<p>
Alben, deren Name eines der folgenden Schlüsselwörter enthält, werden automatisch zugewiesen.
</p>
<p>
<Link href={`/admin/redaktionen/${editorial.id}/alben`}>Zurück zu Albumrechte</Link>
</p>
<form action={createAutoRuleAction.bind(null, editorial.id)}>
<label>
<span>Neues Schlüsselwort</span>
<input name="keyword" type="text" required placeholder="z.B. FC Bayern" />
</label>
<button type="submit">Regel hinzufügen</button>
</form>
<form action={applyAutoRulesAction.bind(null, editorial.id)}>
<button type="submit">Regeln jetzt anwenden</button>
</form>
{rules.length === 0 ? (
<p>Noch keine Auto-Regeln angelegt.</p>
) : (
<ul className="auto-rules-list">
{rules.map((rule) => (
<li key={rule.id} className="auto-rule-item">
<span className="auto-rule-keyword">{rule.keyword}</span>
<span className="auto-rule-date">
{rule.createdAt.toLocaleDateString('de-DE')}
</span>
<form action={deleteAutoRuleAction.bind(null, editorial.id, rule.id)}>
<button type="submit" className="auto-rule-delete">Entfernen</button>
</form>
</li>
))}
</ul>
)}
</section>
);
}
+1
View File
@@ -18,6 +18,7 @@ export default async function EditorialDetailPage({
status: editorialAccounts.status,
emailVerifiedAt: editorialAccounts.emailVerifiedAt,
currentPriceCents: editorialAccounts.currentPriceCents,
archivedAt: editorialAccounts.archivedAt,
})
.from(editorialAccounts)
.where(eq(editorialAccounts.id, id))
+28 -3
View File
@@ -13,19 +13,23 @@ export default async function EditorialsPage() {
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">
<p className="eyebrow">Kontoverwaltung</p>
<h1 id="editorials-title">Redaktionen</h1>
{editorials.length === 0 ? (
<p>Noch keine Redaktionen registriert.</p>
{activeEditorials.length === 0 ? (
<p>Noch keine aktiven Redaktionen registriert.</p>
) : (
<ul>
{editorials.map((editorial) => (
{activeEditorials.map((editorial) => (
<li key={editorial.id}>
<a href={`/admin/redaktionen/${editorial.id}`}>{editorial.name}</a>
<p>
@@ -38,6 +42,27 @@ export default async function EditorialsPage() {
))}
</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>
);
}