fix: album assignment + approval error handling

Album assignment 500'd with IMMICH_UNAVAILABLE because grantAlbum verified the
album via getAlbum, which pulled the full album incl. all assets — large albums
blew the 15s timeout. Request ?withoutAssets=true so Immich returns metadata
only (no consumer reads .assets); make assets optional in the schema.

Album thumbnails 500'd because next/image rejected the ?albumId= query string
(images.localPatterns). Switch the album page to a plain <img>, matching the
editorial catalog (next/image was used in exactly one place).

Overhaul action error handling: grantAlbumAction/revokeAlbumAction/approveEditorialAction
returned a thrown Error, which Next.js turns into an opaque error-digest page —
the German message never reached the admin. They now return {ok,message}; new
client AlbumGrantForm + ApproveForm use useActionState to show the message
inline. Auth (requireAdmin) still throws (guarded by the layout). Update both
action test files to the result contract.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Leon TonhäuserandClaude committed 2026-08-11 02:09:16 +02:00
1 parent 7aeceee078
commit 089f5f7035
9 files changed
+233 -60

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
"use client";
import { useActionState } from "react";
import type { AlbumActionResult } from "@/app/admin/redaktionen/[id]/alben/actions";
// Client wrapper so the grant/revoke result (a returned object, not a thrown
// error) surfaces as inline German text via useActionState. The page picks the
// bound server action (grant or revoke) based on `isGranted`.
export function AlbumGrantForm({
action,
isGranted,
albumId,
}: Readonly<{
action: (state: AlbumActionResult, formData: FormData) => Promise<AlbumActionResult>;
isGranted: boolean;
albumId: string;
}>) {
const [state, formAction, pending] = useActionState(action, { ok: true, message: "" });
return (
<form action={formAction}>
<input name="immichAlbumId" type="hidden" value={albumId} />
<button type="submit" disabled={pending}>
{pending ? "…" : isGranted ? "Zuweisung aufheben" : "Album zuweisen"}
</button>
{state.ok ? null : <p role="alert">{state.message}</p>}
</form>
);
}
+38
View File
@@ -0,0 +1,38 @@
"use client";
import { useActionState } from "react";
import type { ApproveActionResult } from "@/app/admin/redaktionen/[id]/actions";
// Client wrapper so the approve result (a returned object, not a thrown
// error) surfaces as inline German text via useActionState. `canApprove`
// mirrors the server-side gate (email verified + active album grant).
export function ApproveForm({
action,
canApprove,
}: Readonly<{
action: (state: ApproveActionResult, formData: FormData) => Promise<ApproveActionResult>;
canApprove: boolean;
}>) {
const [state, formAction, pending] = useActionState(action, { ok: true, message: "" });
return (
<form action={formAction} className="account-form">
<label>
Individueller Nettopreis (EUR)
<input
inputMode="decimal"
min="0.01"
name="priceEuros"
required
step="0.01"
type="number"
/>
</label>
<button type="submit" disabled={!canApprove || pending}>
{pending ? "…" : "Redaktion freigeben"}
</button>
{state.ok ? null : <p role="alert">{state.message}</p>}
</form>
);
}