- ZIP download from the Merkzettel: every photo is a new usage by default; only already downloaded photos offer "Neu / Bereits genutzt" (SegmentedControl), with thumbnails and a cost summary. "Bild auslassen" is gone. - Toasts (Sakani Toaster) for admin saves, deletes and errors; billing errors are readable and use router.refresh instead of reloads. Errors inside modal dialogs stay inline (a toast would sit behind the backdrop). - Album overview in blog-listing style, Sakani Pagination for albums, search and usage history, skeleton loading states. - Registration stepper; verification mail lands on step 3. - Editorials as a searchable, filterable table; audit log with event picker, German labels and collapsible details. - Release notes 2.4.0 seeded (migration 0009). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
164 lines
5.9 KiB
TypeScript
164 lines
5.9 KiB
TypeScript
"use client";
|
|
|
|
/* eslint-disable @next/next/no-img-element */
|
|
|
|
import { useState, useTransition } from "react";
|
|
import { Badge, Button, EmptyState, Input } from "@sakaniui/react";
|
|
import { IconMail, IconSearch } from "@sakaniui/react/icons";
|
|
|
|
import { Card } from "@/components/ui/sakani";
|
|
|
|
import type { AlbumActionResult } from "./actions";
|
|
import { notifyResult } from "@/components/ui/feedback";
|
|
|
|
type AlbumGridAction = (
|
|
editorialId: string,
|
|
_prevState: AlbumActionResult,
|
|
formData: FormData,
|
|
) => Promise<AlbumActionResult>;
|
|
|
|
type AlbumGridProps = {
|
|
albums: Array<{
|
|
id: string;
|
|
albumName: string;
|
|
albumThumbnailAssetId: string | null;
|
|
assetCount: number;
|
|
isGranted: boolean;
|
|
}>;
|
|
editorialId: string;
|
|
grantAction: AlbumGridAction;
|
|
revokeAction: AlbumGridAction;
|
|
notifyAction: AlbumGridAction;
|
|
};
|
|
|
|
type AlbumCardProps = {
|
|
album: AlbumGridProps["albums"][number];
|
|
editorialId: string;
|
|
grantAction: AlbumGridAction;
|
|
revokeAction: AlbumGridAction;
|
|
notifyAction: AlbumGridAction;
|
|
};
|
|
|
|
function AlbumCard({ album, editorialId, grantAction, revokeAction, notifyAction }: AlbumCardProps) {
|
|
const [isPending, startTransition] = useTransition();
|
|
const [notifyStatus, setNotifyStatus] = useState<"idle" | "pending" | "success" | "error">("idle");
|
|
|
|
const handleAction = (formData: FormData) => {
|
|
startTransition(async () => {
|
|
const initial: AlbumActionResult = { ok: true, message: "" };
|
|
if (album.isGranted) {
|
|
notifyResult(await revokeAction(editorialId, initial, formData), "Zuweisung aufgehoben.");
|
|
} else {
|
|
notifyResult(await grantAction(editorialId, initial, formData), "Album zugewiesen.");
|
|
}
|
|
});
|
|
};
|
|
|
|
const notifyLabel =
|
|
notifyStatus === "pending" ? "Wird gesendet …" :
|
|
notifyStatus === "success" ? "E-Mail gesendet!" :
|
|
notifyStatus === "error" ? "Fehler beim Senden" :
|
|
"Redaktion benachrichtigen";
|
|
|
|
return (
|
|
<li data-granted={album.isGranted}>
|
|
<Card className={`h-full ${album.isGranted ? "outline-2 outline-[var(--color-success-solid)]" : ""}`}>
|
|
<div className="relative aspect-[3/2] overflow-hidden rounded-[var(--radius-lg)] bg-[var(--color-bg-subtle)]">
|
|
{album.albumThumbnailAssetId ? (
|
|
<img
|
|
className="h-full w-full object-contain"
|
|
alt={`Titelbild von ${album.albumName}`}
|
|
loading="lazy"
|
|
src={`/api/assets/${encodeURIComponent(album.albumThumbnailAssetId)}/thumbnail?albumId=${encodeURIComponent(album.id)}`}
|
|
/>
|
|
) : (
|
|
<div aria-label="Kein Albumcover verfügbar" className="grid h-full w-full place-items-center text-xs text-[var(--color-fg-muted)]" role="img">
|
|
Kein Cover
|
|
</div>
|
|
)}
|
|
{album.isGranted && (
|
|
<Badge className="absolute top-2 right-2" emphasis="solid" variant="success">Zugewiesen</Badge>
|
|
)}
|
|
</div>
|
|
<div className="flex flex-col gap-1">
|
|
<h2 className="truncate text-base font-semibold" id={`album-${album.id}`} title={album.albumName}>
|
|
{album.albumName}
|
|
</h2>
|
|
<p className="text-sm text-[var(--color-fg-muted)]">{album.assetCount} Fotos</p>
|
|
</div>
|
|
<div className="mt-auto flex flex-col gap-2">
|
|
<form action={handleAction} className="flex flex-col">
|
|
<input name="immichAlbumId" type="hidden" value={album.id} />
|
|
<Button disabled={isPending} type="submit" variant={album.isGranted ? "outline" : "primary"}>
|
|
{isPending ? "Wird verarbeitet …" : album.isGranted ? "Zuweisung aufheben" : "Album zuweisen"}
|
|
</Button>
|
|
</form>
|
|
{album.isGranted && (
|
|
<form
|
|
className="flex flex-col"
|
|
action={(formData) => {
|
|
setNotifyStatus("pending");
|
|
notifyAction(editorialId, { ok: true, message: "" }, formData).then((res) => {
|
|
setNotifyStatus(res.ok ? "success" : "error");
|
|
notifyResult(res, "E-Mail an die Redaktion gesendet.");
|
|
setTimeout(() => setNotifyStatus("idle"), 3000);
|
|
});
|
|
}}
|
|
>
|
|
<input name="albumName" type="hidden" value={album.albumName} />
|
|
<Button
|
|
disabled={notifyStatus === "pending" || notifyStatus === "success"}
|
|
leftIcon={<IconMail size={16} />}
|
|
type="submit"
|
|
variant={notifyStatus === "error" ? "destructive" : "ghost"}
|
|
>
|
|
{notifyLabel}
|
|
</Button>
|
|
</form>
|
|
)}
|
|
</div>
|
|
</Card>
|
|
</li>
|
|
);
|
|
}
|
|
|
|
export function AlbumGrid({ albums, editorialId, grantAction, revokeAction, notifyAction }: AlbumGridProps) {
|
|
const [search, setSearch] = useState("");
|
|
|
|
const filteredAlbums = albums.filter((album) =>
|
|
album.albumName.toLowerCase().includes(search.toLowerCase()),
|
|
);
|
|
|
|
return (
|
|
<div className="flex flex-col gap-6">
|
|
<div className="max-w-md">
|
|
<Input
|
|
aria-label="Alben durchsuchen"
|
|
leadingIcon={<IconSearch size={16} />}
|
|
onChange={(e) => setSearch(e.target.value)}
|
|
placeholder="Alben suchen …"
|
|
type="search"
|
|
value={search}
|
|
/>
|
|
</div>
|
|
|
|
{filteredAlbums.length === 0 ? (
|
|
<EmptyState type="no-results" title="Keine Alben gefunden." description="Versuchen Sie einen anderen Suchbegriff." />
|
|
) : (
|
|
<ul className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3 2xl:grid-cols-4" aria-label="Zuweisbare Immich-Alben">
|
|
{filteredAlbums.map((album) => (
|
|
<AlbumCard
|
|
key={album.id}
|
|
album={album}
|
|
editorialId={editorialId}
|
|
grantAction={grantAction}
|
|
revokeAction={revokeAction}
|
|
notifyAction={notifyAction}
|
|
/>
|
|
))}
|
|
</ul>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|