From cba70310f91768a1c1fd10de819961d4bce803de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20Tonh=C3=A4user?= Date: Tue, 1 Dec 2026 00:09:37 +0100 Subject: [PATCH] Release 2.4.0: bulk download rework, toasts and Sakani polish - 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 --- AGENTS.md | 3 +- AI_MEMORY.md | 9 + drizzle/0009_release_notes_2_4_0.sql | 6 + drizzle/meta/0009_snapshot.json | 2585 +++++++++++++++++ drizzle/meta/_journal.json | 7 + .../(public)/registrieren/bestaetigt/page.tsx | 20 +- src/app/(public)/registrieren/page.tsx | 2 + .../[editorialId]/BillingSelection.test.tsx | 4 +- .../[editorialId]/BillingSelection.tsx | 120 +- src/app/admin/alben/AlbumAccessManager.tsx | 16 +- src/app/admin/audit/page.tsx | 104 +- src/app/admin/hinweise/AnnouncementForm.tsx | 11 +- .../hinweise/DeleteAnnouncementButton.tsx | 7 +- src/app/admin/kalender/CalendarEventForm.tsx | 11 +- .../kalender/DeleteCalendarEventButton.tsx | 11 +- .../kalender/kategorien/CategoryForm.tsx | 11 +- .../kategorien/DeleteCategoryButton.tsx | 11 +- src/app/admin/redaktionen/EditorialsTable.tsx | 145 + .../redaktionen/[id]/alben/AlbumGrid.tsx | 6 +- .../redaktionen/[id]/alben/page.test.tsx | 2 + .../redaktionen/[id]/auto-regeln/page.tsx | 13 +- src/app/admin/redaktionen/page.tsx | 104 +- .../versionen/DeleteReleaseNoteButton.tsx | 7 +- src/app/admin/versionen/ReleaseNoteForm.tsx | 11 +- src/app/globals.css | 9 + src/app/layout.tsx | 2 + src/app/redaktion/alben/[albumId]/loading.tsx | 16 +- src/app/redaktion/alben/loading.tsx | 22 +- src/app/redaktion/alben/page.tsx | 17 +- .../redaktion/kalender/EventAccessAction.tsx | 26 +- .../DownloadLightboxForm.test.tsx | 62 +- .../leuchtkasten/DownloadLightboxForm.tsx | 243 +- src/app/redaktion/nutzungen/page.test.tsx | 8 +- .../nutzungen/usage-history-content.tsx | 10 +- src/components/download/usage-dialog.tsx | 5 +- src/components/layout/registration-steps.tsx | 23 + src/components/layout/release-notes.tsx | 23 +- src/components/ui/feedback.tsx | 72 + src/components/ui/sakani.tsx | 2 +- src/components/ui/url-pagination.tsx | 36 + src/modules/albums/catalog-content.test.tsx | 6 +- src/modules/albums/catalog-content.tsx | 71 +- src/modules/albums/photo-gallery.tsx | 5 +- src/modules/auth/auth.ts | 2 +- src/modules/editorials/ApproveForm.tsx | 5 +- src/modules/editorials/DangerZone.tsx | 9 +- src/modules/editorials/ResetUsageCard.tsx | 7 +- src/modules/editorials/admin-detail.tsx | 21 +- 48 files changed, 3474 insertions(+), 454 deletions(-) create mode 100644 drizzle/0009_release_notes_2_4_0.sql create mode 100644 drizzle/meta/0009_snapshot.json create mode 100644 src/app/admin/redaktionen/EditorialsTable.tsx create mode 100644 src/components/layout/registration-steps.tsx create mode 100644 src/components/ui/feedback.tsx create mode 100644 src/components/ui/url-pagination.tsx diff --git a/AGENTS.md b/AGENTS.md index f9652b8..0f68977 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -26,7 +26,8 @@ Aktueller Stand: siehe neueste Einträge in `release_notes` (Basis `2.0.0`, Kalender/Selbstbedienung/Sortierung/Beschreibung: `2.1.0`, Dateiname-Suche: `2.1.1`, Statistik/Collab/Rechnungsversand: `2.2.0`, Quartalsabrechnung + Sakani-Formulare: `2.2.1`, Versionshistorie: `2.2.2`, -Kategorien/Vormerken/Monatskalender/Dashboard: `2.3.0`). +Kategorien/Vormerken/Monatskalender/Dashboard: `2.3.0`, +Mehrfach-Download/Toasts/Sakani-Feinschliff: `2.4.0`). ## Sicherheit (bei jeder Änderung mitprüfen) diff --git a/AI_MEMORY.md b/AI_MEMORY.md index feddc3d..3718cb6 100644 --- a/AI_MEMORY.md +++ b/AI_MEMORY.md @@ -92,3 +92,12 @@ Redaktionen können Bilder durchsuchen, einen Leuchtkasten verwenden, Bilder her - **Dashboard (`/admin`):** `src/modules/dashboard/tasks.ts` (rein, getestet) + `queries.ts` (Aufgaben-Zähler), Rest aus `statsQueries.loadOverview(30)` und `calendarService.listAdminEvents()`. - **drizzle-kit generate ohne TTY:** Fragt bei "neue Tabelle + gelöschte Tabelle" interaktiv nach Umbenennung und bricht ohne Terminal ab. Lösung: in zwei Schritten generieren (erst hinzufügen, dann löschen), so entstanden 0006 und 0007. +## 12. Mehrfach-Download, Toasts, Sakani-Feinschliff (Stand 2026-11, v2.4) +- **Toasts:** Ein `` (Sakani `Toaster`, unten rechts) im Root-Layout. Helfer in `src/components/ui/feedback.tsx`: `notifyResult(result, fallback)` für Actions mit `{ ok, message }`, `useResultToast(state)` für `useActionState`, `ToastForm` für Server-Actions ohne Rückgabe (Speichern + `router.refresh()`). Bei Seiten, die vorher `window.location.reload()` nutzten (Abrechnungen), jetzt `router.refresh()`, sonst wäre der Toast weg. +- **Toasts nicht in modalen Dialogen:** Native `.showModal()` liegt im Top-Layer; ein Toast landet dahinter. Fehler in Nutzungsdialog und ZIP-Dialog bleiben deshalb als `Alert` im Dialog; Erfolg kommt als Toast nach dem Schließen. +- **Mehrfach-Download (`DownloadLightboxForm`):** Standard ist für jedes Bild "Neue Nutzung" (gemeinsamer Zweck, optional eigener je Bild). Nur Bilder mit früheren Nutzungen bekommen einen `SegmentedControl` "Neue Nutzung / Bereits genutzt" (Voreinstellung neue Nutzung, vom Nutzer so gewählt); bei mehreren früheren Nutzungen Auswahl per `Select`, sonst die eine. "Bild auslassen" gibt es nicht mehr (Bilder werden über den Merkzettel entfernt). API-Payload unverändert. +- **Pagination:** `UrlPagination` (`src/components/ui/url-pagination.tsx`, Sakani `Pagination`) für Album, Cross-Album-Suche und Nutzungshistorie. Die Quellen liefern nur "hat nächste Seite", daher `total = page + 1` solange es weitergeht. Cursor-basierte Auslieferungsliste bleibt bei `PageLinks`. +- **Albenübersicht:** Blog-Listing-Optik (randloses 3:2-Cover, Anzahl, Titel, Beschreibung); Cover ist dekorativ (`alt=""`), der Titel im Link benennt es. Skeletons hinter Covern/Fotokacheln und in `loading.tsx`. +- **Registrierung:** `RegistrationSteps` (Sakani `Stepper`, mobil vertikal). Die Bestätigungsmail führt auf `/registrieren/bestaetigt?schritt=freigabe` (Schritt 3), das Formular auf die Seite ohne Parameter (Schritt 2). +- **Redaktionen:** `EditorialsTable` (Client, Sakani `Table` + Suche + Statusfilter; "Alle" ohne Archivierte). **Audit:** Ereignis als Auswahl der vorhandenen Typen (`selectDistinct`), deutsche Bezeichnungen (`EVENT_LABELS` in `src/app/admin/audit/page.tsx`, neue Audit-Typen dort ergänzen), Details aufklappbar. + diff --git a/drizzle/0009_release_notes_2_4_0.sql b/drizzle/0009_release_notes_2_4_0.sql new file mode 100644 index 0000000..2474e49 --- /dev/null +++ b/drizzle/0009_release_notes_2_4_0.sql @@ -0,0 +1,6 @@ +-- Custom SQL migration file, put your code below! -- +INSERT INTO "release_notes" ("version", "audience", "body", "created_by_user_id") +VALUES + ('2.4.0', 'admin', 'Neu in 2.4: Speichern und Ändern bestätigt das Portal mit einer kurzen Meldung, Fehler bei Abrechnungen sind verständlich formuliert. Redaktionen erscheinen als Tabelle mit Suche, Statusfilter und offenen Beträgen. Das Audit-Protokoll hat eine Ereignisauswahl, lesbare Bezeichnungen und aufklappbare Details. Die Registrierung zeigt den Ablauf in Schritten.', NULL), + ('2.4.0', 'editorial', 'Neu in 2.4: Beim ZIP-Download vom Merkzettel laufen alle Bilder als neue Nutzung; nur bei schon geladenen Bildern wählen Sie zwischen neuer Nutzung und kostenloser Wiederholung. Die Albenübersicht zeigt große Vorschaubilder, unter den Fotos gibt es Seitenzahlen, und Bestätigungen erscheinen als kurze Meldung unten rechts.', NULL) +ON CONFLICT ("version", "audience") DO NOTHING; diff --git a/drizzle/meta/0009_snapshot.json b/drizzle/meta/0009_snapshot.json new file mode 100644 index 0000000..461a8c5 --- /dev/null +++ b/drizzle/meta/0009_snapshot.json @@ -0,0 +1,2585 @@ +{ + "id": "4b7779b1-b137-41ec-9d2b-5359564b1085", + "prevId": "6ae44eac-9351-400d-91f2-f3f357c44c22", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.activity_events": { + "name": "activity_events", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "editorial_account_id": { + "name": "editorial_account_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "event_type": { + "name": "event_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "immich_album_id": { + "name": "immich_album_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "immich_asset_id": { + "name": "immich_asset_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "query": { + "name": "query", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "occurred_at": { + "name": "occurred_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "activity_events_occurred_at_idx": { + "name": "activity_events_occurred_at_idx", + "columns": [ + { + "expression": "occurred_at", + "isExpression": false, + "asc": false, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + }, + "activity_events_editorial_occurred_idx": { + "name": "activity_events_editorial_occurred_idx", + "columns": [ + { + "expression": "editorial_account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "occurred_at", + "isExpression": false, + "asc": false, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + }, + "activity_events_type_occurred_idx": { + "name": "activity_events_type_occurred_idx", + "columns": [ + { + "expression": "event_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "occurred_at", + "isExpression": false, + "asc": false, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "activity_events_editorial_account_id_editorial_accounts_id_fk": { + "name": "activity_events_editorial_account_id_editorial_accounts_id_fk", + "tableFrom": "activity_events", + "columnsFrom": [ + "editorial_account_id" + ], + "tableTo": "editorial_accounts", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "activity_events_event_type_check": { + "name": "activity_events_event_type_check", + "value": "\"activity_events\".\"event_type\" in ('album_view', 'search', 'lightbox_view')" + } + }, + "isRLSEnabled": false + }, + "public.album_grants": { + "name": "album_grants", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "editorial_account_id": { + "name": "editorial_account_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "immich_album_id": { + "name": "immich_album_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "granted_at": { + "name": "granted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "revoked_at": { + "name": "revoked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "granted_by_user_id": { + "name": "granted_by_user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'admin'" + } + }, + "indexes": { + "album_grants_editorial_account_id_idx": { + "name": "album_grants_editorial_account_id_idx", + "columns": [ + { + "expression": "editorial_account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + }, + "album_grants_immich_album_id_idx": { + "name": "album_grants_immich_album_id_idx", + "columns": [ + { + "expression": "immich_album_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + }, + "album_grants_editorial_active_album_unique": { + "name": "album_grants_editorial_active_album_unique", + "columns": [ + { + "expression": "editorial_account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "lower(\"immich_album_id\")", + "isExpression": true, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "with": {}, + "method": "btree", + "where": "\"album_grants\".\"revoked_at\" is null", + "concurrently": false + } + }, + "foreignKeys": { + "album_grants_editorial_account_id_editorial_accounts_id_fk": { + "name": "album_grants_editorial_account_id_editorial_accounts_id_fk", + "tableFrom": "album_grants", + "columnsFrom": [ + "editorial_account_id" + ], + "tableTo": "editorial_accounts", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + }, + "album_grants_granted_by_user_id_user_id_fk": { + "name": "album_grants_granted_by_user_id_user_id_fk", + "tableFrom": "album_grants", + "columnsFrom": [ + "granted_by_user_id" + ], + "tableTo": "user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "album_grants_immich_album_id_uuid_check": { + "name": "album_grants_immich_album_id_uuid_check", + "value": "\"album_grants\".\"immich_album_id\" ~* '^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$'" + }, + "album_grants_source_check": { + "name": "album_grants_source_check", + "value": "\"album_grants\".\"source\" in ('admin', 'auto_rule', 'self_service')" + } + }, + "isRLSEnabled": false + }, + "public.announcements": { + "name": "announcements", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "event_date": { + "name": "event_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "announcements_created_by_user_id_user_id_fk": { + "name": "announcements_created_by_user_id_user_id_fk", + "tableFrom": "announcements", + "columnsFrom": [ + "created_by_user_id" + ], + "tableTo": "user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.audit_events": { + "name": "audit_events", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "event_type": { + "name": "event_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "actor_user_id": { + "name": "actor_user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "actor_type": { + "name": "actor_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'system'" + }, + "entity_type": { + "name": "entity_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "entity_id": { + "name": "entity_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "previous_values": { + "name": "previous_values", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "new_values": { + "name": "new_values", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "occurred_at": { + "name": "occurred_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "request_id": { + "name": "request_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "audit_events_actor_user_id_user_id_fk": { + "name": "audit_events_actor_user_id_user_id_fk", + "tableFrom": "audit_events", + "columnsFrom": [ + "actor_user_id" + ], + "tableTo": "user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.account": { + "name": "account", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "account_id": { + "name": "account_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider_id": { + "name": "provider_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "access_token": { + "name": "access_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "refresh_token": { + "name": "refresh_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "id_token": { + "name": "id_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "access_token_expires_at": { + "name": "access_token_expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "refresh_token_expires_at": { + "name": "refresh_token_expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "scope": { + "name": "scope", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "account_user_id_user_id_fk": { + "name": "account_user_id_user_id_fk", + "tableFrom": "account", + "columnsFrom": [ + "user_id" + ], + "tableTo": "user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.session": { + "name": "session", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "ip_address": { + "name": "ip_address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_agent": { + "name": "user_agent", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "session_user_id_user_id_fk": { + "name": "session_user_id_user_id_fk", + "tableFrom": "session", + "columnsFrom": [ + "user_id" + ], + "tableTo": "user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "session_token_unique": { + "name": "session_token_unique", + "columns": [ + "token" + ], + "nullsNotDistinct": false + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.two_factor": { + "name": "two_factor", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "secret": { + "name": "secret", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "backup_codes": { + "name": "backup_codes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "verified": { + "name": "verified", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "failed_verification_count": { + "name": "failed_verification_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "locked_until": { + "name": "locked_until", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "two_factor_user_id_user_id_fk": { + "name": "two_factor_user_id_user_id_fk", + "tableFrom": "two_factor", + "columnsFrom": [ + "user_id" + ], + "tableTo": "user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "two_factor_user_id_unique": { + "name": "two_factor_user_id_unique", + "columns": [ + "user_id" + ], + "nullsNotDistinct": false + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.user": { + "name": "user", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email_verified": { + "name": "email_verified", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "image": { + "name": "image", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "role": { + "name": "role", + "type": "portal_role", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'EDITORIAL'" + }, + "two_factor_enabled": { + "name": "two_factor_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "user_email_unique": { + "name": "user_email_unique", + "columns": [ + "email" + ], + "nullsNotDistinct": false + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.verification": { + "name": "verification", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "identifier": { + "name": "identifier", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.album_auto_rules": { + "name": "album_auto_rules", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "editorial_account_id": { + "name": "editorial_account_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "keyword": { + "name": "keyword", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "album_auto_rules_editorial_account_id_keyword_idx": { + "name": "album_auto_rules_editorial_account_id_keyword_idx", + "columns": [ + { + "expression": "editorial_account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "lower(\"keyword\")", + "isExpression": true, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "album_auto_rules_editorial_account_id_editorial_accounts_id_fk": { + "name": "album_auto_rules_editorial_account_id_editorial_accounts_id_fk", + "tableFrom": "album_auto_rules", + "columnsFrom": [ + "editorial_account_id" + ], + "tableTo": "editorial_accounts", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + }, + "album_auto_rules_created_by_user_id_user_id_fk": { + "name": "album_auto_rules_created_by_user_id_user_id_fk", + "tableFrom": "album_auto_rules", + "columnsFrom": [ + "created_by_user_id" + ], + "tableTo": "user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.billing_report_items": { + "name": "billing_report_items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "billing_report_id": { + "name": "billing_report_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "usage_id": { + "name": "usage_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "immich_asset_id_snapshot": { + "name": "immich_asset_id_snapshot", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "filename_snapshot": { + "name": "filename_snapshot", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "album_name_snapshot": { + "name": "album_name_snapshot", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "purpose_snapshot": { + "name": "purpose_snapshot", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "internal_reference_snapshot": { + "name": "internal_reference_snapshot", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "price_cents": { + "name": "price_cents", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "collab": { + "name": "collab", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "billing_report_items_report_usage_unique": { + "name": "billing_report_items_report_usage_unique", + "columns": [ + { + "expression": "billing_report_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "usage_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "billing_report_items_billing_report_id_billing_reports_id_fk": { + "name": "billing_report_items_billing_report_id_billing_reports_id_fk", + "tableFrom": "billing_report_items", + "columnsFrom": [ + "billing_report_id" + ], + "tableTo": "billing_reports", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + }, + "billing_report_items_usage_id_usages_id_fk": { + "name": "billing_report_items_usage_id_usages_id_fk", + "tableFrom": "billing_report_items", + "columnsFrom": [ + "usage_id" + ], + "tableTo": "usages", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.billing_reports": { + "name": "billing_reports", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "report_number": { + "name": "report_number", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "editorial_account_id": { + "name": "editorial_account_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "period_starts_at": { + "name": "period_starts_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "period_ends_at": { + "name": "period_ends_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "billing_address_snapshot": { + "name": "billing_address_snapshot", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "invoice_number": { + "name": "invoice_number", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "net_total_cents": { + "name": "net_total_cents", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "flatrate_cents_snapshot": { + "name": "flatrate_cents_snapshot", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "report_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'draft'" + }, + "pdf": { + "name": "pdf", + "type": "bytea", + "primaryKey": false, + "notNull": false + }, + "pdf_sha256": { + "name": "pdf_sha256", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "invoice_pdf": { + "name": "invoice_pdf", + "type": "bytea", + "primaryKey": false, + "notNull": false + }, + "invoice_pdf_sha256": { + "name": "invoice_pdf_sha256", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "invoice_pdf_filename": { + "name": "invoice_pdf_filename", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "invoice_uploaded_at": { + "name": "invoice_uploaded_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "invoice_email_status": { + "name": "invoice_email_status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'not_sent'" + }, + "invoice_email_sent_at": { + "name": "invoice_email_sent_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "invoice_email_error": { + "name": "invoice_email_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "finalized_at": { + "name": "finalized_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "cancelled_at": { + "name": "cancelled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "cancellation_reason": { + "name": "cancellation_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "cancelled_by_user_id": { + "name": "cancelled_by_user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "billing_reports_report_number_unique": { + "name": "billing_reports_report_number_unique", + "columns": [ + { + "expression": "report_number", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "with": {}, + "method": "btree", + "concurrently": false + }, + "billing_reports_invoice_number_unique": { + "name": "billing_reports_invoice_number_unique", + "columns": [ + { + "expression": "invoice_number", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "billing_reports_editorial_account_id_editorial_accounts_id_fk": { + "name": "billing_reports_editorial_account_id_editorial_accounts_id_fk", + "tableFrom": "billing_reports", + "columnsFrom": [ + "editorial_account_id" + ], + "tableTo": "editorial_accounts", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + }, + "billing_reports_created_by_user_id_user_id_fk": { + "name": "billing_reports_created_by_user_id_user_id_fk", + "tableFrom": "billing_reports", + "columnsFrom": [ + "created_by_user_id" + ], + "tableTo": "user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + }, + "billing_reports_cancelled_by_user_id_user_id_fk": { + "name": "billing_reports_cancelled_by_user_id_user_id_fk", + "tableFrom": "billing_reports", + "columnsFrom": [ + "cancelled_by_user_id" + ], + "tableTo": "user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "billing_reports_pdf_sha256_hex_check": { + "name": "billing_reports_pdf_sha256_hex_check", + "value": "\"billing_reports\".\"pdf_sha256\" ~ '^[0-9a-f]{64}$'" + }, + "billing_reports_invoice_pdf_sha256_hex_check": { + "name": "billing_reports_invoice_pdf_sha256_hex_check", + "value": "\"billing_reports\".\"invoice_pdf_sha256\" IS NULL OR \"billing_reports\".\"invoice_pdf_sha256\" ~ '^[0-9a-f]{64}$'" + }, + "billing_reports_invoice_email_status_check": { + "name": "billing_reports_invoice_email_status_check", + "value": "\"billing_reports\".\"invoice_email_status\" in ('not_sent', 'sent', 'failed')" + }, + "billing_reports_final_pdf_check": { + "name": "billing_reports_final_pdf_check", + "value": "\"billing_reports\".\"status\" <> 'final' OR (\"billing_reports\".\"pdf\" IS NOT NULL AND \"billing_reports\".\"pdf_sha256\" IS NOT NULL)" + } + }, + "isRLSEnabled": false + }, + "public.calendar_events": { + "name": "calendar_events", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "event_date": { + "name": "event_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "immich_album_id": { + "name": "immich_album_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "category_id": { + "name": "category_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "calendar_events_category_id_event_categories_id_fk": { + "name": "calendar_events_category_id_event_categories_id_fk", + "tableFrom": "calendar_events", + "columnsFrom": [ + "category_id" + ], + "tableTo": "event_categories", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + }, + "calendar_events_created_by_user_id_user_id_fk": { + "name": "calendar_events_created_by_user_id_user_id_fk", + "tableFrom": "calendar_events", + "columnsFrom": [ + "created_by_user_id" + ], + "tableTo": "user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.event_categories": { + "name": "event_categories", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "event_categories_name_lower_unique": { + "name": "event_categories_name_lower_unique", + "columns": [ + { + "expression": "lower(\"name\")", + "isExpression": true, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "event_categories_created_by_user_id_user_id_fk": { + "name": "event_categories_created_by_user_id_user_id_fk", + "tableFrom": "event_categories", + "columnsFrom": [ + "created_by_user_id" + ], + "tableTo": "user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "event_categories_color_check": { + "name": "event_categories_color_check", + "value": "\"event_categories\".\"color\" in ('blue', 'green', 'orange', 'purple', 'teal', 'gold', 'red', 'neutral')" + } + }, + "isRLSEnabled": false + }, + "public.event_reservations": { + "name": "event_reservations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "event_id": { + "name": "event_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "editorial_account_id": { + "name": "editorial_account_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "granted_at": { + "name": "granted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "event_reservations_event_editorial_unique": { + "name": "event_reservations_event_editorial_unique", + "columns": [ + { + "expression": "event_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "editorial_account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "event_reservations_event_id_calendar_events_id_fk": { + "name": "event_reservations_event_id_calendar_events_id_fk", + "tableFrom": "event_reservations", + "columnsFrom": [ + "event_id" + ], + "tableTo": "calendar_events", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + }, + "event_reservations_editorial_account_id_editorial_accounts_id_fk": { + "name": "event_reservations_editorial_account_id_editorial_accounts_id_fk", + "tableFrom": "event_reservations", + "columnsFrom": [ + "editorial_account_id" + ], + "tableTo": "editorial_accounts", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.billing_address_versions": { + "name": "billing_address_versions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "editorial_account_id": { + "name": "editorial_account_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "company_name": { + "name": "company_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "contact_name": { + "name": "contact_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "address_line_1": { + "name": "address_line_1", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "address_line_2": { + "name": "address_line_2", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "postal_code": { + "name": "postal_code", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "city": { + "name": "city", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "country_code": { + "name": "country_code", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "valid_from": { + "name": "valid_from", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "superseded_by_id": { + "name": "superseded_by_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "billing_address_versions_editorial_account_id_editorial_accounts_id_fk": { + "name": "billing_address_versions_editorial_account_id_editorial_accounts_id_fk", + "tableFrom": "billing_address_versions", + "columnsFrom": [ + "editorial_account_id" + ], + "tableTo": "editorial_accounts", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + }, + "billing_address_versions_superseded_by_id_billing_address_versions_id_fk": { + "name": "billing_address_versions_superseded_by_id_billing_address_versions_id_fk", + "tableFrom": "billing_address_versions", + "columnsFrom": [ + "superseded_by_id" + ], + "tableTo": "billing_address_versions", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + }, + "billing_address_versions_created_by_user_id_user_id_fk": { + "name": "billing_address_versions_created_by_user_id_user_id_fk", + "tableFrom": "billing_address_versions", + "columnsFrom": [ + "created_by_user_id" + ], + "tableTo": "user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.editorial_accounts": { + "name": "editorial_accounts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "contact_name": { + "name": "contact_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "login_email": { + "name": "login_email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "account_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'pending_email'" + }, + "current_price_cents": { + "name": "current_price_cents", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "flatrate_active": { + "name": "flatrate_active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "flatrate_price_cents": { + "name": "flatrate_price_cents", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "flatrate_asset_limit": { + "name": "flatrate_asset_limit", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "collab_enabled": { + "name": "collab_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "approval_notice_status": { + "name": "approval_notice_status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'not_requested'" + }, + "current_billing_address_version_id": { + "name": "current_billing_address_version_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "email_verified_at": { + "name": "email_verified_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "accepted_terms_version": { + "name": "accepted_terms_version", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "accepted_terms_at": { + "name": "accepted_terms_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "privacy_acknowledged_at": { + "name": "privacy_acknowledged_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "archived_by_user_id": { + "name": "archived_by_user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "editorial_accounts_user_id_user_id_fk": { + "name": "editorial_accounts_user_id_user_id_fk", + "tableFrom": "editorial_accounts", + "columnsFrom": [ + "user_id" + ], + "tableTo": "user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + }, + "editorial_accounts_current_billing_address_version_id_billing_address_versions_id_fk": { + "name": "editorial_accounts_current_billing_address_version_id_billing_address_versions_id_fk", + "tableFrom": "editorial_accounts", + "columnsFrom": [ + "current_billing_address_version_id" + ], + "tableTo": "billing_address_versions", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + }, + "editorial_accounts_archived_by_user_id_user_id_fk": { + "name": "editorial_accounts_archived_by_user_id_user_id_fk", + "tableFrom": "editorial_accounts", + "columnsFrom": [ + "archived_by_user_id" + ], + "tableTo": "user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "editorial_accounts_user_id_unique": { + "name": "editorial_accounts_user_id_unique", + "columns": [ + "user_id" + ], + "nullsNotDistinct": false + }, + "editorial_accounts_login_email_unique": { + "name": "editorial_accounts_login_email_unique", + "columns": [ + "login_email" + ], + "nullsNotDistinct": false + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.lightbox_items": { + "name": "lightbox_items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "editorial_account_id": { + "name": "editorial_account_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "asset_id": { + "name": "asset_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "added_at": { + "name": "added_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "lightbox_items_editorial_asset_idx": { + "name": "lightbox_items_editorial_asset_idx", + "columns": [ + { + "expression": "editorial_account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "asset_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "lightbox_items_editorial_account_id_editorial_accounts_id_fk": { + "name": "lightbox_items_editorial_account_id_editorial_accounts_id_fk", + "tableFrom": "lightbox_items", + "columnsFrom": [ + "editorial_account_id" + ], + "tableTo": "editorial_accounts", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.rate_limits": { + "name": "rate_limits", + "schema": "", + "columns": { + "key": { + "name": "key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "window_boundary": { + "name": "window_boundary", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "count": { + "name": "count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "rate_limits_key_window_boundary_pk": { + "name": "rate_limits_key_window_boundary_pk", + "columns": [ + "key", + "window_boundary" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.release_notes": { + "name": "release_notes", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "version": { + "name": "version", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "audience": { + "name": "audience", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'both'" + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "release_notes_version_audience_unique": { + "name": "release_notes_version_audience_unique", + "columns": [ + { + "expression": "version", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "audience", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "release_notes_created_by_user_id_user_id_fk": { + "name": "release_notes_created_by_user_id_user_id_fk", + "tableFrom": "release_notes", + "columnsFrom": [ + "created_by_user_id" + ], + "tableTo": "user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "release_notes_audience_check": { + "name": "release_notes_audience_check", + "value": "\"release_notes\".\"audience\" in ('admin', 'editorial', 'both')" + }, + "release_notes_version_check": { + "name": "release_notes_version_check", + "value": "\"release_notes\".\"version\" ~ '^[0-9]+\\.[0-9]+(\\.[0-9]+)?$'" + } + }, + "isRLSEnabled": false + }, + "public.download_events": { + "name": "download_events", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "editorial_account_id": { + "name": "editorial_account_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "usage_id": { + "name": "usage_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "immich_asset_id": { + "name": "immich_asset_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "authorized_at": { + "name": "authorized_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "started_at": { + "name": "started_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "download_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'authorized'" + }, + "transferred_bytes": { + "name": "transferred_bytes", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "repeat_download_note": { + "name": "repeat_download_note", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "request_id": { + "name": "request_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "idempotency_key": { + "name": "idempotency_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "intent_kind": { + "name": "intent_kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'new_usage'" + }, + "request_fingerprint": { + "name": "request_fingerprint", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "legacy_intent": { + "name": "legacy_intent", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + } + }, + "indexes": { + "download_events_editorial_authorized_id_idx": { + "name": "download_events_editorial_authorized_id_idx", + "columns": [ + { + "expression": "editorial_account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "authorized_at", + "isExpression": false, + "asc": false, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": false, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + }, + "download_events_editorial_idempotency_key_unique": { + "name": "download_events_editorial_idempotency_key_unique", + "columns": [ + { + "expression": "editorial_account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "idempotency_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "download_events_editorial_account_id_editorial_accounts_id_fk": { + "name": "download_events_editorial_account_id_editorial_accounts_id_fk", + "tableFrom": "download_events", + "columnsFrom": [ + "editorial_account_id" + ], + "tableTo": "editorial_accounts", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + }, + "download_events_usage_id_usages_id_fk": { + "name": "download_events_usage_id_usages_id_fk", + "tableFrom": "download_events", + "columnsFrom": [ + "usage_id" + ], + "tableTo": "usages", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "download_events_intent_kind_check": { + "name": "download_events_intent_kind_check", + "value": "\"download_events\".\"intent_kind\" in ('new_usage', 'repeat_download', 'legacy')" + }, + "download_events_request_fingerprint_hex_check": { + "name": "download_events_request_fingerprint_hex_check", + "value": "\"download_events\".\"request_fingerprint\" ~ '^[0-9a-f]{64}$'" + }, + "download_events_canonical_idempotency_key_check": { + "name": "download_events_canonical_idempotency_key_check", + "value": "\"download_events\".\"legacy_intent\" OR \"download_events\".\"idempotency_key\" ~ '^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$'" + }, + "download_events_canonical_immich_asset_id_check": { + "name": "download_events_canonical_immich_asset_id_check", + "value": "\"download_events\".\"immich_asset_id\" ~ '^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$'" + } + }, + "isRLSEnabled": false + }, + "public.usages": { + "name": "usages", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "editorial_account_id": { + "name": "editorial_account_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "immich_asset_id": { + "name": "immich_asset_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "filename_snapshot": { + "name": "filename_snapshot", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "immich_album_id_snapshot": { + "name": "immich_album_id_snapshot", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "album_name_snapshot": { + "name": "album_name_snapshot", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "purpose": { + "name": "purpose", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "internal_reference": { + "name": "internal_reference", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "price_cents": { + "name": "price_cents", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "collab": { + "name": "collab", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "billing_status": { + "name": "billing_status", + "type": "usage_billing_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'open'" + }, + "billing_report_id": { + "name": "billing_report_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "usages_editorial_created_id_idx": { + "name": "usages_editorial_created_id_idx", + "columns": [ + { + "expression": "editorial_account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": false, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": false, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + }, + "usages_created_at_idx": { + "name": "usages_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "usages_editorial_account_id_editorial_accounts_id_fk": { + "name": "usages_editorial_account_id_editorial_accounts_id_fk", + "tableFrom": "usages", + "columnsFrom": [ + "editorial_account_id" + ], + "tableTo": "editorial_accounts", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + }, + "usages_billing_report_id_billing_reports_id_fk": { + "name": "usages_billing_report_id_billing_reports_id_fk", + "tableFrom": "usages", + "columnsFrom": [ + "billing_report_id" + ], + "tableTo": "billing_reports", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "usages_canonical_immich_asset_id_check": { + "name": "usages_canonical_immich_asset_id_check", + "value": "\"usages\".\"immich_asset_id\" ~ '^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$'" + }, + "usages_canonical_immich_album_id_check": { + "name": "usages_canonical_immich_album_id_check", + "value": "\"usages\".\"immich_album_id_snapshot\" ~ '^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$'" + } + }, + "isRLSEnabled": false + } + }, + "enums": { + "public.portal_role": { + "name": "portal_role", + "schema": "public", + "values": [ + "ADMIN", + "EDITORIAL" + ] + }, + "public.report_status": { + "name": "report_status", + "schema": "public", + "values": [ + "draft", + "final", + "cancelled" + ] + }, + "public.account_status": { + "name": "account_status", + "schema": "public", + "values": [ + "pending_email", + "pending_approval", + "active", + "suspended", + "rejected" + ] + }, + "public.download_status": { + "name": "download_status", + "schema": "public", + "values": [ + "authorized", + "streaming", + "completed", + "failed_before_delivery", + "interrupted" + ] + }, + "public.usage_billing_status": { + "name": "usage_billing_status", + "schema": "public", + "values": [ + "open", + "billed", + "reopened", + "voided" + ] + } + }, + "schemas": {}, + "views": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.json index 44048f1..90ca691 100644 --- a/drizzle/meta/_journal.json +++ b/drizzle/meta/_journal.json @@ -64,6 +64,13 @@ "when": 1796077763423, "tag": "0008_release_notes_2_3_0", "breakpoints": true + }, + { + "idx": 9, + "version": "7", + "when": 1796079496182, + "tag": "0009_release_notes_2_4_0", + "breakpoints": true } ] } \ No newline at end of file diff --git a/src/app/(public)/registrieren/bestaetigt/page.tsx b/src/app/(public)/registrieren/bestaetigt/page.tsx index 0c14038..9125935 100644 --- a/src/app/(public)/registrieren/bestaetigt/page.tsx +++ b/src/app/(public)/registrieren/bestaetigt/page.tsx @@ -1,16 +1,30 @@ import Link from "next/link"; import { PublicShell } from "@/components/layout/public-shell"; +import { RegistrationSteps } from "@/components/layout/registration-steps"; import { Button } from "@/components/ui/button"; -export default function RegistrationConfirmedPage() { +// Two arrivals share this page: right after the form (e-mail still to +// confirm) and from the confirmation link (?schritt=freigabe, see auth.ts). +export default async function RegistrationConfirmedPage({ + searchParams, +}: Readonly<{ searchParams: Promise> }>) { + const { schritt } = await searchParams; + const confirmed = schritt === "freigabe"; + return ( +
- {actionState.message && ( -
- -
- )} {reports.length > 0 && ( @@ -432,15 +416,14 @@ type InvoiceUploadFormProps = { }; function InvoiceUploadForm({ reportId, reportNumber, hasInvoice, emailFailed }: InvoiceUploadFormProps) { + const router = useRouter(); const [file, setFile] = useState(null); const [loading, setLoading] = useState(false); - const [error, setError] = useState(null); async function handleUpload(event: React.FormEvent) { event.preventDefault(); if (!file || loading) return; setLoading(true); - setError(null); try { const formData = new FormData(); formData.set("invoice", file); @@ -452,17 +435,17 @@ function InvoiceUploadForm({ reportId, reportNumber, hasInvoice, emailFailed }: const body = await response.json().catch(() => ({ code: "ERROR" })); throw new Error(invoiceErrorMessage(body.code)); } - window.location.reload(); + toast.success(`Rechnung zu Bericht Nr. ${reportNumber} hochgeladen. Der Versand an die Redaktion läuft.`); + router.refresh(); } catch (err) { - setError(err instanceof Error ? err.message : "Upload fehlgeschlagen"); - setLoading(false); + toast.error(err instanceof Error ? err.message : invoiceErrorMessage(null)); } + setLoading(false); } async function handleResend() { if (loading) return; setLoading(true); - setError(null); try { const response = await fetch( `/api/billing-reports/${encodeURIComponent(reportId)}/invoice/resend`, @@ -472,11 +455,12 @@ function InvoiceUploadForm({ reportId, reportNumber, hasInvoice, emailFailed }: const body = await response.json().catch(() => ({ code: "ERROR" })); throw new Error(invoiceErrorMessage(body.code)); } - window.location.reload(); + toast.success("Rechnung erneut versendet."); + router.refresh(); } catch (err) { - setError(err instanceof Error ? err.message : "Versand fehlgeschlagen"); - setLoading(false); + toast.error(err instanceof Error ? err.message : invoiceErrorMessage(null)); } + setLoading(false); } return ( @@ -509,7 +493,6 @@ function InvoiceUploadForm({ reportId, reportNumber, hasInvoice, emailFailed }: Nach dem Upload geht die Rechnung gebündelt mit dem Nutzungsnachweis automatisch per E-Mail an die Redaktion.

- {error && } ); } @@ -535,10 +518,10 @@ type CancelReportFormProps = { }; function CancelReportForm({ reportId, reportNumber }: CancelReportFormProps) { + const router = useRouter(); const [reason, setReason] = useState(""); const [confirmed, setConfirmed] = useState(false); const [loading, setLoading] = useState(false); - const [error, setError] = useState(null); const trimmed = reason.trim(); const valid = trimmed.length >= 5 && trimmed.length <= 500 && confirmed; @@ -547,7 +530,6 @@ function CancelReportForm({ reportId, reportNumber }: CancelReportFormProps) { event.preventDefault(); if (!valid) return; setLoading(true); - setError(null); try { const response = await fetch(`/api/billing-reports/${encodeURIComponent(reportId)}/cancel`, { method: "POST", @@ -556,13 +538,14 @@ function CancelReportForm({ reportId, reportNumber }: CancelReportFormProps) { }); if (!response.ok) { const body = await response.json().catch(() => ({ code: "ERROR" })); - throw new Error(body.code ?? "Stornierung fehlgeschlagen"); + throw new Error(billingErrorMessage(body.code)); } - window.location.reload(); + toast.success(`Bericht Nr. ${reportNumber} storniert. Die Nutzungen sind wieder offen.`); + router.refresh(); } catch (err) { - setError(err instanceof Error ? err.message : "Stornierung fehlgeschlagen"); - setLoading(false); + toast.error(err instanceof Error ? err.message : billingErrorMessage(null)); } + setLoading(false); } return ( @@ -587,7 +570,30 @@ function CancelReportForm({ reportId, reportNumber }: CancelReportFormProps) { {loading ? "Wird storniert …" : "Stornieren"} - {error && } ); } + +function billingErrorMessage(code: unknown): string { + switch (code) { + case "NO_USAGES_SELECTED": + return "Bitte mindestens eine offene Nutzung auswählen."; + case "USAGE_NOT_ELIGIBLE": + case "USAGE_NOT_FOUND": + return "Eine der gewählten Nutzungen ist nicht mehr abrechenbar. Bitte die Seite neu laden."; + case "ADDRESS_NOT_FOUND": + return "Für diese Redaktion fehlt die Rechnungsadresse."; + case "EDITORIAL_NOT_FOUND": + return "Diese Redaktion existiert nicht mehr."; + case "REPORT_NOT_FOUND": + return "Dieser Bericht existiert nicht mehr."; + case "INVALID_CANCELLATION_REASON": + return "Bitte einen Stornierungsgrund mit 5 bis 500 Zeichen angeben."; + case "REPORT_NUMBER_COLLISION": + return "Die Berichtsnummer war gerade vergeben. Bitte erneut versuchen."; + case "RATE_LIMITED": + return "Zu viele Versuche. Bitte kurz warten."; + default: + return "Der Vorgang ist fehlgeschlagen. Bitte erneut versuchen."; + } +} diff --git a/src/app/admin/alben/AlbumAccessManager.tsx b/src/app/admin/alben/AlbumAccessManager.tsx index 927706c..dc88ac2 100644 --- a/src/app/admin/alben/AlbumAccessManager.tsx +++ b/src/app/admin/alben/AlbumAccessManager.tsx @@ -5,12 +5,13 @@ import { useActionState, useMemo, useState, useTransition } from "react"; import Link from "next/link"; -import { Alert, Checkbox, EmptyState, Input, Table } from "@sakaniui/react"; +import { Checkbox, EmptyState, Input, Table } from "@sakaniui/react"; import { IconSearch, IconX } from "@sakaniui/react/icons"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import type { AlbumAccessActionResult } from "./actions"; +import { notifyResult, useResultToast } from "@/components/ui/feedback"; type AccessAction = ( state: AlbumAccessActionResult, @@ -42,12 +43,12 @@ export function AlbumAccessManager({ bulkGrantAction: AccessAction; revokeAction: AccessAction; }>) { - const [bulkState, setBulkState] = useState(INITIAL_RESULT); const [bulkPending, startBulkTransition] = useTransition(); const [revokeState, revokeFormAction, revokePending] = useActionState( revokeAction, INITIAL_RESULT, ); + useResultToast(revokeState); const [selectedAlbumIds, setSelectedAlbumIds] = useState>(new Set()); const [selectedEditorialIds, setSelectedEditorialIds] = useState>(new Set()); const [bulkSearch, setBulkSearch] = useState(""); @@ -58,7 +59,7 @@ export function AlbumAccessManager({ const handleBulkSubmit = (formData: FormData) => { startBulkTransition(async () => { const result = await bulkGrantAction(INITIAL_RESULT, formData); - setBulkState(result); + notifyResult(result); if (result.ok && result.grantedCount > 0) { setSelectedAlbumIds(new Set()); setSelectedEditorialIds(new Set()); @@ -255,13 +256,9 @@ export function AlbumAccessManager({
- {bulkState.message ? ( - - ) : ( -

+

Wähle mindestens ein Album und eine Redaktion aus.

- )} @@ -291,9 +288,6 @@ export function AlbumAccessManager({
- {revokeState.message ? ( - - ) : null} {albums.length === 0 ? ( diff --git a/src/app/admin/audit/page.tsx b/src/app/admin/audit/page.tsx index f4e1cac..253a648 100644 --- a/src/app/admin/audit/page.tsx +++ b/src/app/admin/audit/page.tsx @@ -2,7 +2,9 @@ import Link from "next/link"; import { Button } from "@/components/ui/button"; import { PageHeader } from "@/components/ui/page-header"; -import { Card, DataTable, EmptyState, Input } from "@/components/ui/sakani"; +import { Badge, Card, DataTable, EmptyState, FormSelect, Input } from "@/components/ui/sakani"; +import { db } from "@/db/client"; +import { auditEvents } from "@/db/schema"; import { listAuditEvents, type AuditEventRow } from "@/modules/audit/queries"; import { requireAdminPage } from "../access"; @@ -24,14 +26,21 @@ export default async function AuditPage({ searchParams }: { searchParams: Search const dateTo = firstParam(params, "dateTo"); const cursor = firstParam(params, "cursor"); - const page = await listAuditEvents( + const [page, typeRows] = await Promise.all([ + listAuditEvents( { eventType: eventType || undefined, dateFrom: dateFrom ? berlinDateToUtc(dateFrom) : undefined, dateTo: dateTo ? berlinDateToUtcEndOfDay(dateTo) : undefined, }, - cursor || null, - ); + cursor || null, + ), + db.selectDistinct({ eventType: auditEvents.eventType }).from(auditEvents).orderBy(auditEvents.eventType), + ]); + const typeOptions = [ + { label: "Alle Ereignisse", value: "" }, + ...typeRows.map(({ eventType: type }) => ({ label: eventLabel(type), value: type })), + ]; return (
@@ -44,7 +53,7 @@ export default async function AuditPage({ searchParams }: { searchParams: Search
- + @@ -58,16 +67,30 @@ export default async function AuditPage({ searchParams }: { searchParams: Search columns={[ { key: "at", header: "Zeitstempel" }, { key: "actor", header: "Akteur" }, - { key: "type", header: "Ereignistyp" }, + { key: "type", header: "Ereignis" }, { key: "subject", header: "Betreff" }, { key: "details", header: "Details" }, ]} rows={page.events.map((event) => ({ at: {berlinFormatter.format(new Date(event.occurredAt))}, - actor: actorLabel(event), - type: {event.eventType}, - subject: {entityLabel(event)}, - details:
{formatMetadata(event)}
, + actor: ( +
+ + {ACTOR_BADGES[event.actorType]?.label ?? event.actorType} + + {event.actorType === "system" ? null : ( + {actorLabel(event)} + )} +
+ ), + type: ( +
+ {eventLabel(event.eventType)} + {event.eventType} +
+ ), + subject: {entityLabel(event)}, + details: , }))} /> )} @@ -104,10 +127,65 @@ function entityLabel(event: AuditEventRow): string { return `${event.entityType} · ${event.entityId}`; } -function formatMetadata(event: AuditEventRow): string { +const ACTOR_BADGES: Record = { + admin: { label: "Admin", variant: "accent" }, + editorial: { label: "Redaktion", variant: "info" }, + system: { label: "System", variant: "neutral" }, +}; + +const EVENT_LABELS: Record = { + album_granted: "Album freigegeben", + album_revoked: "Albumzugriff entzogen", + album_self_granted: "Album selbst freigeschaltet", + announcement_created: "Hinweis veröffentlicht", + announcement_deleted: "Hinweis gelöscht", + billable_usage_created: "Neue Nutzung", + billing_address_replaced: "Rechnungsadresse geändert", + billing_report_cancelled: "Abrechnung storniert", + billing_report_finalized: "Abrechnung erstellt", + calendar_event_created: "Termin angelegt", + calendar_event_deleted: "Termin gelöscht", + editorial_approved: "Redaktion freigegeben", + editorial_collab_updated: "Collab-Einstellung geändert", + event_category_created: "Kategorie angelegt", + event_category_deleted: "Kategorie gelöscht", + event_reservation_removed: "Vormerkung entfernt", + event_reserved: "Termin vorgemerkt", + event_response_recorded: "Rückmeldung zu Termin", + invoice_email_failed: "Rechnungsmail fehlgeschlagen", + invoice_email_sent: "Rechnungsmail versendet", + invoice_uploaded: "Rechnung hochgeladen", + release_note_created: "Versionshinweis angelegt", + release_note_deleted: "Versionshinweis gelöscht", + usage_collab_updated: "Collab-Kennzeichnung geändert", +}; + +function eventLabel(type: string): string { + return EVENT_LABELS[type] ?? type.replaceAll("_", " "); +} + +function AuditDetails({ event }: Readonly<{ event: AuditEventRow }>) { const detail = event.newValues ?? event.previousValues; - if (!detail) return "—"; - return JSON.stringify(detail, null, 2); + if (!detail || typeof detail !== "object") { + return -; + } + const entries = Object.entries(detail as Record); + if (entries.length === 0) return -; + return ( +
+ + {entries.length === 1 ? "1 Angabe" : `${entries.length} Angaben`} + +
+ {entries.map(([key, value]) => ( +
+
{key}
+
{typeof value === "string" ? value : JSON.stringify(value)}
+
+ ))} +
+
+ ); } function berlinDateToUtc(dateStr: string): Date | undefined { diff --git a/src/app/admin/hinweise/AnnouncementForm.tsx b/src/app/admin/hinweise/AnnouncementForm.tsx index 5f95e39..13b3847 100644 --- a/src/app/admin/hinweise/AnnouncementForm.tsx +++ b/src/app/admin/hinweise/AnnouncementForm.tsx @@ -2,13 +2,14 @@ import { useId, useState, useTransition } from "react"; -import { Alert, Input, Textarea } from "@sakaniui/react"; +import { Input, Textarea } from "@sakaniui/react"; import { Card } from "@/components/ui/sakani"; import { Button } from "@/components/ui/button"; import type { AnnouncementActionResult } from "./actions"; +import { notifyResult } from "@/components/ui/feedback"; // Same direct-call-in-transition pattern as the album bulk grant form so the // message box clears after a successful publish without an effect. @@ -24,14 +25,13 @@ export function AnnouncementForm({ }>) { const messageId = useId(); const dateId = useId(); - const [state, setState] = useState({ ok: true, message: "" }); const [pending, startTransition] = useTransition(); const [message, setMessage] = useState(""); const handleSubmit = (formData: FormData) => { startTransition(async () => { const result = await action({ ok: true, message: "" }, formData); - setState(result); + notifyResult(result); if (result.ok) { setMessage(""); } @@ -69,11 +69,6 @@ export function AnnouncementForm({ {pending ? "Wird veröffentlicht …" : "Hinweis veröffentlichen"} - {state.message ? ( -
- -
- ) : null}
); diff --git a/src/app/admin/hinweise/DeleteAnnouncementButton.tsx b/src/app/admin/hinweise/DeleteAnnouncementButton.tsx index 10012c7..dd421a3 100644 --- a/src/app/admin/hinweise/DeleteAnnouncementButton.tsx +++ b/src/app/admin/hinweise/DeleteAnnouncementButton.tsx @@ -7,6 +7,7 @@ import { IconTrash } from "@sakaniui/react/icons"; import { Button } from "@/components/ui/button"; import type { AnnouncementActionResult } from "./actions"; +import { useResultToast } from "@/components/ui/feedback"; // One tiny form per announcement row so every delete button reports its own // result inline (same pattern as AlbumGrantForm). @@ -21,6 +22,7 @@ export function DeleteAnnouncementButton({ announcementId: string; }>) { const [state, formAction, pending] = useActionState(action, { ok: true, message: "" }); + useResultToast(state, "Hinweis gelöscht."); return (
@@ -28,11 +30,6 @@ export function DeleteAnnouncementButton({ - {state.ok ? null : ( -

- {state.message} -

- )}
); } diff --git a/src/app/admin/kalender/CalendarEventForm.tsx b/src/app/admin/kalender/CalendarEventForm.tsx index b4e506f..caccb34 100644 --- a/src/app/admin/kalender/CalendarEventForm.tsx +++ b/src/app/admin/kalender/CalendarEventForm.tsx @@ -2,12 +2,13 @@ import { useId, useState, useTransition } from "react"; -import { Alert, Input } from "@sakaniui/react"; +import { Input } from "@sakaniui/react"; import { Button } from "@/components/ui/button"; import { Card, FormSelect } from "@/components/ui/sakani"; import type { CalendarActionResult } from "./actions"; +import { notifyResult } from "@/components/ui/feedback"; export function CalendarEventForm({ action, @@ -22,14 +23,13 @@ export function CalendarEventForm({ }>) { const titleId = useId(); const dateId = useId(); - const [state, setState] = useState({ ok: true, message: "" }); const [pending, startTransition] = useTransition(); const [title, setTitle] = useState(""); const handleSubmit = (formData: FormData) => { startTransition(async () => { const result = await action({ ok: true, message: "" }, formData); - setState(result); + notifyResult(result); if (result.ok) { setTitle(""); } @@ -80,11 +80,6 @@ export function CalendarEventForm({ {pending ? "Wird angelegt …" : "Termin anlegen"} - {state.message ? ( -
- -
- ) : null} ); diff --git a/src/app/admin/kalender/DeleteCalendarEventButton.tsx b/src/app/admin/kalender/DeleteCalendarEventButton.tsx index 4b0ff7b..10b770b 100644 --- a/src/app/admin/kalender/DeleteCalendarEventButton.tsx +++ b/src/app/admin/kalender/DeleteCalendarEventButton.tsx @@ -1,10 +1,11 @@ "use client"; -import { useState, useTransition } from "react"; +import { useTransition } from "react"; import { Button } from "@/components/ui/button"; import type { CalendarActionResult } from "./actions"; +import { notifyResult } from "@/components/ui/feedback"; // Deleting an event also revokes self-service grants on its linked album, so // the admin confirms once before the action runs. @@ -15,7 +16,6 @@ export function DeleteCalendarEventButton({ action: (state: CalendarActionResult, formData: FormData) => Promise; eventId: string; }>) { - const [state, setState] = useState({ ok: true, message: "" }); const [pending, startTransition] = useTransition(); const handleClick = () => { @@ -25,7 +25,7 @@ export function DeleteCalendarEventButton({ const formData = new FormData(); formData.set("eventId", eventId); startTransition(async () => { - setState(await action({ ok: true, message: "" }, formData)); + notifyResult(await action({ ok: true, message: "" }, formData), "Termin gelöscht."); }); }; @@ -34,11 +34,6 @@ export function DeleteCalendarEventButton({ - {state.ok ? null : ( -

- {state.message} -

- )} ); } diff --git a/src/app/admin/kalender/kategorien/CategoryForm.tsx b/src/app/admin/kalender/kategorien/CategoryForm.tsx index 1c350c2..1be4938 100644 --- a/src/app/admin/kalender/kategorien/CategoryForm.tsx +++ b/src/app/admin/kalender/kategorien/CategoryForm.tsx @@ -1,7 +1,7 @@ "use client"; import { useId, useState, useTransition } from "react"; -import { Alert, Input } from "@sakaniui/react"; +import { Input } from "@sakaniui/react"; import { CategoryDot } from "@/components/calendar/category-legend"; import { Button } from "@/components/ui/button"; @@ -9,6 +9,7 @@ import { Card } from "@/components/ui/sakani"; import { CATEGORY_COLOR_LABELS, CATEGORY_COLORS, type CategoryColor } from "@/modules/calendar/colors"; import type { CategoryActionResult } from "./actions"; +import { notifyResult } from "@/components/ui/feedback"; export function CategoryForm({ action, @@ -16,13 +17,12 @@ export function CategoryForm({ const nameId = useId(); const [name, setName] = useState(""); const [color, setColor] = useState("blue"); - const [state, setState] = useState({ ok: true, message: "" }); const [pending, startTransition] = useTransition(); const handleSubmit = (formData: FormData) => { startTransition(async () => { const result = await action({ ok: true, message: "" }, formData); - setState(result); + notifyResult(result); if (result.ok) setName(""); }); }; @@ -73,11 +73,6 @@ export function CategoryForm({ {pending ? "Wird gespeichert …" : "Kategorie speichern"} - {state.message ? ( -
- -
- ) : null} ); diff --git a/src/app/admin/kalender/kategorien/DeleteCategoryButton.tsx b/src/app/admin/kalender/kategorien/DeleteCategoryButton.tsx index 70f640c..937aceb 100644 --- a/src/app/admin/kalender/kategorien/DeleteCategoryButton.tsx +++ b/src/app/admin/kalender/kategorien/DeleteCategoryButton.tsx @@ -1,10 +1,11 @@ "use client"; -import { useState, useTransition } from "react"; +import { useTransition } from "react"; import { Button } from "@/components/ui/button"; import type { CategoryActionResult } from "./actions"; +import { notifyResult } from "@/components/ui/feedback"; export function DeleteCategoryButton({ action, @@ -15,13 +16,12 @@ export function DeleteCategoryButton({ categoryId: string; inUse: boolean; }>) { - const [state, setState] = useState({ ok: true, message: "" }); const [pending, startTransition] = useTransition(); const handleClick = () => { const formData = new FormData(); formData.set("categoryId", categoryId); - startTransition(async () => setState(await action({ ok: true, message: "" }, formData))); + startTransition(async () => notifyResult(await action({ ok: true, message: "" }, formData), "Kategorie gelöscht.")); }; return ( @@ -36,11 +36,6 @@ export function DeleteCategoryButton({ > {pending ? "…" : "Löschen"} - {state.ok ? null : ( -

- {state.message} -

- )} ); } diff --git a/src/app/admin/redaktionen/EditorialsTable.tsx b/src/app/admin/redaktionen/EditorialsTable.tsx new file mode 100644 index 0000000..75bbb85 --- /dev/null +++ b/src/app/admin/redaktionen/EditorialsTable.tsx @@ -0,0 +1,145 @@ +"use client"; + +import { useMemo, useState } from "react"; +import Link from "next/link"; +import { Badge, EmptyState, Input, SegmentedControl, Table, type TableColumn } from "@sakaniui/react"; +import { IconSearch } from "@sakaniui/react/icons"; + +export type EditorialRow = { + id: string; + name: string; + contactName: string; + loginEmail: string; + status: string; + archived: boolean; + priceCents: number | null; + openCents: number; + createdAt: string; +}; + +type StatusKey = "active" | "pending" | "suspended" | "archived"; + +const STATUS: Record = { + active: { label: "Aktiv", variant: "success" }, + pending: { label: "Ausstehend", variant: "warning" }, + suspended: { label: "Gesperrt", variant: "danger" }, + archived: { label: "Archiviert", variant: "neutral" }, +}; + +function statusOf(row: EditorialRow): StatusKey { + if (row.archived) return "archived"; + if (row.status === "active") return "active"; + if (row.status === "pending_email" || row.status === "pending_approval") return "pending"; + return "suspended"; +} + +const euro = new Intl.NumberFormat("de-DE", { style: "currency", currency: "EUR" }); +const date = new Intl.DateTimeFormat("de-DE", { dateStyle: "medium", timeZone: "Europe/Berlin" }); + +type Row = EditorialRow & { statusCell?: never; priceCell?: never; openCell?: never; createdCell?: never }; + +const columns: TableColumn[] = [ + { + key: "name", + header: "Redaktion", + render: (row) => ( +
+ + {row.name} + + {row.loginEmail} +
+ ), + }, + { key: "contactName", header: "Kontakt" }, + { + key: "statusCell", + header: "Status", + render: (row) => { + const status = STATUS[statusOf(row)]; + return {status.label}; + }, + }, + { + key: "priceCell", + header: "Preis netto", + align: "right", + render: (row) => ( + {row.priceCents === null ? "offen" : euro.format(row.priceCents / 100)} + ), + }, + { + key: "openCell", + header: "Nicht abgerechnet", + align: "right", + render: (row) => ( + 0 ? "font-medium text-[var(--color-warning-fg)]" : "text-[var(--color-fg-muted)]"}`}> + {euro.format(row.openCents / 100)} + + ), + }, + { + key: "createdCell", + header: "Registriert", + align: "right", + render: (row) => {date.format(new Date(row.createdAt))}, + }, +]; + +const FILTERS = [ + { value: "all", label: "Alle" }, + { value: "active", label: "Aktiv" }, + { value: "pending", label: "Ausstehend" }, + { value: "suspended", label: "Gesperrt" }, + { value: "archived", label: "Archiviert" }, +]; + +export function EditorialsTable({ rows }: Readonly<{ rows: EditorialRow[] }>) { + const [query, setQuery] = useState(""); + const [filter, setFilter] = useState("all"); + + const visible = useMemo(() => { + const needle = query.trim().toLowerCase(); + return rows.filter((row) => { + const status = statusOf(row); + // "Alle" hides archived accounts; they have their own filter. + if (filter === "all" ? status === "archived" : status !== filter) return false; + return !needle || [row.name, row.contactName, row.loginEmail].some((value) => value.toLowerCase().includes(needle)); + }); + }, [rows, query, filter]); + + return ( +
+
+
+ +
+
+ } + onChange={(event) => setQuery(event.target.value)} + placeholder="Name, Kontakt oder E-Mail …" + type="search" + value={query} + /> +
+
+ + {visible.length === 0 ? ( + + ) : ( + columns={columns} rowKey={(row) => row.id} rows={visible} /> + )} +

+ {visible.length} von {rows.length} Redaktionen +

+
+ ); +} diff --git a/src/app/admin/redaktionen/[id]/alben/AlbumGrid.tsx b/src/app/admin/redaktionen/[id]/alben/AlbumGrid.tsx index 82e19a5..ebcd0fe 100644 --- a/src/app/admin/redaktionen/[id]/alben/AlbumGrid.tsx +++ b/src/app/admin/redaktionen/[id]/alben/AlbumGrid.tsx @@ -9,6 +9,7 @@ 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, @@ -46,9 +47,9 @@ function AlbumCard({ album, editorialId, grantAction, revokeAction, notifyAction startTransition(async () => { const initial: AlbumActionResult = { ok: true, message: "" }; if (album.isGranted) { - await revokeAction(editorialId, initial, formData); + notifyResult(await revokeAction(editorialId, initial, formData), "Zuweisung aufgehoben."); } else { - await grantAction(editorialId, initial, formData); + notifyResult(await grantAction(editorialId, initial, formData), "Album zugewiesen."); } }); }; @@ -99,6 +100,7 @@ function AlbumCard({ album, editorialId, grantAction, revokeAction, notifyAction 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); }); }} diff --git a/src/app/admin/redaktionen/[id]/alben/page.test.tsx b/src/app/admin/redaktionen/[id]/alben/page.test.tsx index 00a0824..0b1bbd2 100644 --- a/src/app/admin/redaktionen/[id]/alben/page.test.tsx +++ b/src/app/admin/redaktionen/[id]/alben/page.test.tsx @@ -3,6 +3,8 @@ import { render, screen } from "@testing-library/react"; import { expect, test, vi } from "vitest"; +vi.mock("next/navigation", () => ({ useRouter: () => ({ refresh: vi.fn(), push: vi.fn() }) })); + import { EditorialDetailContent } from "@/modules/editorials/admin-detail"; import { AlbumGrantError } from "@/modules/albums/grants"; import { loadAssignableAlbums } from "./page-content"; diff --git a/src/app/admin/redaktionen/[id]/auto-regeln/page.tsx b/src/app/admin/redaktionen/[id]/auto-regeln/page.tsx index ba846b5..7ddec8a 100644 --- a/src/app/admin/redaktionen/[id]/auto-regeln/page.tsx +++ b/src/app/admin/redaktionen/[id]/auto-regeln/page.tsx @@ -14,6 +14,7 @@ import { PageHeader } from "@/components/ui/page-header"; import { requireAdminPage } from "../../../access"; import { applyAutoRulesAction, createAutoRuleAction, deleteAutoRuleAction } from "./actions"; +import { ToastForm } from "@/components/ui/feedback"; type AutoRulesPageProps = Readonly<{ params: Promise<{ id: string }>; @@ -51,14 +52,14 @@ export default async function AutoRulesPage({ params }: AutoRulesPageProps) { -
+
- +
@@ -71,11 +72,11 @@ export default async function AutoRulesPage({ params }: AutoRulesPageProps) { Alle derzeit aktiven automatischen Zuweisungen. -
+ - +
@@ -91,11 +92,11 @@ export default async function AutoRulesPage({ params }: AutoRulesPageProps) { Erstellt am {new Date(rule.createdAt).toLocaleDateString('de-DE')} -
+ - +
))} diff --git a/src/app/admin/redaktionen/page.tsx b/src/app/admin/redaktionen/page.tsx index 028deac..84084d7 100644 --- a/src/app/admin/redaktionen/page.tsx +++ b/src/app/admin/redaktionen/page.tsx @@ -3,10 +3,13 @@ import Link from "next/link"; import { db } from "@/db/client"; import { editorialAccounts, usages } from "@/db/schema"; import { PageHeader } from "@/components/ui/page-header"; -import { IconChevronRight } from "@sakaniui/react/icons"; -import { Badge, Card, EmptyState } from "@/components/ui/sakani"; +import { EmptyState } from "@/components/ui/sakani"; + +import { requireAdminPage } from "../access"; +import { EditorialsTable } from "./EditorialsTable"; export default async function EditorialsPage() { + await requireAdminPage(); const [editorials, openUsageTotals] = await Promise.all([ db .select({ @@ -37,96 +40,31 @@ export default async function EditorialsPage() { openUsageTotals.map((total) => [total.editorialId, total.openCents]), ); - const activeEditorials = editorials.filter((e) => !e.archivedAt); - const archivedEditorials = editorials.filter((e) => e.archivedAt); - return (
- {activeEditorials.length === 0 ? ( - + {editorials.length === 0 ? ( + ) : ( -
    - {activeEditorials.map((editorial) => { - const openCents = openCentsByEditorial.get(editorial.id) ?? 0; - return ( -
  • - - -
    -

    {editorial.name}

    - - {STATUS[editorial.status]?.label ?? "Gesperrt"} - -
    -
    -
    Kontakt
    -
    {editorial.contactName}
    -
    E-Mail
    -
    {editorial.loginEmail}
    -
    -

    - {editorial.currentPriceCents === null - ? "Preis noch nicht festgelegt" - : `Netto ${formatCents(editorial.currentPriceCents)}`} - 0 ? "text-[var(--color-warning-fg)]" : "text-[var(--color-fg-muted)]"}`} - title="Summe der noch nicht abgerechneten Bildnutzungen" - > - · Offen {formatCents(openCents)} - -

    -
    - -
  • - ); - })} -
- )} - - {archivedEditorials.length > 0 && ( -
- - -
    - {archivedEditorials.map((editorial) => ( -
  • - - -
    -

    {editorial.name}

    - Archiviert -
    -

    {editorial.contactName} · {editorial.loginEmail}

    -

    - Archiviert am: {editorial.archivedAt ? new Date(editorial.archivedAt).toLocaleDateString("de-DE") : ""} -

    -
    - -
  • - ))} -
-
+ ({ + id: editorial.id, + name: editorial.name, + contactName: editorial.contactName, + loginEmail: editorial.loginEmail, + status: editorial.status, + archived: Boolean(editorial.archivedAt), + priceCents: editorial.currentPriceCents, + openCents: openCentsByEditorial.get(editorial.id) ?? 0, + createdAt: editorial.createdAt.toISOString(), + }))} + /> )}
); } - -const CARD_LINK = - "block h-full rounded-[var(--radius-xl)] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--color-border-focus)]"; - -const STATUS: Record = { - active: { label: "Aktiv", variant: "success" }, - pending_approval: { label: "Ausstehend", variant: "warning" }, -}; - -function formatCents(cents: number): string { - return new Intl.NumberFormat("de-DE", { style: "currency", currency: "EUR" }).format(cents / 100); -} \ No newline at end of file diff --git a/src/app/admin/versionen/DeleteReleaseNoteButton.tsx b/src/app/admin/versionen/DeleteReleaseNoteButton.tsx index 2c1d3d9..aa4e7d7 100644 --- a/src/app/admin/versionen/DeleteReleaseNoteButton.tsx +++ b/src/app/admin/versionen/DeleteReleaseNoteButton.tsx @@ -5,6 +5,7 @@ import { useActionState } from "react"; import { Button } from "@/components/ui/button"; import type { ReleaseNoteActionResult } from "./actions"; +import { useResultToast } from "@/components/ui/feedback"; export function DeleteReleaseNoteButton({ action, @@ -14,6 +15,7 @@ export function DeleteReleaseNoteButton({ noteId: string; }>) { const [state, formAction, pending] = useActionState(action, { ok: true, message: "" }); + useResultToast(state, "Versionshinweis gelöscht."); return (
@@ -21,11 +23,6 @@ export function DeleteReleaseNoteButton({ - {state.ok ? null : ( -

- {state.message} -

- )}
); } diff --git a/src/app/admin/versionen/ReleaseNoteForm.tsx b/src/app/admin/versionen/ReleaseNoteForm.tsx index 7631c24..b03ec90 100644 --- a/src/app/admin/versionen/ReleaseNoteForm.tsx +++ b/src/app/admin/versionen/ReleaseNoteForm.tsx @@ -2,12 +2,13 @@ import { useId, useState, useTransition } from "react"; -import { Alert, Input, Textarea } from "@sakaniui/react"; +import { Input, Textarea } from "@sakaniui/react"; import { Button } from "@/components/ui/button"; import { Card, FormSelect } from "@/components/ui/sakani"; import type { ReleaseNoteActionResult } from "./actions"; +import { notifyResult } from "@/components/ui/feedback"; export function ReleaseNoteForm({ action, @@ -16,14 +17,13 @@ export function ReleaseNoteForm({ }>) { const versionId = useId(); const bodyId = useId(); - const [state, setState] = useState({ ok: true, message: "" }); const [pending, startTransition] = useTransition(); const [body, setBody] = useState(""); const handleSubmit = (formData: FormData) => { startTransition(async () => { const result = await action({ ok: true, message: "" }, formData); - setState(result); + notifyResult(result); if (result.ok) { setBody(""); } @@ -67,11 +67,6 @@ export function ReleaseNoteForm({ {pending ? "Wird veröffentlicht …" : "Hinweis veröffentlichen"} - {state.message ? ( -
- -
- ) : null} ); diff --git a/src/app/globals.css b/src/app/globals.css index 03102d2..d44e474 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -208,7 +208,15 @@ body:has([data-app-shell]) .legal-footer { background: var(--contact-sheet); } +.photo-tile-skeleton { + position: absolute; + inset: 0; + width: 100%; + height: 100%; +} + .photo-tile-trigger { + position: relative; display: block; width: 100%; margin: 0; @@ -220,6 +228,7 @@ body:has([data-app-shell]) .legal-footer { } .photo-tile-image { + position: relative; display: block; width: 100%; height: auto; diff --git a/src/app/layout.tsx b/src/app/layout.tsx index df78d61..1904b36 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -10,6 +10,7 @@ import "./globals.css"; import { LegalFooter } from "@/components/layout/legal-footer"; import { ThemeProvider } from "@/components/theme-provider"; +import { AppToaster } from "@/components/ui/feedback"; export const metadata: Metadata = { title: "Redaktionsportal | Leon Tonhäuser", @@ -34,6 +35,7 @@ export default function RootLayout({ children }: Readonly<{ children: ReactNode {children} + diff --git a/src/app/redaktion/alben/[albumId]/loading.tsx b/src/app/redaktion/alben/[albumId]/loading.tsx index 8918159..fc69a50 100644 --- a/src/app/redaktion/alben/[albumId]/loading.tsx +++ b/src/app/redaktion/alben/[albumId]/loading.tsx @@ -1,10 +1,18 @@ -import { Spinner } from "@/components/ui/sakani"; +import { Skeleton } from "@/components/ui/sakani"; export default function AlbumLoading() { return ( -
- -

Fotos werden geladen.

+
+ Fotos werden geladen. + + +
    + {Array.from({ length: 8 }, (_, index) => ( +
  • + +
  • + ))} +
); } diff --git a/src/app/redaktion/alben/loading.tsx b/src/app/redaktion/alben/loading.tsx index 71a9561..c03456d 100644 --- a/src/app/redaktion/alben/loading.tsx +++ b/src/app/redaktion/alben/loading.tsx @@ -1,10 +1,24 @@ -import { Spinner } from "@/components/ui/sakani"; +import { Skeleton } from "@/components/ui/sakani"; +// Sakani's Skeleton sizes itself via width/height props (its CSS outranks +// Tailwind sizing classes on its root). export default function AlbumsLoading() { return ( -
- -

Alben werden geladen.

+
+ Alben werden geladen. + + +
    + {Array.from({ length: 6 }, (_, index) => ( +
  • +
    + +
    + + +
  • + ))} +
); } diff --git a/src/app/redaktion/alben/page.tsx b/src/app/redaktion/alben/page.tsx index 1f5fec1..fb13c4e 100644 --- a/src/app/redaktion/alben/page.tsx +++ b/src/app/redaktion/alben/page.tsx @@ -1,6 +1,7 @@ import { recordActivity } from "@/modules/activity/service"; import { AlbumCatalogError, albumCatalog, PHOTO_PAGE_SIZE } from "@/modules/albums/catalog"; -import { AlbumContactSheet, formatCount, PageLinks, PhotoSearchForm } from "@/modules/albums/catalog-content"; +import { UrlPagination } from "@/components/ui/url-pagination"; +import { AlbumContactSheet, formatCount, PhotoSearchForm } from "@/modules/albums/catalog-content"; import { filterPhotos, normalizeSort, paginatePhotos, sortPhotos, type InAppPage, type PhotoSort } from "@/modules/albums/filter"; import { PhotoGallery } from "@/modules/albums/photo-gallery"; import { AnnouncementBanner } from "@/modules/announcements/announcement-banner"; @@ -108,16 +109,12 @@ function SearchRateLimited({ query, format, jahr, sortierung }: { query: string; } function GlobalSearchPagination({ currentPage, page, query, format, jahr, sortierung }: { currentPage: number; page: InAppPage; query: string; format?: string; jahr?: string; sortierung: PhotoSort }) { - const hasPrev = currentPage > 1; - const hasNext = page.nextPage !== null; - if (!hasPrev && !hasNext) { - return null; - } - return ( - ); } diff --git a/src/app/redaktion/kalender/EventAccessAction.tsx b/src/app/redaktion/kalender/EventAccessAction.tsx index 0fc0e74..77e215a 100644 --- a/src/app/redaktion/kalender/EventAccessAction.tsx +++ b/src/app/redaktion/kalender/EventAccessAction.tsx @@ -1,9 +1,9 @@ "use client"; -import { useState, useTransition } from "react"; +import { useTransition } from "react"; import Link from "next/link"; import { useRouter } from "next/navigation"; -import { Badge, Button } from "@sakaniui/react"; +import { Badge, Button, toast } from "@sakaniui/react"; import type { EventAccessState } from "@/modules/calendar/service"; @@ -25,7 +25,6 @@ export function EventAccessAction({ unreserveAction: Action; }>) { const router = useRouter(); - const [state, setState] = useState({ ok: true, message: "" }); const [pending, startTransition] = useTransition(); const run = (action: Action) => { @@ -33,8 +32,12 @@ export function EventAccessAction({ formData.set("eventId", eventId); startTransition(async () => { const result = await action({ ok: true, message: "" }, formData); - setState(result); - if (result.ok) router.refresh(); + if (result.ok) { + toast.success(result.message); + router.refresh(); + } else { + toast.error(result.message); + } }); }; @@ -71,17 +74,6 @@ export function EventAccessAction({ } return ( -
-
{content}
- {state.message ? ( -

- {state.message} -

- ) : null} -
+
{content}
); } diff --git a/src/app/redaktion/leuchtkasten/DownloadLightboxForm.test.tsx b/src/app/redaktion/leuchtkasten/DownloadLightboxForm.test.tsx index c1d04f0..634b353 100644 --- a/src/app/redaktion/leuchtkasten/DownloadLightboxForm.test.tsx +++ b/src/app/redaktion/leuchtkasten/DownloadLightboxForm.test.tsx @@ -1,6 +1,6 @@ // @vitest-environment jsdom -import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react"; +import { cleanup, fireEvent, render, screen, waitFor, within } from "@testing-library/react"; import { afterEach, expect, test, vi } from "vitest"; import { DownloadLightboxForm } from "./DownloadLightboxForm"; @@ -12,33 +12,45 @@ afterEach(() => { vi.unstubAllGlobals(); }); -test("confirms new and previous uses separately and preserves the keys after a failed request", async () => { - const fetch = vi.fn().mockRejectedValue(new Error("connection lost")); - vi.stubGlobal("fetch", fetch); - render(); - fireEvent.click(screen.getByRole("button", { name: "ZIP-Download vorbereiten" })); - expect((screen.getByRole("button", { name: "ZIP herunterladen" }) as HTMLButtonElement).disabled).toBe(true); +const photos = [ + { assetId: "first", albumId: "allowed", filename: "first.jpg" }, + { assetId: "second", albumId: "allowed", filename: "second.jpg" }, +]; +const options = { + priceCents: 1500, + collabEnabled: false, + priorUsagesByAsset: { + second: [{ id: "prior", purpose: "Früherer Artikel", createdAt: "2026-11-01T12:00:00Z" }], + }, +}; + +test("books every photo as a new usage and offers a choice only for already downloaded ones", () => { + render(); + fireEvent.click(screen.getByRole("button", { name: "ZIP-Download vorbereiten" })); + + expect(screen.queryByText("Bild auslassen")).toBeNull(); + const [firstRow, secondRow] = screen.getAllByRole("listitem"); + expect(within(firstRow).queryByText("Bereits genutzt")).toBeNull(); + expect(within(secondRow).getByText("Bereits genutzt")).toBeTruthy(); - fireEvent.change(screen.getByRole("combobox", { name: "first.jpg" }), { target: { value: "new" } }); - fireEvent.change(screen.getByRole("combobox", { name: "second.jpg" }), { target: { value: "prior" } }); const submit = screen.getByRole("button", { name: "Nutzungen bestätigen und laden" }); expect(submit.disabled).toBe(true); - fireEvent.change(screen.getByLabelText("Gemeinsamer Zweck für neue Nutzungen"), { - target: { value: "Neuer Artikel" }, - }); - expect(screen.getByRole("status").textContent).toMatch(/1 neue Nutzung.*15,00/); + fireEvent.change(screen.getByLabelText("Verwendungszweck"), { target: { value: "Neuer Artikel" } }); + expect(submit.disabled).toBe(false); + expect(screen.getByRole("status").textContent).toMatch(/2 neue Nutzungen.*30,00/); +}); + +test("switching to 'Bereits genutzt' repeats the earlier usage and keeps keys after a failed request", async () => { + const fetch = vi.fn().mockRejectedValue(new Error("connection lost")); + vi.stubGlobal("fetch", fetch); + render(); + fireEvent.click(screen.getByRole("button", { name: "ZIP-Download vorbereiten" })); + + fireEvent.click(within(screen.getAllByRole("listitem")[1]).getByText("Bereits genutzt")); + fireEvent.change(screen.getByLabelText("Verwendungszweck"), { target: { value: "Neuer Artikel" } }); + expect(screen.getByRole("status").textContent).toMatch(/1 neue Nutzung.*1 kostenlos erneut.*15,00/); + + const submit = screen.getByRole("button", { name: "Nutzungen bestätigen und laden" }); fireEvent.click(submit); await waitFor(() => expect(submit.disabled).toBe(false)); fireEvent.click(submit); diff --git a/src/app/redaktion/leuchtkasten/DownloadLightboxForm.tsx b/src/app/redaktion/leuchtkasten/DownloadLightboxForm.tsx index c141e61..00a6c70 100644 --- a/src/app/redaktion/leuchtkasten/DownloadLightboxForm.tsx +++ b/src/app/redaktion/leuchtkasten/DownloadLightboxForm.tsx @@ -1,17 +1,27 @@ "use client"; +/* eslint-disable @next/next/no-img-element */ + import { useRef, useState, type FormEvent } from "react"; import { useRouter } from "next/navigation"; -import { Alert, Button, Checkbox, Input } from "@sakaniui/react"; +import { Alert, Badge, Button, Checkbox, Input, SegmentedControl, Select, toast } from "@sakaniui/react"; import { IconDownload } from "@sakaniui/react/icons"; +import { thumbnailUrl } from "@/modules/albums/catalog-content"; import { formatBerlinDate } from "@/modules/downloads/format"; import type { EditorialDownloadOptions } from "@/modules/downloads/stream"; type Photo = { assetId: string; albumId: string; filename: string }; -type Choice = { selection: string; purpose?: string }; +// Every photo is a new usage unless the editorial switches an already +// downloaded one to "Bereits genutzt" (free repeat of an earlier usage). +type Choice = { mode: "new" | "repeat"; usageId?: string; purpose?: string; ownPurpose?: boolean }; +const MAX_PHOTOS = 100; const priceFormatter = new Intl.NumberFormat("de-DE", { style: "currency", currency: "EUR" }); +const MODE_OPTIONS = [ + { value: "new", label: "Neu" }, + { value: "repeat", label: "Bereits genutzt" }, +]; export function DownloadLightboxForm({ photos, @@ -30,25 +40,24 @@ export function DownloadLightboxForm({ const intentKeys = useRef(new Map()); const router = useRouter(); - const selected = photos.filter(({ assetId }) => { - const selection = choices[assetId]?.selection; - return Boolean(selection && selection !== "skip"); - }); - const newPhotos = selected.filter(({ assetId }) => choices[assetId].selection === "new"); + const priorUsages = (assetId: string) => + [...(options.priorUsagesByAsset[assetId] ?? [])].sort((a, b) => b.createdAt.localeCompare(a.createdAt)); + const choiceFor = (assetId: string): Choice => { + const choice = choices[assetId] ?? { mode: "new" }; + if (choice.mode === "repeat" && !priorUsages(assetId).some(({ id }) => id === choice.usageId)) { + return { ...choice, usageId: priorUsages(assetId)[0]?.id }; + } + return choice; + }; + const update = (assetId: string, patch: Partial) => + setChoices((previous) => ({ ...previous, [assetId]: { ...choiceFor(assetId), ...patch } })); + const purposeFor = (choice: Choice) => (choice.ownPurpose && choice.purpose?.trim()) || commonPurpose.trim(); + + const newPhotos = photos.filter(({ assetId }) => choiceFor(assetId).mode === "new"); + const repeatCount = photos.length - newPhotos.length; + const missingPurpose = newPhotos.some(({ assetId }) => [...purposeFor(choiceFor(assetId))].length < 3); + const ready = photos.length > 0 && photos.length <= MAX_PHOTOS && !missingPurpose; const price = priceFormatter.format(options.priceCents / 100); - const ready = selected.length > 0 && selected.length <= 100 && - photos.every(({ assetId }) => currentSelection(assetId)) && - newPhotos.every(({ assetId }) => [...purposeFor(choices[assetId])].length >= 3); - - function currentSelection(assetId: string) { - const selection = choices[assetId]?.selection; - if (selection === "new" || selection === "skip") return selection; - return options.priorUsagesByAsset[assetId]?.find(({ id }) => id === selection)?.id ?? ""; - } - - function purposeFor(choice: Choice) { - return choice.purpose?.trim() || commonPurpose.trim(); - } async function handleBulkDownload(event: FormEvent) { event.preventDefault(); @@ -58,10 +67,10 @@ export function DownloadLightboxForm({ setError(null); try { - const items = selected.map(({ assetId, albumId }) => { - const choice = choices[assetId]; - const purpose = choice.selection === "new" ? purposeFor(choice) : undefined; - const key = JSON.stringify([assetId, choice.selection, purpose]); + const items = photos.map(({ assetId, albumId }) => { + const choice = choiceFor(assetId); + const purpose = choice.mode === "new" ? purposeFor(choice) : undefined; + const key = JSON.stringify([assetId, choice.mode, choice.usageId, purpose]); let idempotencyKey = intentKeys.current.get(key); if (!idempotencyKey) { idempotencyKey = crypto.randomUUID(); @@ -69,7 +78,7 @@ export function DownloadLightboxForm({ } return purpose ? { assetId, albumId, purpose, idempotencyKey } - : { assetId, usageId: choice.selection, idempotencyKey }; + : { assetId, usageId: choice.usageId, idempotencyKey }; }); const response = await fetch("/api/lightbox/bulk-download", { @@ -111,8 +120,10 @@ export function DownloadLightboxForm({ setChoices({}); setCommonPurpose(""); setCollab(false); + toast.success(`ZIP mit ${photos.length} ${photos.length === 1 ? "Bild" : "Bildern"} wird heruntergeladen.`); router.refresh(); } catch (error) { + // Stays inside the open modal: a toast would sit behind its backdrop. setError(error instanceof Error ? error.message : "Bitte versuchen Sie es erneut."); } finally { inFlight.current = false; @@ -126,82 +137,156 @@ export function DownloadLightboxForm({ ZIP-Download vorbereiten - -
-

Nutzungen für ZIP-Download

- setCommonPurpose(event.target.value)} - value={commonPurpose} - /> -
    + + +
    +

    ZIP-Download · {photos.length} {photos.length === 1 ? "Bild" : "Bilder"}

    +

    Nutzungen bestätigen

    +

    + Alle Bilder werden als neue Nutzung gebucht. Bilder, die Sie schon einmal geladen haben, können Sie + stattdessen kostenlos unter der bisherigen Nutzung erneut laden. +

    +
    + + {newPhotos.length > 0 && ( + setCommonPurpose(event.target.value)} + placeholder="z. B. Spielbericht HSV - Wolfsburg, Ausgabe 13.12." + value={commonPurpose} + /> + )} + +
      {photos.map(({ assetId, filename }) => { - const choice = choices[assetId]; + const choice = choiceFor(assetId); + const prior = priorUsages(assetId); return ( -
    • - - {choice?.selection === "new" && ( - { - const purpose = event.target.value; - setChoices((previous) => ({ ...previous, [assetId]: { selection: "new", purpose } })); - }} - value={choice.purpose ?? ""} + label="Bisherige Nutzung" + onChange={(usageId) => update(assetId, { usageId })} + options={prior.map((usage) => ({ + label: `${usage.purpose} (${formatBerlinDate(new Date(usage.createdAt))})`, + value: usage.id, + }))} + value={choice.usageId} /> )} + {choice.mode === "repeat" && prior.length === 1 && ( +

      + Kostenlos unter „{prior[0].purpose}“ erneut laden. +

      + )} + + {choice.mode === "new" && + (choice.ownPurpose ? ( + update(assetId, { purpose: event.target.value })} + value={choice.purpose ?? ""} + /> + ) : ( + + ))}
    • ); })}
    + {options.collabEnabled && newPhotos.length > 0 && ( setCollab(event.target.checked)} /> )} - {newPhotos.length > 0 && ( -

    - {newPhotos.length} neue {newPhotos.length === 1 ? "Nutzung" : "Nutzungen"} ·{" "} - {collab - ? "kostenfrei als Collab-Nutzung." - : `bis ${priceFormatter.format(newPhotos.length * options.priceCents / 100)} netto. Ein verfügbares Flatrate-Kontingent wird beim Download angerechnet.`} -

    + +
    + {newPhotos.length > 0 && ( + + {newPhotos.length} {newPhotos.length === 1 ? "neue Nutzung" : "neue Nutzungen"} + + )} + {repeatCount > 0 && {repeatCount} kostenlos erneut} + + {newPhotos.length === 0 + ? "Keine neuen Kosten." + : collab + ? "Kostenfrei als Collab-Nutzung." + : `Bis ${priceFormatter.format((newPhotos.length * options.priceCents) / 100)} netto; ein Flatrate-Kontingent wird angerechnet.`} + +
    + + {photos.length > MAX_PHOTOS && ( + )} - {selected.length > 100 && } {error && } -
    + + {missingPurpose && newPhotos.length > 0 && ( +

    Bitte einen Verwendungszweck mit mindestens 3 Zeichen angeben.

    + )} +
    -
    diff --git a/src/app/redaktion/nutzungen/page.test.tsx b/src/app/redaktion/nutzungen/page.test.tsx index d9ecbf6..abceda3 100644 --- a/src/app/redaktion/nutzungen/page.test.tsx +++ b/src/app/redaktion/nutzungen/page.test.tsx @@ -1,7 +1,9 @@ // @vitest-environment jsdom import { cleanup, render, screen } from "@testing-library/react"; -import { afterEach, expect, test } from "vitest"; +import { afterEach, expect, test, vi } from "vitest"; + +vi.mock("next/navigation", () => ({ useRouter: () => ({ push: vi.fn(), refresh: vi.fn() }) })); import { UsageHistoryContent } from "./usage-history-content"; @@ -121,9 +123,7 @@ test("renders every terminal attempt with its immutable usage snapshot", () => { expect(screen.getAllByText(/Nutzungspreis\s+15,00\s*€/)).toHaveLength(5); expect(screen.getAllByText(/15,00\s*€/)).toHaveLength(7); expect(screen.getAllByText(/0,00\s*€/)).toHaveLength(4); - expect(screen.getByRole("link", { name: /nächste nutzungsseite/i }).getAttribute("href")).toBe( - "/redaktion/nutzungen?page=2", - ); + expect(screen.getByRole("navigation", { name: "Seiten der Nutzungshistorie" })).toBeTruthy(); expect( screen.getByRole("link", { name: /neueste auslieferungen/i }).getAttribute("href"), ).toBe("/redaktion/nutzungen?page=1"); diff --git a/src/app/redaktion/nutzungen/usage-history-content.tsx b/src/app/redaktion/nutzungen/usage-history-content.tsx index 8281782..238cf20 100644 --- a/src/app/redaktion/nutzungen/usage-history-content.tsx +++ b/src/app/redaktion/nutzungen/usage-history-content.tsx @@ -3,6 +3,7 @@ import Link from "next/link"; import { Button } from "@/components/ui/button"; import { PageHeader } from "@/components/ui/page-header"; import { Badge, Card, EmptyState } from "@/components/ui/sakani"; +import { UrlPagination } from "@/components/ui/url-pagination"; import { PageLinks } from "@/modules/albums/catalog-content"; import { formatBerlinDateTime } from "@/modules/downloads/format"; @@ -125,12 +126,11 @@ function AttemptRow({ attempt }: Readonly<{ attempt: UsageHistoryAttempt }>) { function HistoryPagination({ history }: Readonly<{ history: UsageHistoryPage }>) { return ( - 1 ? `/redaktion/nutzungen?page=${history.page - 1}` : null} - prevLabel="Vorherige Nutzungsseite" - nextHref={history.hasNext ? `/redaktion/nutzungen?page=${history.page + 1}` : null} - nextLabel="Nächste Nutzungsseite" + hasNext={history.hasNext} + href={`/redaktion/nutzungen?page=${history.page}`} + page={history.page} /> ); } diff --git a/src/components/download/usage-dialog.tsx b/src/components/download/usage-dialog.tsx index a158a66..7f962df 100644 --- a/src/components/download/usage-dialog.tsx +++ b/src/components/download/usage-dialog.tsx @@ -1,7 +1,7 @@ "use client"; import { useRef, useState, type FormEvent } from "react"; -import { Alert, Button } from "@sakaniui/react"; +import { Alert, Button, toast } from "@sakaniui/react"; import { IconDownload } from "@sakaniui/react/icons"; import { formatBerlinDate } from "@/modules/downloads/format"; @@ -109,6 +109,9 @@ export function UsageDialog({ link.click(); dialogRef.current?.close(); idempotencyKeyRef.current = null; + // Errors stay inside the open modal (a toast would sit behind its + // backdrop); success is announced once the dialog is closed. + toast.success(`Download gestartet: ${filename}`); } catch { // Network failure / response not JSON — the server-code cases are // handled above; this is only a transport-level failure. diff --git a/src/components/layout/registration-steps.tsx b/src/components/layout/registration-steps.tsx new file mode 100644 index 0000000..db8b6e0 --- /dev/null +++ b/src/components/layout/registration-steps.tsx @@ -0,0 +1,23 @@ +import { Stepper } from "@/components/ui/sakani"; + +const STEPS = [ + { label: "Registrieren", description: "Firmen- und Kontaktdaten" }, + { label: "E-Mail bestätigen", description: "Link in Ihrem Postfach" }, + { label: "Freigabe", description: "Wir prüfen Ihre Angaben" }, + { label: "Loslegen", description: "Alben ansehen und laden" }, +]; + +/** Where the editorial stands in the sign-up process (0-based step). */ +export function RegistrationSteps({ current }: Readonly<{ current: 0 | 1 | 2 | 3 }>) { + return ( + + ); +} diff --git a/src/components/layout/release-notes.tsx b/src/components/layout/release-notes.tsx index cc13f21..4183e71 100644 --- a/src/components/layout/release-notes.tsx +++ b/src/components/layout/release-notes.tsx @@ -9,22 +9,21 @@ import { IconCheck } from "@sakaniui/react/icons"; // then sees the popup once more. ponytail: only the latest release is kept; // add a history list when users ask for older notes. export const RELEASE = { - version: "2.3", - title: "Kalender mit Kategorien und Vormerken", + version: "2.4", + title: "Mehrfach-Download und neuer Feinschliff", notes: { redaktion: [ - "Kalender als Monatsansicht: Termine erscheinen in der Farbe ihrer Kategorie, die Legende steht darunter.", - "Mit „Zu meinen Alben hinzufügen“ merken Sie ein Spiel vor. Ist das Album schon da, ist es sofort freigeschaltet, sonst automatisch, sobald es angelegt ist.", - "Bekommen Sie ein Album ohnehin über eine automatische Regel, steht das direkt am Termin.", - "Die Fotos in einem Album stehen jetzt in gleich großen Kacheln, zeilenweise von links nach rechts.", - "Seit 2.2: Collab-Downloads (wenn freigeschaltet), Rechnung und Nutzungsnachweis gebündelt per E-Mail, Suche auch nach Dateinamen.", + "ZIP-Download vom Merkzettel: Alle Bilder laufen als neue Nutzung. Nur bei Bildern, die Sie schon geladen haben, wählen Sie zwischen neuer Nutzung und kostenloser Wiederholung.", + "Albenübersicht mit großen Vorschaubildern, Seitenzahlen unter den Fotos und Ladeanimationen.", + "Bestätigungen und Hinweise erscheinen als kurze Meldung unten rechts.", + "Seit 2.3: Kalender als Monatsansicht mit „Zu meinen Alben hinzufügen“.", ], admin: [ - "Kategorien unter Kalender, Kategorien verwalten: Name und Farbe speichern, beim Termin auswählen.", - "Kalender als Monatsansicht mit Legende; statt Zusagen sehen Sie je Termin die Vormerkungen der Redaktionen.", - "Vorgemerkte Alben werden automatisch freigeschaltet, sobald das Album in Immich erscheint (gleicher Takt wie die Auto-Regeln).", - "Neues Dashboard: offene Aufgaben, nächste Termine, Kurzzahlen und letzte Aktivitäten.", - "Seit 2.2: Statistiken, Collab, Rechnungsversand, Abrechnung quartalsweise, Versionshistorie.", + "Speichern und Ändern bestätigt das Portal mit einer kurzen Meldung; Fehler bei Abrechnungen sind verständlich formuliert.", + "Redaktionen als Tabelle mit Suche, Statusfilter und offenen Beträgen.", + "Audit-Protokoll mit Ereignisauswahl, lesbaren Bezeichnungen und aufklappbaren Details.", + "Die Registrierung zeigt den Ablauf in Schritten: Registrieren, E-Mail bestätigen, Freigabe, Loslegen.", + "Seit 2.3: Kategorien, Monatskalender, Vormerkungen und neues Dashboard.", ], }, } as const; diff --git a/src/components/ui/feedback.tsx b/src/components/ui/feedback.tsx new file mode 100644 index 0000000..0e2551b --- /dev/null +++ b/src/components/ui/feedback.tsx @@ -0,0 +1,72 @@ +"use client"; + +import { useEffect, useRef, useTransition, type ReactNode } from "react"; +import { useRouter } from "next/navigation"; +import { Toaster, toast } from "@sakaniui/react"; + +export type ActionFeedback = { ok: boolean; message: string }; + +/** One toast stack for the whole app (mounted in the root layout). */ +export function AppToaster() { + return ; +} + +/** Shows a result as toast: success or error; nothing when there is no text. */ +export function notifyResult(result: ActionFeedback | null | undefined, successFallback?: string) { + if (!result) return; + const message = result.message || (result.ok ? successFallback : undefined); + if (!message) return; + if (result.ok) toast.success(message); + else toast.error(message); +} + +/** For useActionState: toast every new result (the initial state stays quiet). */ +export function useResultToast(state: ActionFeedback, successFallback?: string) { + const first = useRef(state); + useEffect(() => { + if (state === first.current) return; + notifyResult(state, successFallback); + }, [state, successFallback]); +} + +/** + * Form for server actions that return nothing (save, then revalidate): + * runs the action, then toasts `success` or a generic error. + */ +export function ToastForm({ + action, + success, + failure = "Das hat nicht geklappt. Bitte versuchen Sie es erneut.", + className, + children, +}: Readonly<{ + action: (formData: FormData) => Promise; + success: string; + failure?: string; + className?: string; + children: ReactNode; +}>) { + const router = useRouter(); + const [pending, startTransition] = useTransition(); + return ( + + startTransition(async () => { + try { + await action(formData); + toast.success(success); + router.refresh(); + } catch { + toast.error(failure); + } + }) + } + className={className} + > +
    + {children} +
    + + ); +} diff --git a/src/components/ui/sakani.tsx b/src/components/ui/sakani.tsx index 4ddff4b..4c1c4fc 100644 --- a/src/components/ui/sakani.tsx +++ b/src/components/ui/sakani.tsx @@ -7,7 +7,7 @@ import { useState, type ComponentProps, type ReactNode } from "react"; import { Card as SakaniCard, Select, Table, type SelectOption } from "@sakaniui/react"; -export { Alert, Badge, BarChart, Button, Checkbox, EmptyState, Input, Progress, Select, Spinner, StatCard, Textarea } from "@sakaniui/react"; +export { Alert, Badge, BarChart, Button, Checkbox, EmptyState, Input, Progress, Select, Skeleton, Spinner, StatCard, Stepper, Textarea } from "@sakaniui/react"; // Sakani's card body mutes its text (fg-muted, 14px) and stacks children with // no gap — meant for a one-line description. Our cards hold real content. diff --git a/src/components/ui/url-pagination.tsx b/src/components/ui/url-pagination.tsx new file mode 100644 index 0000000..1df6090 --- /dev/null +++ b/src/components/ui/url-pagination.tsx @@ -0,0 +1,36 @@ +"use client"; + +import { useRouter } from "next/navigation"; +import { Pagination } from "@sakaniui/react"; + +/** + * Sakani pagination driven by the URL. `href` is the current page's URL with + * every active filter; a page change swaps only `param` in it. + * ponytail: the APIs behind it report "has next page", not a page count, so + * the last known page is current + 1. Pass a real total once one exists. + */ +export function UrlPagination({ + href, + page, + hasNext, + param = "page", + ariaLabel = "Seiten", +}: Readonly<{ href: string; page: number; hasNext: boolean; param?: string; ariaLabel?: string }>) { + const router = useRouter(); + const total = hasNext ? page + 1 : page; + if (total <= 1) return null; + + return ( + + ); +} diff --git a/src/modules/albums/catalog-content.test.tsx b/src/modules/albums/catalog-content.test.tsx index fa55b5b..4c58ad3 100644 --- a/src/modules/albums/catalog-content.test.tsx +++ b/src/modules/albums/catalog-content.test.tsx @@ -26,9 +26,9 @@ test("renders granted albums as labelled contact-sheet links", () => { const album = screen.getByRole("link", { name: /heimspiel gegen nord/i }); expect(album.getAttribute("href")).toBe("/redaktion/alben/heimspiel"); expect(screen.getByText("24 Fotos")).not.toBeNull(); - expect(screen.getByAltText("Titelbild: Heimspiel gegen Nord").getAttribute("src")).toBe( - "/api/assets/cover-1/thumbnail", - ); + // The cover is decorative: the title in the same link names it. + expect(album.querySelector("img")?.getAttribute("src")).toBe("/api/assets/cover-1/thumbnail"); + expect(album.querySelector("img")?.getAttribute("alt")).toBe(""); }); const photo = { diff --git a/src/modules/albums/catalog-content.tsx b/src/modules/albums/catalog-content.tsx index 4fcb635..df29f7d 100644 --- a/src/modules/albums/catalog-content.tsx +++ b/src/modules/albums/catalog-content.tsx @@ -4,44 +4,52 @@ import Link from "next/link"; import { IconSearch } from "@sakaniui/react/icons"; import { Button } from "@/components/ui/button"; -import { Card, FormSelect, Input } from "@/components/ui/sakani"; +import { Card, FormSelect, Input, Skeleton } from "@/components/ui/sakani"; +import { UrlPagination } from "@/components/ui/url-pagination"; import type { ImmichSearchPage } from "@/modules/immich/types"; import type { VisibleAlbum } from "./catalog"; +// Blog-listing look: borderless 3:2 cover on top, count and title below. +// A skeleton sits behind each cover until the image has loaded. export function AlbumContactSheet({ albums }: Readonly<{ albums: VisibleAlbum[] }>) { return ( -
      +
        {albums.map((album) => (
      • - -
        - {album.albumThumbnailAssetId ? ( +
        + {album.albumThumbnailAssetId ? ( + <> + {/* Sakani's CSS outranks Tailwind on its own root, so the wrapper positions it. */} + {`Titelbild: - ) : ( -
        - Kein Titelbild -
        - )} -
        - {album.albumName} - {formatCount(album.assetCount, "Foto")} -
        -
        -
        + + ) : ( + Kein Titelbild + )} +
    +
    + + {formatCount(album.assetCount, "Foto")} + +

    + {album.albumName} +

    + {album.description ? ( +

    {album.description}

    + ) : null} +
    ))} @@ -49,7 +57,7 @@ export function AlbumContactSheet({ albums }: Readonly<{ albums: VisibleAlbum[] ); } -// Server-rendered pagination. Links thread every active filter (suche, +// Sakani pagination. The page URL threads every active filter (suche, // format, jahr) so flipping pages does not silently drop them — that was the // old bug: pageHref only carried `suche`, so "Nächste Seite" reset format/jahr. export function PhotoPagination({ @@ -69,13 +77,14 @@ export function PhotoPagination({ jahr?: string; sortierung?: string; }>) { - const hasPrev = currentPage > 1; - const hasNext = page.nextPage !== null; - if (!hasPrev && !hasNext) { - return null; - } - - return ; + return ( + + ); } // Server-rendered prev/next links (album search, usage history, …). diff --git a/src/modules/albums/photo-gallery.tsx b/src/modules/albums/photo-gallery.tsx index 957ea8e..dddb392 100644 --- a/src/modules/albums/photo-gallery.tsx +++ b/src/modules/albums/photo-gallery.tsx @@ -3,7 +3,7 @@ /* eslint-disable @next/next/no-img-element */ import { useEffect, useState } from "react"; -import { EmptyState, IconButton } from "@sakaniui/react"; +import { EmptyState, IconButton, Skeleton } from "@sakaniui/react"; import { IconChevronLeft, IconChevronRight, IconX } from "@sakaniui/react/icons"; import { UsageDialog } from "@/components/download/usage-dialog"; @@ -91,6 +91,9 @@ export function PhotoGallery({ onClick={() => setOpenIndex(index)} aria-label={`${asset.filename} vergrößern`} > + {asset.filename}( approveEditorialAction.bind(null, editorialId), { ok: true, message: "" } ); + useResultToast(state, "Redaktion freigegeben."); return (
    @@ -28,7 +30,6 @@ export function ApproveForm({ editorialId }: { editorialId: string }) { - {!state.ok && } ); } diff --git a/src/modules/editorials/DangerZone.tsx b/src/modules/editorials/DangerZone.tsx index e7ec894..0017f35 100644 --- a/src/modules/editorials/DangerZone.tsx +++ b/src/modules/editorials/DangerZone.tsx @@ -4,8 +4,9 @@ import { useState, useTransition } from "react"; import { archiveEditorialAction, hardDeleteEditorialAction } from "@/app/admin/redaktionen/[id]/actions"; import { Card, CardHeader, CardTitle, CardDescription, CardContent } from "@/components/ui/card"; -import { Alert, Input } from "@/components/ui/sakani"; +import { Input } from "@/components/ui/sakani"; import { Button } from "@/components/ui/button"; +import { notifyResult } from "@/components/ui/feedback"; type DangerZoneProps = { editorialId: string; @@ -16,7 +17,6 @@ export function DangerZone({ editorialId, editorialName }: DangerZoneProps) { const [confirmText, setConfirmText] = useState(""); const [isPending, startTransition] = useTransition(); const [isDeleting, setIsDeleting] = useState(false); - const [result, setResult] = useState<{ ok: boolean; message: string } | null>(null); const isConfirmed = confirmText === editorialName; function handleArchive() { @@ -25,7 +25,7 @@ export function DangerZone({ editorialId, editorialName }: DangerZoneProps) { try { await archiveEditorialAction(editorialId); } catch { - setResult({ ok: false, message: "Das Archivieren ist fehlgeschlagen." }); + notifyResult({ ok: false, message: "Das Archivieren ist fehlgeschlagen." }); } }); } @@ -36,7 +36,7 @@ export function DangerZone({ editorialId, editorialName }: DangerZoneProps) { startTransition(async () => { const actionResult = await hardDeleteEditorialAction(editorialId); // On success the action redirects; anything returned here is a failure. - setResult(actionResult); + notifyResult(actionResult); setIsDeleting(false); }); } @@ -77,7 +77,6 @@ export function DangerZone({ editorialId, editorialName }: DangerZoneProps) { {isDeleting ? "Wird gelöscht…" : "Endgültig löschen"}
- {result && !result.ok && } ); diff --git a/src/modules/editorials/ResetUsageCard.tsx b/src/modules/editorials/ResetUsageCard.tsx index 5eadf0a..ee1a8e7 100644 --- a/src/modules/editorials/ResetUsageCard.tsx +++ b/src/modules/editorials/ResetUsageCard.tsx @@ -4,8 +4,9 @@ import { useState, useTransition } from "react"; import { resetUsageDataAction } from "@/app/admin/redaktionen/[id]/actions"; import { Card, CardHeader, CardTitle, CardDescription, CardContent } from "@/components/ui/card"; -import { Alert, Input } from "@/components/ui/sakani"; +import { Input } from "@/components/ui/sakani"; import { Button } from "@/components/ui/button"; +import { notifyResult } from "@/components/ui/feedback"; type ResetUsageCardProps = { editorialId: string; @@ -15,14 +16,13 @@ type ResetUsageCardProps = { export function ResetUsageCard({ editorialId, editorialName }: ResetUsageCardProps) { const [confirmText, setConfirmText] = useState(""); const [isPending, startTransition] = useTransition(); - const [result, setResult] = useState<{ ok: boolean; message: string } | null>(null); const isConfirmed = confirmText === editorialName; function handleReset() { if (!isConfirmed || isPending) return; startTransition(async () => { const actionResult = await resetUsageDataAction(editorialId); - setResult(actionResult); + notifyResult(actionResult); if (actionResult.ok) { setConfirmText(""); } @@ -57,7 +57,6 @@ export function ResetUsageCard({ editorialId, editorialName }: ResetUsageCardPro > {isPending ? "Wird zurückgesetzt…" : "Nutzungsdaten zurücksetzen"} - {result && }
diff --git a/src/modules/editorials/admin-detail.tsx b/src/modules/editorials/admin-detail.tsx index b42250e..95f1ca8 100644 --- a/src/modules/editorials/admin-detail.tsx +++ b/src/modules/editorials/admin-detail.tsx @@ -7,6 +7,7 @@ import { archiveEditorialAction, unarchiveEditorialAction, suspendEditorialActio import { DangerZone } from "./DangerZone"; import { ResetUsageCard } from "./ResetUsageCard"; import { ApproveForm } from "./ApproveForm"; +import { ToastForm } from "@/components/ui/feedback"; export type EditorialDetail = { id: string; @@ -51,11 +52,11 @@ export function EditorialDetailContent({ -
+ - +
@@ -130,7 +131,7 @@ export function EditorialDetailContent({ Pauschalpreis für Downloads aktivieren. -
+ - +
)} @@ -179,7 +180,7 @@ export function EditorialDetailContent({ -
+ - +
)} @@ -201,18 +202,18 @@ export function EditorialDetailContent({ {editorial.status === 'active' && ( -
+ - +
)} {editorial.status === 'suspended' && ( -
+ - +
)}