Compare commits
11 Commits
todo/mvp1-
...
todo/mvp1-
| Author | SHA1 | Date | |
|---|---|---|---|
|
60c9035743
|
|||
|
741883465c
|
|||
|
7a82934fe7
|
|||
|
473433b220
|
|||
|
987843d96b
|
|||
|
c6ebf3759a
|
|||
|
81983cfe40
|
|||
|
697b3ab5e7
|
|||
|
984511f166
|
|||
|
b9424c8a8b
|
|||
|
6e9c0ad4e5
|
90
TODO.md
90
TODO.md
@@ -118,7 +118,7 @@ This file is the single source of truth for roadmap and delivery progress.
|
|||||||
page CRUD, navigation tree, reusable page blocks (forms/price cards/gallery embeds)
|
page CRUD, navigation tree, reusable page blocks (forms/price cards/gallery embeds)
|
||||||
- [~] [P1] `todo/mvp1-commissions-customers`:
|
- [~] [P1] `todo/mvp1-commissions-customers`:
|
||||||
commission request intake + admin CRUD + kanban + customer entity/linking
|
commission request intake + admin CRUD + kanban + customer entity/linking
|
||||||
- [~] [P1] `todo/mvp1-announcements-news`:
|
- [x] [P1] `todo/mvp1-announcements-news`:
|
||||||
announcement management/rendering + news/blog CRUD and public rendering
|
announcement management/rendering + news/blog CRUD and public rendering
|
||||||
- [~] [P1] `todo/mvp1-public-rendering-integration`:
|
- [~] [P1] `todo/mvp1-public-rendering-integration`:
|
||||||
public rendering for pages/navigation/media/portfolio/announcements and commissioning entrypoints
|
public rendering for pages/navigation/media/portfolio/announcements and commissioning entrypoints
|
||||||
@@ -137,23 +137,23 @@ This file is the single source of truth for roadmap and delivery progress.
|
|||||||
### Admin App (Primary Focus)
|
### Admin App (Primary Focus)
|
||||||
|
|
||||||
- [~] [P1] Page management (create/edit/publish/unpublish/schedule)
|
- [~] [P1] Page management (create/edit/publish/unpublish/schedule)
|
||||||
- [ ] [P1] Page builder with reusable content blocks (hero, rich text, gallery, CTA, forms, price cards)
|
- [x] [P1] Page builder with reusable content blocks (hero, rich text, gallery, CTA, forms, price cards)
|
||||||
- [~] [P1] Navigation management (menus, nested items, order, visibility)
|
- [x] [P1] Navigation management (menus, nested items, order, visibility)
|
||||||
- [~] [P1] Media library (upload, browse, replace, delete) with media-type classification (artwork, banner, promo, generic, video/gif)
|
- [~] [P1] Media library (upload, browse, replace, delete) with media-type classification (artwork, banner, promo, generic, video/gif)
|
||||||
- [ ] [P1] Media enrichment metadata (alt text, copyright, author, source, tags, licensing, usage context)
|
- [x] [P1] Media enrichment metadata (alt text, copyright, author, source, tags, licensing, usage context)
|
||||||
- [ ] [P1] Portfolio grouping primitives (galleries, albums, categories, tags) with ordering/visibility controls
|
- [x] [P1] Portfolio grouping primitives (galleries, albums, categories, tags) with ordering/visibility controls
|
||||||
- [ ] [P1] Artwork refinement fields (medium, dimensions, year, framing, availability, price visibility)
|
- [x] [P1] Artwork refinement fields (medium, dimensions, year, framing, availability, price visibility)
|
||||||
- [ ] [P1] Artwork rendition management (thumbnail, card, full, retina/custom sizes)
|
- [x] [P1] Artwork rendition management (thumbnail, card, full, retina/custom sizes)
|
||||||
- [ ] [P1] Type-specific processing presets (artwork/banner/promo/video/gif) with validation rules
|
- [x] [P1] Type-specific processing presets (artwork/banner/promo/video/gif) with validation rules
|
||||||
- [ ] [P1] Users management (invite, roles, status)
|
- [x] [P1] Users management (invite, roles, status)
|
||||||
- [ ] [P1] Disable/ban user function and enforcement in auth/session checks
|
- [x] [P1] Disable/ban user function and enforcement in auth/session checks
|
||||||
- [~] [P1] Owner/support protection rules in user management actions (cannot delete/demote)
|
- [x] [P1] Owner/support protection rules in user management actions (cannot delete/demote)
|
||||||
- [~] [P1] Commissions management (request intake, owner, due date, notes, linked customer, linked artworks)
|
- [x] [P1] Commissions management (request intake, owner, due date, notes, linked customer, linked artworks)
|
||||||
- [~] [P1] Customer records (contact profile, notes, consent flags, recurrence marker)
|
- [x] [P1] Customer records (contact profile, notes, consent flags, recurrence marker)
|
||||||
- [~] [P1] Customer-to-commission linkage and reuse workflow (no re-entry for recurring customers)
|
- [x] [P1] Customer-to-commission linkage and reuse workflow (no re-entry for recurring customers)
|
||||||
- [~] [P1] Kanban workflow for commissions (new, scoped, in-progress, review, done)
|
- [x] [P1] Kanban workflow for commissions (new, scoped, in-progress, review, done)
|
||||||
- [x] [P1] Header banner management (message, CTA, active window)
|
- [x] [P1] Header banner management (message, CTA, active window)
|
||||||
- [~] [P1] Announcements management (prominent site notices with schedule, priority, and audience targeting)
|
- [x] [P1] Announcements management (prominent site notices with schedule, priority, and audience targeting)
|
||||||
- [~] [P2] News/blog editorial workflow (draft/review/publish, authoring metadata)
|
- [~] [P2] News/blog editorial workflow (draft/review/publish, authoring metadata)
|
||||||
|
|
||||||
### Public App
|
### Public App
|
||||||
@@ -171,9 +171,9 @@ This file is the single source of truth for roadmap and delivery progress.
|
|||||||
|
|
||||||
### News / Blog (Secondary Track)
|
### News / Blog (Secondary Track)
|
||||||
|
|
||||||
- [~] [P1] News/blog content type (editorial content for artist updates and process posts)
|
- [x] [P1] News/blog content type (editorial content for artist updates and process posts)
|
||||||
- [~] [P1] Admin list/editor for news posts
|
- [x] [P1] Admin list/editor for news posts
|
||||||
- [~] [P1] Public news index + detail pages
|
- [x] [P1] Public news index + detail pages
|
||||||
- [ ] [P2] Tag/category and basic archive support
|
- [ ] [P2] Tag/category and basic archive support
|
||||||
|
|
||||||
### Testing
|
### Testing
|
||||||
@@ -190,21 +190,39 @@ This file is the single source of truth for roadmap and delivery progress.
|
|||||||
- [ ] [P2] Add code-level diagrams (Mermaid) for service boundaries and data relationships
|
- [ ] [P2] Add code-level diagrams (Mermaid) for service boundaries and data relationships
|
||||||
- [ ] [P2] Add route/action inventory for admin and public apps with linked source files
|
- [ ] [P2] Add route/action inventory for admin and public apps with linked source files
|
||||||
|
|
||||||
## MVP 1.5: UX/UI And Theming
|
## MVP 1.5: MVP1 Refinements (Planned)
|
||||||
|
|
||||||
### MVP1.5 Suggested Branch Order
|
### Scope
|
||||||
|
|
||||||
- [ ] [P1] `todo/mvp15-design-tokens-foundation`:
|
- [ ] [P1] Refine and harden all completed MVP1 modules (pages, navigation, media, portfolio, commissions, news)
|
||||||
|
- [ ] [P1] Resolve UX rough edges discovered during MVP1 implementation
|
||||||
|
- [ ] [P1] Improve admin workflows and reduce editor friction for daily use
|
||||||
|
- [ ] [P1] Stabilize public rendering behavior with better fallbacks and consistency
|
||||||
|
|
||||||
|
## MVP 2: MVP1 Quality Refinements (Planned)
|
||||||
|
|
||||||
|
### Scope
|
||||||
|
|
||||||
|
- [ ] [P1] Finish non-blocking enhancements postponed from MVP1 implementation
|
||||||
|
- [ ] [P1] Improve data modeling consistency and migration hygiene for MVP1 modules
|
||||||
|
- [ ] [P1] Consolidate reusable UI and domain primitives introduced during MVP1
|
||||||
|
- [ ] [P1] Address integration debt before moving to larger design/production phases
|
||||||
|
|
||||||
|
## MVP 3: UX/UI And Theming
|
||||||
|
|
||||||
|
### MVP3 Suggested Branch Order
|
||||||
|
|
||||||
|
- [ ] [P1] `todo/mvp3-design-tokens-foundation`:
|
||||||
establish shared design tokens (color, spacing, radius, typography scale, motion) in `@cms/ui` and app-level theme contracts
|
establish shared design tokens (color, spacing, radius, typography scale, motion) in `@cms/ui` and app-level theme contracts
|
||||||
- [ ] [P1] `todo/mvp15-admin-layout-polish`:
|
- [ ] [P1] `todo/mvp3-admin-layout-polish`:
|
||||||
refine admin shell, navigation hierarchy, spacing rhythm, table/form visual consistency, empty/loading/error states
|
refine admin shell, navigation hierarchy, spacing rhythm, table/form visual consistency, empty/loading/error states
|
||||||
- [ ] [P1] `todo/mvp15-public-layout-and-templates`:
|
- [ ] [P1] `todo/mvp3-public-layout-and-templates`:
|
||||||
define public visual direction (hero/header/footer/content widths), page templates for home/content/news/portfolio
|
define public visual direction (hero/header/footer/content widths), page templates for home/content/news/portfolio
|
||||||
- [ ] [P2] `todo/mvp15-component-library-pass`:
|
- [ ] [P2] `todo/mvp3-component-library-pass`:
|
||||||
align shadcn-based primitives with CMS brand system (buttons, inputs, cards, badges, tabs, dialogs, toasts)
|
align shadcn-based primitives with CMS brand system (buttons, inputs, cards, badges, tabs, dialogs, toasts)
|
||||||
- [ ] [P2] `todo/mvp15-responsive-and-a11y-pass`:
|
- [ ] [P2] `todo/mvp3-responsive-and-a11y-pass`:
|
||||||
mobile/tablet breakpoints, keyboard flow, focus states, contrast checks, reduced-motion support
|
mobile/tablet breakpoints, keyboard flow, focus states, contrast checks, reduced-motion support
|
||||||
- [ ] [P2] `todo/mvp15-visual-regression-baseline`:
|
- [ ] [P2] `todo/mvp3-visual-regression-baseline`:
|
||||||
add screenshot baselines for critical admin/public routes to guard layout regressions
|
add screenshot baselines for critical admin/public routes to guard layout regressions
|
||||||
|
|
||||||
### Deliverables
|
### Deliverables
|
||||||
@@ -214,7 +232,7 @@ This file is the single source of truth for roadmap and delivery progress.
|
|||||||
- [ ] [P2] Shared UI primitives are consistent across admin and public apps
|
- [ ] [P2] Shared UI primitives are consistent across admin and public apps
|
||||||
- [ ] [P2] Core routes have visual-regression coverage for the new layout baseline
|
- [ ] [P2] Core routes have visual-regression coverage for the new layout baseline
|
||||||
|
|
||||||
## MVP 2: Production Readiness
|
## MVP 4: Production Readiness
|
||||||
|
|
||||||
### Admin App
|
### Admin App
|
||||||
|
|
||||||
@@ -253,9 +271,9 @@ This file is the single source of truth for roadmap and delivery progress.
|
|||||||
|
|
||||||
### Testing
|
### Testing
|
||||||
|
|
||||||
- [~] [P1] Testing workstream moved to `MVP 3: Testing and Quality` and temporarily paused to prioritize feature delivery
|
- [~] [P1] Testing workstream moved to `MVP 5: Testing and Quality` and temporarily paused to prioritize feature delivery
|
||||||
|
|
||||||
## MVP 3: Testing and Quality
|
## MVP 5: Testing and Quality
|
||||||
|
|
||||||
### Status
|
### Status
|
||||||
|
|
||||||
@@ -316,7 +334,7 @@ This file is the single source of truth for roadmap and delivery progress.
|
|||||||
- [2026-02-11] Release workflow now publishes changelog-derived notes to Gitea releases and supports executable production rollback via SSH + compose tag switch.
|
- [2026-02-11] Release workflow now publishes changelog-derived notes to Gitea releases and supports executable production rollback via SSH + compose tag switch.
|
||||||
- [2026-02-11] Branch protection verification checklist is now documented; final UI-level verification remains environment-specific.
|
- [2026-02-11] Branch protection verification checklist is now documented; final UI-level verification remains environment-specific.
|
||||||
- [2026-02-11] Added a staging deployment execution checklist and deployment-record template to capture first real-host rollout evidence.
|
- [2026-02-11] Added a staging deployment execution checklist and deployment-record template to capture first real-host rollout evidence.
|
||||||
- [2026-02-11] Artist-focused feature map refined: MVP1 covers portfolio media/domain CRUD + announcements + customer/commission linking; MVP2 covers advanced automation (watermark, palette extraction, media transform pipelines).
|
- [2026-02-11] Artist-focused feature map refined: MVP1 covers portfolio media/domain CRUD + announcements + customer/commission linking; MVP4 covers advanced automation (watermark, palette extraction, media transform pipelines).
|
||||||
- [2026-02-11] `gaertan` inspiration to reuse: S3 object strategy with signed delivery, commission type/options/extras/custom-input modeling, request-status kanban mapping, and gallery rendition/color extraction patterns.
|
- [2026-02-11] `gaertan` inspiration to reuse: S3 object strategy with signed delivery, commission type/options/extras/custom-input modeling, request-status kanban mapping, and gallery rendition/color extraction patterns.
|
||||||
- [2026-02-11] MVP1 media foundation started: portfolio domain models (`MediaAsset`, `Artwork`, galleries/albums/categories/tags, rendition links) plus initial admin `/media` and `/portfolio` data views.
|
- [2026-02-11] MVP1 media foundation started: portfolio domain models (`MediaAsset`, `Artwork`, galleries/albums/categories/tags, rendition links) plus initial admin `/media` and `/portfolio` data views.
|
||||||
- [2026-02-11] `prisma migrate dev --name media_foundation` can fail when DB endpoint is unreachable; apply this named migration once `DATABASE_URL` host is reachable again.
|
- [2026-02-11] `prisma migrate dev --name media_foundation` can fail when DB endpoint is unreachable; apply this named migration once `DATABASE_URL` host is reachable again.
|
||||||
@@ -325,6 +343,7 @@ This file is the single source of truth for roadmap and delivery progress.
|
|||||||
- [2026-02-12] Upload storage is now provider-based (`local` + `s3`) via `CMS_MEDIA_STORAGE_PROVIDER`; admin-side GUI toggle remains a later MVP item.
|
- [2026-02-12] Upload storage is now provider-based (`local` + `s3`) via `CMS_MEDIA_STORAGE_PROVIDER`; admin-side GUI toggle remains a later MVP item.
|
||||||
- [2026-02-12] Media storage keys now use asset-centric layout (`tenant/<id>/asset/<assetId>/<fileRole>/<assetId>__<variant>.<ext>`) with DB-managed media taxonomy.
|
- [2026-02-12] Media storage keys now use asset-centric layout (`tenant/<id>/asset/<assetId>/<fileRole>/<assetId>__<variant>.<ext>`) with DB-managed media taxonomy.
|
||||||
- [2026-02-12] Admin media CRUD now includes list-to-detail flow (`/media/:id`) with metadata edit and delete actions.
|
- [2026-02-12] Admin media CRUD now includes list-to-detail flow (`/media/:id`) with metadata edit and delete actions.
|
||||||
|
- [2026-02-12] Media enrichment metadata baseline completed: `MediaAsset` now supports licensing/usage/location/captured-at fields across upload input, admin editor, and public artwork detail rendering.
|
||||||
- [2026-02-12] MVP1 pages/navigation baseline started: `Page`, `NavigationMenu`, and `NavigationItem` models plus admin CRUD routes (`/pages`, `/pages/:id`, `/navigation`).
|
- [2026-02-12] MVP1 pages/navigation baseline started: `Page`, `NavigationMenu`, and `NavigationItem` models plus admin CRUD routes (`/pages`, `/pages/:id`, `/navigation`).
|
||||||
- [2026-02-12] Public app now renders CMS-managed navigation (header) and CMS-managed pages by slug (including homepage when `home` page exists).
|
- [2026-02-12] Public app now renders CMS-managed navigation (header) and CMS-managed pages by slug (including homepage when `home` page exists).
|
||||||
- [2026-02-12] Commissions/customer baseline added: admin `/commissions` now supports customer creation, commission intake, status transitions, and a basic kanban board.
|
- [2026-02-12] Commissions/customer baseline added: admin `/commissions` now supports customer creation, commission intake, status transitions, and a basic kanban board.
|
||||||
@@ -342,6 +361,15 @@ This file is the single source of truth for roadmap and delivery progress.
|
|||||||
- [2026-02-12] Page editor now supports locale translations in `/pages/:id`; public page rendering uses locale-aware page lookup with base-content fallback.
|
- [2026-02-12] Page editor now supports locale translations in `/pages/:id`; public page rendering uses locale-aware page lookup with base-content fallback.
|
||||||
- [2026-02-12] Public rendering integration advanced with locale-aware navigation/news translations and a new public commission request entry route (`/[locale]/commissions`) that creates/reuses customer records and opens a `new` commission.
|
- [2026-02-12] Public rendering integration advanced with locale-aware navigation/news translations and a new public commission request entry route (`/[locale]/commissions`) that creates/reuses customer records and opens a `new` commission.
|
||||||
- [2026-02-12] Public portfolio baseline added with `/{locale}/portfolio` and `/{locale}/portfolio/{slug}`, including published-artwork filters (gallery/album/category/tag), rendition image streaming via web `/api/media/file/:id`, and media-aware artwork detail rendering.
|
- [2026-02-12] Public portfolio baseline added with `/{locale}/portfolio` and `/{locale}/portfolio/{slug}`, including published-artwork filters (gallery/album/category/tag), rendition image streaming via web `/api/media/file/:id`, and media-aware artwork detail rendering.
|
||||||
|
- [2026-02-12] Portfolio grouping controls completed in admin `/portfolio`: galleries/albums/categories/tags now support visibility and sort-order management (create/update/delete), and public tag filters now respect visibility.
|
||||||
|
- [2026-02-12] Artwork refinement baseline completed: admin `/portfolio` now captures/edits medium, dimensions, year, framing, availability, publish state, and optional price visibility (`priceAmountCents` + `priceCurrency`), with public artwork detail rendering visible prices only.
|
||||||
|
- [2026-02-12] Artwork rendition management completed: admin `/portfolio` supports `thumbnail/card/full/retina/custom` slot assignment with dimensions and primary flag, plus per-artwork rendition listing and delete controls.
|
||||||
|
- [2026-02-12] Media type presets baseline completed in upload API: server-side validation now uses shared per-type rules (mime + max size) for `artwork/banner/promotion/video/gif/generic`, with optional env cap override via `CMS_MEDIA_UPLOAD_MAX_BYTES`.
|
||||||
|
- [2026-02-12] Page builder reusable blocks completed: admin block editor now supports full field editing + ordering controls for hero/rich-text/gallery/cta/form/price-cards; public renderer includes form-link behavior for `contact`/`commission` keys.
|
||||||
|
- [2026-02-12] Navigation management completed: admin `/navigation` now supports menu update/delete controls, nested item parent selection via menu-local dropdown, and full order/visibility updates across menus and items.
|
||||||
|
- [2026-02-12] Users management baseline completed: admin `/users` now supports managed user creation, role changes (`admin/editor/manager`), status changes (ban/unban), and protected/system guardrails for role-change/delete/ban actions.
|
||||||
|
- [2026-02-12] Commissions management completed: admin kanban cards now include inline detail editing (assignee/customer/budget/due date/notes), linked-artwork references via `linkedArtworkIds`, and creation/edit flows use assignable users instead of raw ID entry.
|
||||||
|
- [2026-02-12] Announcements/news completed: announcements now support locale audience targeting (`targetLocales`) with public locale-aware rendering, and homepage news list now uses locale-aware published posts only.
|
||||||
- [2026-02-12] Public UX pass: commission request flow now reports explicit invalid budget range errors, and header navigation now falls back to localized defaults (`home`, `portfolio`, `news`, `commissions`) when no CMS menu exists; seed data now creates those default menu entries.
|
- [2026-02-12] Public UX pass: commission request flow now reports explicit invalid budget range errors, and header navigation now falls back to localized defaults (`home`, `portfolio`, `news`, `commissions`) when no CMS menu exists; seed data now creates those default menu entries.
|
||||||
- [2026-02-12] Added `e2e/public-rendering.pw.ts` web coverage for fallback navigation visibility, portfolio routes, and commission submission validation (invalid budget range + successful submission path).
|
- [2026-02-12] Added `e2e/public-rendering.pw.ts` web coverage for fallback navigation visibility, portfolio routes, and commission submission validation (invalid budget range + successful submission path).
|
||||||
- [2026-02-12] Testing execution is temporarily paused for delivery velocity: root test scripts are stubbed and CI test steps are disabled; all testing backlog is consolidated under `MVP 3: Testing and Quality`.
|
- [2026-02-12] Testing execution is temporarily paused for delivery velocity: root test scripts are stubbed and CI test steps are disabled; all testing backlog is consolidated under `MVP 3: Testing and Quality`.
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import { requirePermissionForRoute } from "@/lib/route-guards"
|
|||||||
export const dynamic = "force-dynamic"
|
export const dynamic = "force-dynamic"
|
||||||
|
|
||||||
type SearchParamsInput = Record<string, string | string[] | undefined>
|
type SearchParamsInput = Record<string, string | string[] | undefined>
|
||||||
|
const SUPPORTED_LOCALES = ["de", "en", "es", "fr"] as const
|
||||||
|
|
||||||
function readFirstValue(value: string | string[] | undefined): string | null {
|
function readFirstValue(value: string | string[] | undefined): string | null {
|
||||||
if (Array.isArray(value)) {
|
if (Array.isArray(value)) {
|
||||||
@@ -49,6 +50,22 @@ function readNullableDate(formData: FormData, field: string): Date | null {
|
|||||||
return parsed
|
return parsed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function readLocaleSelections(formData: FormData, field: string): string[] {
|
||||||
|
const values = formData.getAll(field)
|
||||||
|
const locales = new Set<string>()
|
||||||
|
|
||||||
|
for (const value of values) {
|
||||||
|
if (
|
||||||
|
typeof value === "string" &&
|
||||||
|
SUPPORTED_LOCALES.includes(value as (typeof SUPPORTED_LOCALES)[number])
|
||||||
|
) {
|
||||||
|
locales.add(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Array.from(locales)
|
||||||
|
}
|
||||||
|
|
||||||
function readInt(formData: FormData, field: string, fallback = 100): number {
|
function readInt(formData: FormData, field: string, fallback = 100): number {
|
||||||
const value = readInputString(formData, field)
|
const value = readInputString(formData, field)
|
||||||
|
|
||||||
@@ -94,6 +111,7 @@ async function createAnnouncementAction(formData: FormData) {
|
|||||||
title: readInputString(formData, "title"),
|
title: readInputString(formData, "title"),
|
||||||
message: readInputString(formData, "message"),
|
message: readInputString(formData, "message"),
|
||||||
placement: readInputString(formData, "placement"),
|
placement: readInputString(formData, "placement"),
|
||||||
|
targetLocales: readLocaleSelections(formData, "targetLocales"),
|
||||||
priority: readInt(formData, "priority", 100),
|
priority: readInt(formData, "priority", 100),
|
||||||
ctaLabel: readNullableString(formData, "ctaLabel"),
|
ctaLabel: readNullableString(formData, "ctaLabel"),
|
||||||
ctaHref: readNullableString(formData, "ctaHref"),
|
ctaHref: readNullableString(formData, "ctaHref"),
|
||||||
@@ -125,6 +143,7 @@ async function updateAnnouncementAction(formData: FormData) {
|
|||||||
title: readInputString(formData, "title"),
|
title: readInputString(formData, "title"),
|
||||||
message: readInputString(formData, "message"),
|
message: readInputString(formData, "message"),
|
||||||
placement: readInputString(formData, "placement"),
|
placement: readInputString(formData, "placement"),
|
||||||
|
targetLocales: readLocaleSelections(formData, "targetLocales"),
|
||||||
priority: readInt(formData, "priority", 100),
|
priority: readInt(formData, "priority", 100),
|
||||||
ctaLabel: readNullableString(formData, "ctaLabel"),
|
ctaLabel: readNullableString(formData, "ctaLabel"),
|
||||||
ctaHref: readNullableString(formData, "ctaHref"),
|
ctaHref: readNullableString(formData, "ctaHref"),
|
||||||
@@ -277,6 +296,20 @@ export default async function AnnouncementsPage({
|
|||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="space-y-1">
|
||||||
|
<p className="text-xs text-neutral-600">Target locales (empty = all locales)</p>
|
||||||
|
<div className="flex flex-wrap gap-3">
|
||||||
|
{SUPPORTED_LOCALES.map((locale) => (
|
||||||
|
<label
|
||||||
|
key={`create-locale-${locale}`}
|
||||||
|
className="inline-flex items-center gap-2 text-sm"
|
||||||
|
>
|
||||||
|
<input name="targetLocales" type="checkbox" value={locale} className="size-4" />
|
||||||
|
{locale.toUpperCase()}
|
||||||
|
</label>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div className="grid gap-3 md:grid-cols-2">
|
<div className="grid gap-3 md:grid-cols-2">
|
||||||
<label className="space-y-1">
|
<label className="space-y-1">
|
||||||
<span className="text-xs text-neutral-600">Starts at</span>
|
<span className="text-xs text-neutral-600">Starts at</span>
|
||||||
@@ -390,6 +423,26 @@ export default async function AnnouncementsPage({
|
|||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="mt-3 space-y-1">
|
||||||
|
<p className="text-xs text-neutral-600">Target locales (empty = all locales)</p>
|
||||||
|
<div className="flex flex-wrap gap-3">
|
||||||
|
{SUPPORTED_LOCALES.map((locale) => (
|
||||||
|
<label
|
||||||
|
key={`${announcement.id}-locale-${locale}`}
|
||||||
|
className="inline-flex items-center gap-2 text-sm"
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
name="targetLocales"
|
||||||
|
type="checkbox"
|
||||||
|
value={locale}
|
||||||
|
defaultChecked={announcement.targetLocales.includes(locale)}
|
||||||
|
className="size-4"
|
||||||
|
/>
|
||||||
|
{locale.toUpperCase()}
|
||||||
|
</label>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div className="mt-3 flex flex-wrap items-center justify-between gap-3">
|
<div className="mt-3 flex flex-wrap items-center justify-between gap-3">
|
||||||
<label className="inline-flex items-center gap-2 text-sm text-neutral-700">
|
<label className="inline-flex items-center gap-2 text-sm text-neutral-700">
|
||||||
<input
|
<input
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
import { randomUUID } from "node:crypto"
|
import { randomUUID } from "node:crypto"
|
||||||
|
import {
|
||||||
|
getMediaUploadMaxBytes,
|
||||||
|
isMimeAllowedForMediaType,
|
||||||
|
mediaAssetTypeSchema,
|
||||||
|
} from "@cms/content"
|
||||||
import { hasPermission } from "@cms/content/rbac"
|
import { hasPermission } from "@cms/content/rbac"
|
||||||
import { createMediaAsset } from "@cms/db"
|
import { createMediaAsset } from "@cms/db"
|
||||||
|
|
||||||
@@ -7,33 +12,7 @@ import { storeUpload } from "@/lib/media/storage"
|
|||||||
|
|
||||||
export const runtime = "nodejs"
|
export const runtime = "nodejs"
|
||||||
|
|
||||||
const MAX_UPLOAD_BYTES = Number(process.env.CMS_MEDIA_UPLOAD_MAX_BYTES ?? 25 * 1024 * 1024)
|
const MAX_UPLOAD_BYTES_OVERRIDE = Number(process.env.CMS_MEDIA_UPLOAD_MAX_BYTES ?? 0)
|
||||||
|
|
||||||
type AllowedRule = {
|
|
||||||
mimePrefix?: string
|
|
||||||
mimeExact?: string[]
|
|
||||||
}
|
|
||||||
|
|
||||||
const ALLOWED_MIME_BY_TYPE: Record<string, AllowedRule> = {
|
|
||||||
artwork: {
|
|
||||||
mimePrefix: "image/",
|
|
||||||
},
|
|
||||||
banner: {
|
|
||||||
mimePrefix: "image/",
|
|
||||||
},
|
|
||||||
promotion: {
|
|
||||||
mimePrefix: "image/",
|
|
||||||
},
|
|
||||||
video: {
|
|
||||||
mimePrefix: "video/",
|
|
||||||
},
|
|
||||||
gif: {
|
|
||||||
mimeExact: ["image/gif"],
|
|
||||||
},
|
|
||||||
generic: {
|
|
||||||
mimePrefix: "",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseTextField(formData: FormData, field: string): string {
|
function parseTextField(formData: FormData, field: string): string {
|
||||||
const value = formData.get(field)
|
const value = formData.get(field)
|
||||||
@@ -58,6 +37,22 @@ function parseTags(formData: FormData): string[] {
|
|||||||
.filter((item) => item.length > 0)
|
.filter((item) => item.length > 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseOptionalDateField(formData: FormData, field: string): Date | undefined {
|
||||||
|
const value = parseTextField(formData, field)
|
||||||
|
|
||||||
|
if (!value) {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
const parsed = new Date(value)
|
||||||
|
|
||||||
|
if (Number.isNaN(parsed.getTime())) {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
return parsed
|
||||||
|
}
|
||||||
|
|
||||||
function deriveTitleFromFilename(fileName: string): string {
|
function deriveTitleFromFilename(fileName: string): string {
|
||||||
const trimmed = fileName.trim()
|
const trimmed = fileName.trim()
|
||||||
|
|
||||||
@@ -72,24 +67,6 @@ function deriveTitleFromFilename(fileName: string): string {
|
|||||||
return normalized.length > 0 ? normalized : "Untitled media"
|
return normalized.length > 0 ? normalized : "Untitled media"
|
||||||
}
|
}
|
||||||
|
|
||||||
function isMimeAllowed(mediaType: string, mimeType: string): boolean {
|
|
||||||
const rule = ALLOWED_MIME_BY_TYPE[mediaType]
|
|
||||||
|
|
||||||
if (!rule) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rule.mimeExact?.includes(mimeType)) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rule.mimePrefix === "") {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
return rule.mimePrefix ? mimeType.startsWith(rule.mimePrefix) : false
|
|
||||||
}
|
|
||||||
|
|
||||||
function badRequest(message: string): Response {
|
function badRequest(message: string): Response {
|
||||||
return Response.json(
|
return Response.json(
|
||||||
{
|
{
|
||||||
@@ -131,12 +108,13 @@ export async function POST(request: Request): Promise<Response> {
|
|||||||
return badRequest("Invalid form payload.")
|
return badRequest("Invalid form payload.")
|
||||||
}
|
}
|
||||||
|
|
||||||
const type = parseTextField(formData, "type")
|
const parsedType = mediaAssetTypeSchema.safeParse(parseTextField(formData, "type"))
|
||||||
const fileEntry = formData.get("file")
|
const fileEntry = formData.get("file")
|
||||||
|
|
||||||
if (!type) {
|
if (!parsedType.success) {
|
||||||
return badRequest("Type is required.")
|
return badRequest("Type is required.")
|
||||||
}
|
}
|
||||||
|
const type = parsedType.data
|
||||||
|
|
||||||
if (!(fileEntry instanceof File)) {
|
if (!(fileEntry instanceof File)) {
|
||||||
return badRequest("File is required.")
|
return badRequest("File is required.")
|
||||||
@@ -146,13 +124,17 @@ export async function POST(request: Request): Promise<Response> {
|
|||||||
return badRequest("File is empty.")
|
return badRequest("File is empty.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fileEntry.size > MAX_UPLOAD_BYTES) {
|
const typeMaxBytes = getMediaUploadMaxBytes(type)
|
||||||
|
const effectiveMaxBytes =
|
||||||
|
MAX_UPLOAD_BYTES_OVERRIDE > 0 ? Math.min(MAX_UPLOAD_BYTES_OVERRIDE, typeMaxBytes) : typeMaxBytes
|
||||||
|
|
||||||
|
if (fileEntry.size > effectiveMaxBytes) {
|
||||||
return badRequest(
|
return badRequest(
|
||||||
`File is too large. Maximum upload is ${Math.floor(MAX_UPLOAD_BYTES / 1024 / 1024)} MB.`,
|
`File is too large for ${type}. Maximum upload is ${Math.floor(effectiveMaxBytes / 1024 / 1024)} MB.`,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isMimeAllowed(type, fileEntry.type)) {
|
if (!isMimeAllowedForMediaType(type, fileEntry.type)) {
|
||||||
return badRequest(`File type ${fileEntry.type || "unknown"} is not allowed for ${type}.`)
|
return badRequest(`File type ${fileEntry.type || "unknown"} is not allowed for ${type}.`)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,6 +160,11 @@ export async function POST(request: Request): Promise<Response> {
|
|||||||
source: parseOptionalField(formData, "source"),
|
source: parseOptionalField(formData, "source"),
|
||||||
copyright: parseOptionalField(formData, "copyright"),
|
copyright: parseOptionalField(formData, "copyright"),
|
||||||
author: parseOptionalField(formData, "author"),
|
author: parseOptionalField(formData, "author"),
|
||||||
|
licenseType: parseOptionalField(formData, "licenseType"),
|
||||||
|
licenseUrl: parseOptionalField(formData, "licenseUrl"),
|
||||||
|
usageContext: parseOptionalField(formData, "usageContext"),
|
||||||
|
location: parseOptionalField(formData, "location"),
|
||||||
|
capturedAt: parseOptionalDateField(formData, "capturedAt"),
|
||||||
tags: parseTags(formData),
|
tags: parseTags(formData),
|
||||||
storageKey: stored.storageKey,
|
storageKey: stored.storageKey,
|
||||||
mimeType: fileEntry.type || undefined,
|
mimeType: fileEntry.type || undefined,
|
||||||
|
|||||||
@@ -2,8 +2,11 @@ import {
|
|||||||
commissionKanbanOrder,
|
commissionKanbanOrder,
|
||||||
createCommission,
|
createCommission,
|
||||||
createCustomer,
|
createCustomer,
|
||||||
|
db,
|
||||||
|
listArtworks,
|
||||||
listCommissions,
|
listCommissions,
|
||||||
listCustomers,
|
listCustomers,
|
||||||
|
updateCommission,
|
||||||
updateCommissionStatus,
|
updateCommissionStatus,
|
||||||
} from "@cms/db"
|
} from "@cms/db"
|
||||||
import { Button } from "@cms/ui/button"
|
import { Button } from "@cms/ui/button"
|
||||||
@@ -67,6 +70,19 @@ function readNullableDate(formData: FormData, field: string): Date | null {
|
|||||||
return parsed
|
return parsed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function readUuidList(formData: FormData, field: string): string[] {
|
||||||
|
const raw = readInputString(formData, field)
|
||||||
|
|
||||||
|
if (!raw) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
return raw
|
||||||
|
.split(",")
|
||||||
|
.map((entry) => entry.trim())
|
||||||
|
.filter((entry) => entry.length > 0)
|
||||||
|
}
|
||||||
|
|
||||||
function redirectWithState(params: { notice?: string; error?: string }) {
|
function redirectWithState(params: { notice?: string; error?: string }) {
|
||||||
const query = new URLSearchParams()
|
const query = new URLSearchParams()
|
||||||
|
|
||||||
@@ -124,6 +140,7 @@ async function createCommissionAction(formData: FormData) {
|
|||||||
status: readInputString(formData, "status"),
|
status: readInputString(formData, "status"),
|
||||||
customerId: readNullableString(formData, "customerId"),
|
customerId: readNullableString(formData, "customerId"),
|
||||||
assignedUserId: readNullableString(formData, "assignedUserId"),
|
assignedUserId: readNullableString(formData, "assignedUserId"),
|
||||||
|
linkedArtworkIds: readUuidList(formData, "linkedArtworkIds"),
|
||||||
budgetMin: readNullableNumber(formData, "budgetMin"),
|
budgetMin: readNullableNumber(formData, "budgetMin"),
|
||||||
budgetMax: readNullableNumber(formData, "budgetMax"),
|
budgetMax: readNullableNumber(formData, "budgetMax"),
|
||||||
dueAt: readNullableDate(formData, "dueAt"),
|
dueAt: readNullableDate(formData, "dueAt"),
|
||||||
@@ -136,6 +153,35 @@ async function createCommissionAction(formData: FormData) {
|
|||||||
redirectWithState({ notice: "Commission created." })
|
redirectWithState({ notice: "Commission created." })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function updateCommissionAction(formData: FormData) {
|
||||||
|
"use server"
|
||||||
|
|
||||||
|
await requirePermissionForRoute({
|
||||||
|
nextPath: "/commissions",
|
||||||
|
permission: "commissions:write",
|
||||||
|
scope: "own",
|
||||||
|
})
|
||||||
|
|
||||||
|
try {
|
||||||
|
await updateCommission({
|
||||||
|
id: readInputString(formData, "id"),
|
||||||
|
title: readInputString(formData, "title"),
|
||||||
|
description: readNullableString(formData, "description"),
|
||||||
|
customerId: readNullableString(formData, "customerId"),
|
||||||
|
assignedUserId: readNullableString(formData, "assignedUserId"),
|
||||||
|
linkedArtworkIds: readUuidList(formData, "linkedArtworkIds"),
|
||||||
|
budgetMin: readNullableNumber(formData, "budgetMin"),
|
||||||
|
budgetMax: readNullableNumber(formData, "budgetMax"),
|
||||||
|
dueAt: readNullableDate(formData, "dueAt"),
|
||||||
|
})
|
||||||
|
} catch {
|
||||||
|
redirectWithState({ error: "Failed to update commission details." })
|
||||||
|
}
|
||||||
|
|
||||||
|
revalidatePath("/commissions")
|
||||||
|
redirectWithState({ notice: "Commission updated." })
|
||||||
|
}
|
||||||
|
|
||||||
async function updateCommissionStatusAction(formData: FormData) {
|
async function updateCommissionStatusAction(formData: FormData) {
|
||||||
"use server"
|
"use server"
|
||||||
|
|
||||||
@@ -166,6 +212,14 @@ function formatDate(value: Date | null) {
|
|||||||
return value.toLocaleDateString("en-US")
|
return value.toLocaleDateString("en-US")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatDateInput(value: Date | null) {
|
||||||
|
if (!value) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return value.toISOString().slice(0, 10)
|
||||||
|
}
|
||||||
|
|
||||||
export default async function CommissionsManagementPage({
|
export default async function CommissionsManagementPage({
|
||||||
searchParams,
|
searchParams,
|
||||||
}: {
|
}: {
|
||||||
@@ -177,10 +231,22 @@ export default async function CommissionsManagementPage({
|
|||||||
scope: "own",
|
scope: "own",
|
||||||
})
|
})
|
||||||
|
|
||||||
const [resolvedSearchParams, customers, commissions] = await Promise.all([
|
const [resolvedSearchParams, customers, commissions, assignees, artworks] = await Promise.all([
|
||||||
searchParams,
|
searchParams,
|
||||||
listCustomers(200),
|
listCustomers(200),
|
||||||
listCommissions(300),
|
listCommissions(300),
|
||||||
|
db.user.findMany({
|
||||||
|
where: {
|
||||||
|
isBanned: false,
|
||||||
|
},
|
||||||
|
orderBy: [{ createdAt: "asc" }],
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
name: true,
|
||||||
|
username: true,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
listArtworks(300),
|
||||||
])
|
])
|
||||||
|
|
||||||
const notice = readFirstValue(resolvedSearchParams.notice)
|
const notice = readFirstValue(resolvedSearchParams.notice)
|
||||||
@@ -309,11 +375,18 @@ export default async function CommissionsManagementPage({
|
|||||||
</div>
|
</div>
|
||||||
<div className="grid gap-3 md:grid-cols-3">
|
<div className="grid gap-3 md:grid-cols-3">
|
||||||
<label className="space-y-1">
|
<label className="space-y-1">
|
||||||
<span className="text-xs text-neutral-600">Assigned user id</span>
|
<span className="text-xs text-neutral-600">Assigned user</span>
|
||||||
<input
|
<select
|
||||||
name="assignedUserId"
|
name="assignedUserId"
|
||||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||||
/>
|
>
|
||||||
|
<option value="">(none)</option>
|
||||||
|
{assignees.map((assignee) => (
|
||||||
|
<option key={assignee.id} value={assignee.id}>
|
||||||
|
{assignee.name} @{assignee.username ?? "no-user"}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
</label>
|
</label>
|
||||||
<label className="space-y-1">
|
<label className="space-y-1">
|
||||||
<span className="text-xs text-neutral-600">Budget min</span>
|
<span className="text-xs text-neutral-600">Budget min</span>
|
||||||
@@ -344,6 +417,14 @@ export default async function CommissionsManagementPage({
|
|||||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
|
<label className="space-y-1">
|
||||||
|
<span className="text-xs text-neutral-600">Linked artwork IDs (comma separated)</span>
|
||||||
|
<textarea
|
||||||
|
name="linkedArtworkIds"
|
||||||
|
rows={2}
|
||||||
|
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
<Button type="submit">Create commission</Button>
|
<Button type="submit">Create commission</Button>
|
||||||
</form>
|
</form>
|
||||||
</article>
|
</article>
|
||||||
@@ -383,6 +464,9 @@ export default async function CommissionsManagementPage({
|
|||||||
<p className="text-xs text-neutral-600">
|
<p className="text-xs text-neutral-600">
|
||||||
{commission.customer?.name ?? "No customer"}
|
{commission.customer?.name ?? "No customer"}
|
||||||
</p>
|
</p>
|
||||||
|
<p className="text-xs text-neutral-500">
|
||||||
|
Assignee: {commission.assignedUser?.name ?? "none"}
|
||||||
|
</p>
|
||||||
<p className="text-xs text-neutral-500">
|
<p className="text-xs text-neutral-500">
|
||||||
Due: {formatDate(commission.dueAt)}
|
Due: {formatDate(commission.dueAt)}
|
||||||
</p>
|
</p>
|
||||||
@@ -406,6 +490,99 @@ export default async function CommissionsManagementPage({
|
|||||||
Move
|
Move
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
<details className="mt-2 rounded border border-neutral-200 p-2 text-xs">
|
||||||
|
<summary className="cursor-pointer text-neutral-700">
|
||||||
|
Edit details
|
||||||
|
</summary>
|
||||||
|
<form action={updateCommissionAction} className="mt-2 space-y-2">
|
||||||
|
<input type="hidden" name="id" value={commission.id} />
|
||||||
|
<input
|
||||||
|
name="title"
|
||||||
|
defaultValue={commission.title}
|
||||||
|
className="w-full rounded border border-neutral-300 px-2 py-1"
|
||||||
|
/>
|
||||||
|
<textarea
|
||||||
|
name="description"
|
||||||
|
rows={2}
|
||||||
|
defaultValue={commission.description ?? ""}
|
||||||
|
className="w-full rounded border border-neutral-300 px-2 py-1"
|
||||||
|
/>
|
||||||
|
<select
|
||||||
|
name="customerId"
|
||||||
|
defaultValue={commission.customerId ?? ""}
|
||||||
|
className="w-full rounded border border-neutral-300 px-2 py-1"
|
||||||
|
>
|
||||||
|
<option value="">(no customer)</option>
|
||||||
|
{customers.map((customer) => (
|
||||||
|
<option
|
||||||
|
key={`${commission.id}-customer-${customer.id}`}
|
||||||
|
value={customer.id}
|
||||||
|
>
|
||||||
|
{customer.name}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
<select
|
||||||
|
name="assignedUserId"
|
||||||
|
defaultValue={commission.assignedUserId ?? ""}
|
||||||
|
className="w-full rounded border border-neutral-300 px-2 py-1"
|
||||||
|
>
|
||||||
|
<option value="">(no assignee)</option>
|
||||||
|
{assignees.map((assignee) => (
|
||||||
|
<option
|
||||||
|
key={`${commission.id}-assignee-${assignee.id}`}
|
||||||
|
value={assignee.id}
|
||||||
|
>
|
||||||
|
{assignee.name}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
<div className="grid grid-cols-2 gap-2">
|
||||||
|
<input
|
||||||
|
name="budgetMin"
|
||||||
|
type="number"
|
||||||
|
min={0}
|
||||||
|
step="0.01"
|
||||||
|
defaultValue={commission.budgetMin ?? ""}
|
||||||
|
placeholder="Budget min"
|
||||||
|
className="rounded border border-neutral-300 px-2 py-1"
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
name="budgetMax"
|
||||||
|
type="number"
|
||||||
|
min={0}
|
||||||
|
step="0.01"
|
||||||
|
defaultValue={commission.budgetMax ?? ""}
|
||||||
|
placeholder="Budget max"
|
||||||
|
className="rounded border border-neutral-300 px-2 py-1"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<input
|
||||||
|
name="dueAt"
|
||||||
|
type="date"
|
||||||
|
defaultValue={formatDateInput(commission.dueAt)}
|
||||||
|
className="w-full rounded border border-neutral-300 px-2 py-1"
|
||||||
|
/>
|
||||||
|
<textarea
|
||||||
|
name="linkedArtworkIds"
|
||||||
|
rows={2}
|
||||||
|
defaultValue={commission.linkedArtworkIds.join(",")}
|
||||||
|
placeholder="Artwork IDs"
|
||||||
|
className="w-full rounded border border-neutral-300 px-2 py-1"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
className="rounded border border-neutral-300 px-2 py-1 text-xs"
|
||||||
|
>
|
||||||
|
Save details
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</details>
|
||||||
|
{commission.linkedArtworkIds.length > 0 ? (
|
||||||
|
<p className="mt-2 text-[11px] text-neutral-500">
|
||||||
|
Linked artworks: {commission.linkedArtworkIds.length}
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
</form>
|
</form>
|
||||||
))
|
))
|
||||||
)}
|
)}
|
||||||
@@ -449,6 +626,24 @@ export default async function CommissionsManagementPage({
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<section className="rounded-xl border border-neutral-200 p-6">
|
||||||
|
<h2 className="text-xl font-medium">Artwork Reference</h2>
|
||||||
|
<p className="mt-1 text-sm text-neutral-600">
|
||||||
|
Use these IDs when linking artworks to commissions.
|
||||||
|
</p>
|
||||||
|
<div className="mt-3 max-h-64 overflow-auto rounded border border-neutral-200 p-3 text-xs">
|
||||||
|
{artworks.length === 0 ? (
|
||||||
|
<p className="text-neutral-500">No artworks available.</p>
|
||||||
|
) : (
|
||||||
|
artworks.map((artwork) => (
|
||||||
|
<p key={artwork.id} className="font-mono text-neutral-700">
|
||||||
|
{artwork.id} - {artwork.title}
|
||||||
|
</p>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
</AdminShell>
|
</AdminShell>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,22 @@ function readNullableInt(formData: FormData, field: string): number | null {
|
|||||||
return parsed
|
return parsed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function readNullableDate(formData: FormData, field: string): Date | null {
|
||||||
|
const value = readInputString(formData, field)
|
||||||
|
|
||||||
|
if (!value) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
const parsed = new Date(value)
|
||||||
|
|
||||||
|
if (Number.isNaN(parsed.getTime())) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
return parsed
|
||||||
|
}
|
||||||
|
|
||||||
function readTags(formData: FormData): string[] {
|
function readTags(formData: FormData): string[] {
|
||||||
const raw = readInputString(formData, "tags")
|
const raw = readInputString(formData, "tags")
|
||||||
|
|
||||||
@@ -127,6 +143,11 @@ export default async function MediaAssetEditorPage({ params, searchParams }: Pag
|
|||||||
source: readNullableString(formData, "source"),
|
source: readNullableString(formData, "source"),
|
||||||
copyright: readNullableString(formData, "copyright"),
|
copyright: readNullableString(formData, "copyright"),
|
||||||
author: readNullableString(formData, "author"),
|
author: readNullableString(formData, "author"),
|
||||||
|
licenseType: readNullableString(formData, "licenseType"),
|
||||||
|
licenseUrl: readNullableString(formData, "licenseUrl"),
|
||||||
|
usageContext: readNullableString(formData, "usageContext"),
|
||||||
|
location: readNullableString(formData, "location"),
|
||||||
|
capturedAt: readNullableDate(formData, "capturedAt"),
|
||||||
tags: readTags(formData),
|
tags: readTags(formData),
|
||||||
mimeType: readNullableString(formData, "mimeType"),
|
mimeType: readNullableString(formData, "mimeType"),
|
||||||
width: readNullableInt(formData, "width"),
|
width: readNullableInt(formData, "width"),
|
||||||
@@ -320,6 +341,56 @@ export default async function MediaAssetEditorPage({ params, searchParams }: Pag
|
|||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="grid gap-3 md:grid-cols-2">
|
||||||
|
<label className="space-y-1">
|
||||||
|
<span className="text-xs text-neutral-600">License type</span>
|
||||||
|
<input
|
||||||
|
name="licenseType"
|
||||||
|
defaultValue={mediaAsset.licenseType ?? ""}
|
||||||
|
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label className="space-y-1">
|
||||||
|
<span className="text-xs text-neutral-600">License URL</span>
|
||||||
|
<input
|
||||||
|
name="licenseUrl"
|
||||||
|
defaultValue={mediaAsset.licenseUrl ?? ""}
|
||||||
|
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid gap-3 md:grid-cols-2">
|
||||||
|
<label className="space-y-1">
|
||||||
|
<span className="text-xs text-neutral-600">Usage context</span>
|
||||||
|
<input
|
||||||
|
name="usageContext"
|
||||||
|
defaultValue={mediaAsset.usageContext ?? ""}
|
||||||
|
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label className="space-y-1">
|
||||||
|
<span className="text-xs text-neutral-600">Location</span>
|
||||||
|
<input
|
||||||
|
name="location"
|
||||||
|
defaultValue={mediaAsset.location ?? ""}
|
||||||
|
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<label className="space-y-1">
|
||||||
|
<span className="text-xs text-neutral-600">Captured at</span>
|
||||||
|
<input
|
||||||
|
name="capturedAt"
|
||||||
|
type="datetime-local"
|
||||||
|
defaultValue={
|
||||||
|
mediaAsset.capturedAt ? toLocalDateTimeInputValue(mediaAsset.capturedAt) : ""
|
||||||
|
}
|
||||||
|
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
<div className="grid gap-3 md:grid-cols-3">
|
<div className="grid gap-3 md:grid-cols-3">
|
||||||
<label className="space-y-1">
|
<label className="space-y-1">
|
||||||
<span className="text-xs text-neutral-600">MIME type</span>
|
<span className="text-xs text-neutral-600">MIME type</span>
|
||||||
|
|||||||
@@ -2,9 +2,11 @@ import {
|
|||||||
createNavigationItem,
|
createNavigationItem,
|
||||||
createNavigationMenu,
|
createNavigationMenu,
|
||||||
deleteNavigationItem,
|
deleteNavigationItem,
|
||||||
|
deleteNavigationMenu,
|
||||||
listNavigationMenus,
|
listNavigationMenus,
|
||||||
listPages,
|
listPages,
|
||||||
updateNavigationItem,
|
updateNavigationItem,
|
||||||
|
updateNavigationMenu,
|
||||||
upsertNavigationItemTranslation,
|
upsertNavigationItemTranslation,
|
||||||
} from "@cms/db"
|
} from "@cms/db"
|
||||||
import { Button } from "@cms/ui/button"
|
import { Button } from "@cms/ui/button"
|
||||||
@@ -131,6 +133,50 @@ async function createItemAction(formData: FormData) {
|
|||||||
redirectWithState({ notice: "Navigation item created." })
|
redirectWithState({ notice: "Navigation item created." })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function updateMenuAction(formData: FormData) {
|
||||||
|
"use server"
|
||||||
|
|
||||||
|
await requirePermissionForRoute({
|
||||||
|
nextPath: "/navigation",
|
||||||
|
permission: "navigation:write",
|
||||||
|
scope: "team",
|
||||||
|
})
|
||||||
|
|
||||||
|
try {
|
||||||
|
await updateNavigationMenu({
|
||||||
|
id: readInputString(formData, "id"),
|
||||||
|
name: readInputString(formData, "name"),
|
||||||
|
slug: readInputString(formData, "slug"),
|
||||||
|
location: readInputString(formData, "location"),
|
||||||
|
isVisible: readInputString(formData, "isVisible") === "true",
|
||||||
|
})
|
||||||
|
} catch {
|
||||||
|
redirectWithState({ error: "Failed to update navigation menu." })
|
||||||
|
}
|
||||||
|
|
||||||
|
revalidatePath("/navigation")
|
||||||
|
redirectWithState({ notice: "Navigation menu updated." })
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteMenuAction(formData: FormData) {
|
||||||
|
"use server"
|
||||||
|
|
||||||
|
await requirePermissionForRoute({
|
||||||
|
nextPath: "/navigation",
|
||||||
|
permission: "navigation:write",
|
||||||
|
scope: "team",
|
||||||
|
})
|
||||||
|
|
||||||
|
try {
|
||||||
|
await deleteNavigationMenu(readInputString(formData, "id"))
|
||||||
|
} catch {
|
||||||
|
redirectWithState({ error: "Failed to delete navigation menu." })
|
||||||
|
}
|
||||||
|
|
||||||
|
revalidatePath("/navigation")
|
||||||
|
redirectWithState({ notice: "Navigation menu deleted." })
|
||||||
|
}
|
||||||
|
|
||||||
async function updateItemAction(formData: FormData) {
|
async function updateItemAction(formData: FormData) {
|
||||||
"use server"
|
"use server"
|
||||||
|
|
||||||
@@ -279,14 +325,58 @@ export default async function NavigationManagementPage({
|
|||||||
) : (
|
) : (
|
||||||
menus.map((menu) => (
|
menus.map((menu) => (
|
||||||
<article key={menu.id} className="rounded-xl border border-neutral-200 p-6">
|
<article key={menu.id} className="rounded-xl border border-neutral-200 p-6">
|
||||||
<div className="flex flex-wrap items-center justify-between gap-2">
|
<form action={updateMenuAction} className="rounded border border-neutral-200 p-3">
|
||||||
<h3 className="text-lg font-medium">
|
<input type="hidden" name="id" value={menu.id} />
|
||||||
{menu.name} <span className="text-sm text-neutral-500">({menu.location})</span>
|
<div className="grid gap-3 md:grid-cols-4">
|
||||||
</h3>
|
<label className="space-y-1">
|
||||||
<span className="text-xs text-neutral-500">
|
<span className="text-xs text-neutral-600">Menu name</span>
|
||||||
{menu.isVisible ? "visible" : "hidden"}
|
<input
|
||||||
</span>
|
name="name"
|
||||||
|
defaultValue={menu.name}
|
||||||
|
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label className="space-y-1">
|
||||||
|
<span className="text-xs text-neutral-600">Slug</span>
|
||||||
|
<input
|
||||||
|
name="slug"
|
||||||
|
defaultValue={menu.slug}
|
||||||
|
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label className="space-y-1">
|
||||||
|
<span className="text-xs text-neutral-600">Location</span>
|
||||||
|
<input
|
||||||
|
name="location"
|
||||||
|
defaultValue={menu.location}
|
||||||
|
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label className="space-y-1">
|
||||||
|
<span className="text-xs text-neutral-600">Visible</span>
|
||||||
|
<select
|
||||||
|
name="isVisible"
|
||||||
|
defaultValue={menu.isVisible ? "true" : "false"}
|
||||||
|
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||||
|
>
|
||||||
|
<option value="true">Visible</option>
|
||||||
|
<option value="false">Hidden</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="mt-3 flex items-center gap-2">
|
||||||
|
<Button type="submit" size="sm">
|
||||||
|
Save menu
|
||||||
|
</Button>
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
formAction={deleteMenuAction}
|
||||||
|
className="rounded-md border border-red-300 px-3 py-2 text-sm text-red-700"
|
||||||
|
>
|
||||||
|
Delete menu
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
<div className="mt-4 space-y-3">
|
<div className="mt-4 space-y-3">
|
||||||
{menu.items.length === 0 ? (
|
{menu.items.length === 0 ? (
|
||||||
@@ -348,11 +438,20 @@ export default async function NavigationManagementPage({
|
|||||||
</label>
|
</label>
|
||||||
<label className="space-y-1">
|
<label className="space-y-1">
|
||||||
<span className="text-xs text-neutral-600">Parent id</span>
|
<span className="text-xs text-neutral-600">Parent id</span>
|
||||||
<input
|
<select
|
||||||
name="parentId"
|
name="parentId"
|
||||||
defaultValue={item.parentId ?? ""}
|
defaultValue={item.parentId ?? ""}
|
||||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||||
/>
|
>
|
||||||
|
<option value="">(none)</option>
|
||||||
|
{menu.items
|
||||||
|
.filter((entry) => entry.id !== item.id)
|
||||||
|
.map((entry) => (
|
||||||
|
<option key={`${item.id}-parent-${entry.id}`} value={entry.id}>
|
||||||
|
{entry.label}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import Link from "next/link"
|
|||||||
import { redirect } from "next/navigation"
|
import { redirect } from "next/navigation"
|
||||||
|
|
||||||
import { AdminShell } from "@/components/admin-shell"
|
import { AdminShell } from "@/components/admin-shell"
|
||||||
|
import { PageBlockEditor } from "@/components/pages/page-block-editor"
|
||||||
import { requirePermissionForRoute } from "@/lib/route-guards"
|
import { requirePermissionForRoute } from "@/lib/route-guards"
|
||||||
|
|
||||||
export const dynamic = "force-dynamic"
|
export const dynamic = "force-dynamic"
|
||||||
@@ -242,16 +243,7 @@ export default async function PageEditorPage({ params, searchParams }: PageProps
|
|||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<label className="space-y-1">
|
<PageBlockEditor name="content" initialContent={page.content} />
|
||||||
<span className="text-xs text-neutral-600">Content</span>
|
|
||||||
<textarea
|
|
||||||
name="content"
|
|
||||||
rows={10}
|
|
||||||
defaultValue={page.content}
|
|
||||||
required
|
|
||||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
|
||||||
/>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<div className="grid gap-3 md:grid-cols-2">
|
<div className="grid gap-3 md:grid-cols-2">
|
||||||
<label className="space-y-1">
|
<label className="space-y-1">
|
||||||
@@ -368,16 +360,11 @@ export default async function PageEditorPage({ params, searchParams }: PageProps
|
|||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<label className="space-y-1">
|
<PageBlockEditor
|
||||||
<span className="text-xs text-neutral-600">Content</span>
|
|
||||||
<textarea
|
|
||||||
name="content"
|
name="content"
|
||||||
rows={8}
|
initialContent={selectedTranslation?.content ?? page.content}
|
||||||
defaultValue={selectedTranslation?.content ?? page.content}
|
label="Translation Blocks"
|
||||||
required
|
|
||||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
|
||||||
/>
|
/>
|
||||||
</label>
|
|
||||||
|
|
||||||
<div className="grid gap-3 md:grid-cols-2">
|
<div className="grid gap-3 md:grid-cols-2">
|
||||||
<label className="space-y-1">
|
<label className="space-y-1">
|
||||||
|
|||||||
@@ -5,10 +5,14 @@ import {
|
|||||||
createCategory,
|
createCategory,
|
||||||
createGallery,
|
createGallery,
|
||||||
createTag,
|
createTag,
|
||||||
|
deleteArtworkRendition,
|
||||||
|
deleteGrouping,
|
||||||
linkArtworkToGrouping,
|
linkArtworkToGrouping,
|
||||||
listArtworks,
|
listArtworks,
|
||||||
listMediaAssets,
|
listMediaAssets,
|
||||||
listMediaFoundationGroups,
|
listMediaFoundationGroups,
|
||||||
|
updateArtwork,
|
||||||
|
updateGrouping,
|
||||||
} from "@cms/db"
|
} from "@cms/db"
|
||||||
import { Button } from "@cms/ui/button"
|
import { Button } from "@cms/ui/button"
|
||||||
import { revalidatePath } from "next/cache"
|
import { revalidatePath } from "next/cache"
|
||||||
@@ -32,6 +36,30 @@ function readOptionalField(formData: FormData, key: string): string | undefined
|
|||||||
return value.length > 0 ? value : undefined
|
return value.length > 0 ? value : undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function readOptionalNullableField(formData: FormData, key: string): string | null {
|
||||||
|
const value = readField(formData, key)
|
||||||
|
return value.length > 0 ? value : null
|
||||||
|
}
|
||||||
|
|
||||||
|
function readNonNegativeInt(formData: FormData, key: string): number {
|
||||||
|
const raw = readField(formData, key)
|
||||||
|
const value = Number(raw)
|
||||||
|
return Number.isFinite(value) && value >= 0 ? Math.floor(value) : 0
|
||||||
|
}
|
||||||
|
|
||||||
|
function readOptionalNonNegativeInt(formData: FormData, key: string): number | undefined {
|
||||||
|
const raw = readField(formData, key)
|
||||||
|
if (!raw) {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
const value = Number(raw)
|
||||||
|
return Number.isFinite(value) && value >= 0 ? Math.floor(value) : undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
function readBooleanField(formData: FormData, key: string): boolean {
|
||||||
|
return formData.get(key) === "on" || readField(formData, key) === "true"
|
||||||
|
}
|
||||||
|
|
||||||
function readFirstValue(value: string | string[] | undefined): string | null {
|
function readFirstValue(value: string | string[] | undefined): string | null {
|
||||||
if (Array.isArray(value)) {
|
if (Array.isArray(value)) {
|
||||||
return value[0] ?? null
|
return value[0] ?? null
|
||||||
@@ -89,6 +117,15 @@ async function createArtworkAction(formData: FormData) {
|
|||||||
dimensions: readOptionalField(formData, "dimensions"),
|
dimensions: readOptionalField(formData, "dimensions"),
|
||||||
framing: readOptionalField(formData, "framing"),
|
framing: readOptionalField(formData, "framing"),
|
||||||
availability: readOptionalField(formData, "availability"),
|
availability: readOptionalField(formData, "availability"),
|
||||||
|
priceAmountCents: (() => {
|
||||||
|
const raw = readField(formData, "priceAmount")
|
||||||
|
return raw ? Math.round(Number(raw) * 100) : undefined
|
||||||
|
})(),
|
||||||
|
priceCurrency: (() => {
|
||||||
|
const raw = readField(formData, "priceCurrency").toUpperCase()
|
||||||
|
return raw.length === 3 ? raw : undefined
|
||||||
|
})(),
|
||||||
|
isPriceVisible: readBooleanField(formData, "isPriceVisible"),
|
||||||
year: (() => {
|
year: (() => {
|
||||||
const raw = readField(formData, "year")
|
const raw = readField(formData, "year")
|
||||||
return raw ? Number(raw) : undefined
|
return raw ? Number(raw) : undefined
|
||||||
@@ -102,6 +139,41 @@ async function createArtworkAction(formData: FormData) {
|
|||||||
redirectWithState({ notice: "Artwork created." })
|
redirectWithState({ notice: "Artwork created." })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function updateArtworkAction(formData: FormData) {
|
||||||
|
"use server"
|
||||||
|
|
||||||
|
await requireWritePermission()
|
||||||
|
|
||||||
|
try {
|
||||||
|
await updateArtwork({
|
||||||
|
id: readField(formData, "artworkId"),
|
||||||
|
medium: readOptionalNullableField(formData, "medium"),
|
||||||
|
dimensions: readOptionalNullableField(formData, "dimensions"),
|
||||||
|
year: (() => {
|
||||||
|
const raw = readField(formData, "year")
|
||||||
|
return raw ? Number(raw) : null
|
||||||
|
})(),
|
||||||
|
framing: readOptionalNullableField(formData, "framing"),
|
||||||
|
availability: readOptionalNullableField(formData, "availability"),
|
||||||
|
priceAmountCents: (() => {
|
||||||
|
const value = readOptionalNonNegativeInt(formData, "priceAmountCents")
|
||||||
|
return value ?? null
|
||||||
|
})(),
|
||||||
|
priceCurrency: (() => {
|
||||||
|
const raw = readField(formData, "priceCurrency").toUpperCase()
|
||||||
|
return raw.length === 3 ? raw : null
|
||||||
|
})(),
|
||||||
|
isPriceVisible: readBooleanField(formData, "isPriceVisible"),
|
||||||
|
isPublished: readBooleanField(formData, "isPublished"),
|
||||||
|
})
|
||||||
|
} catch {
|
||||||
|
redirectWithState({ error: "Failed to update artwork refinement fields." })
|
||||||
|
}
|
||||||
|
|
||||||
|
revalidatePath("/portfolio")
|
||||||
|
redirectWithState({ notice: "Artwork refinement updated." })
|
||||||
|
}
|
||||||
|
|
||||||
async function createGroupAction(formData: FormData) {
|
async function createGroupAction(formData: FormData) {
|
||||||
"use server"
|
"use server"
|
||||||
|
|
||||||
@@ -117,23 +189,32 @@ async function createGroupAction(formData: FormData) {
|
|||||||
name,
|
name,
|
||||||
slug,
|
slug,
|
||||||
description: readOptionalField(formData, "description"),
|
description: readOptionalField(formData, "description"),
|
||||||
|
sortOrder: readNonNegativeInt(formData, "sortOrder"),
|
||||||
|
isVisible: readBooleanField(formData, "isVisible"),
|
||||||
})
|
})
|
||||||
} else if (type === "album") {
|
} else if (type === "album") {
|
||||||
await createAlbum({
|
await createAlbum({
|
||||||
name,
|
name,
|
||||||
slug,
|
slug,
|
||||||
description: readOptionalField(formData, "description"),
|
description: readOptionalField(formData, "description"),
|
||||||
|
sortOrder: readNonNegativeInt(formData, "sortOrder"),
|
||||||
|
isVisible: readBooleanField(formData, "isVisible"),
|
||||||
})
|
})
|
||||||
} else if (type === "category") {
|
} else if (type === "category") {
|
||||||
await createCategory({
|
await createCategory({
|
||||||
name,
|
name,
|
||||||
slug,
|
slug,
|
||||||
description: readOptionalField(formData, "description"),
|
description: readOptionalField(formData, "description"),
|
||||||
|
sortOrder: readNonNegativeInt(formData, "sortOrder"),
|
||||||
|
isVisible: readBooleanField(formData, "isVisible"),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
await createTag({
|
await createTag({
|
||||||
name,
|
name,
|
||||||
slug,
|
slug,
|
||||||
|
description: readOptionalField(formData, "description"),
|
||||||
|
sortOrder: readNonNegativeInt(formData, "sortOrder"),
|
||||||
|
isVisible: readBooleanField(formData, "isVisible"),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
@@ -144,6 +225,47 @@ async function createGroupAction(formData: FormData) {
|
|||||||
redirectWithState({ notice: `${type} created.` })
|
redirectWithState({ notice: `${type} created.` })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function updateGroupAction(formData: FormData) {
|
||||||
|
"use server"
|
||||||
|
|
||||||
|
await requireWritePermission()
|
||||||
|
|
||||||
|
try {
|
||||||
|
await updateGrouping({
|
||||||
|
groupType: readField(formData, "groupType"),
|
||||||
|
groupId: readField(formData, "groupId"),
|
||||||
|
name: readField(formData, "name"),
|
||||||
|
slug: slugify(readField(formData, "slug")),
|
||||||
|
description: readOptionalNullableField(formData, "description"),
|
||||||
|
sortOrder: readNonNegativeInt(formData, "sortOrder"),
|
||||||
|
isVisible: readBooleanField(formData, "isVisible"),
|
||||||
|
})
|
||||||
|
} catch {
|
||||||
|
redirectWithState({ error: "Failed to update grouping entity." })
|
||||||
|
}
|
||||||
|
|
||||||
|
revalidatePath("/portfolio")
|
||||||
|
redirectWithState({ notice: "Grouping entity updated." })
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteGroupAction(formData: FormData) {
|
||||||
|
"use server"
|
||||||
|
|
||||||
|
await requireWritePermission()
|
||||||
|
|
||||||
|
try {
|
||||||
|
await deleteGrouping({
|
||||||
|
groupType: readField(formData, "groupType"),
|
||||||
|
groupId: readField(formData, "groupId"),
|
||||||
|
})
|
||||||
|
} catch {
|
||||||
|
redirectWithState({ error: "Failed to delete grouping entity." })
|
||||||
|
}
|
||||||
|
|
||||||
|
revalidatePath("/portfolio")
|
||||||
|
redirectWithState({ notice: "Grouping entity deleted." })
|
||||||
|
}
|
||||||
|
|
||||||
async function linkArtworkGroupAction(formData: FormData) {
|
async function linkArtworkGroupAction(formData: FormData) {
|
||||||
"use server"
|
"use server"
|
||||||
|
|
||||||
@@ -195,6 +317,21 @@ async function attachRenditionAction(formData: FormData) {
|
|||||||
redirectWithState({ notice: "Rendition attached." })
|
redirectWithState({ notice: "Rendition attached." })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function deleteRenditionAction(formData: FormData) {
|
||||||
|
"use server"
|
||||||
|
|
||||||
|
await requireWritePermission()
|
||||||
|
|
||||||
|
try {
|
||||||
|
await deleteArtworkRendition(readField(formData, "renditionId"))
|
||||||
|
} catch {
|
||||||
|
redirectWithState({ error: "Failed to delete rendition." })
|
||||||
|
}
|
||||||
|
|
||||||
|
revalidatePath("/portfolio")
|
||||||
|
redirectWithState({ notice: "Rendition deleted." })
|
||||||
|
}
|
||||||
|
|
||||||
export default async function PortfolioPage({
|
export default async function PortfolioPage({
|
||||||
searchParams,
|
searchParams,
|
||||||
}: {
|
}: {
|
||||||
@@ -290,6 +427,26 @@ export default async function PortfolioPage({
|
|||||||
placeholder="Availability"
|
placeholder="Availability"
|
||||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||||
/>
|
/>
|
||||||
|
<div className="grid gap-3 md:grid-cols-3">
|
||||||
|
<input
|
||||||
|
name="priceAmount"
|
||||||
|
type="number"
|
||||||
|
step="0.01"
|
||||||
|
min={0}
|
||||||
|
placeholder="Price amount (e.g. 199.99)"
|
||||||
|
className="rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
name="priceCurrency"
|
||||||
|
maxLength={3}
|
||||||
|
placeholder="Currency (USD)"
|
||||||
|
className="rounded border border-neutral-300 px-3 py-2 text-sm uppercase"
|
||||||
|
/>
|
||||||
|
<label className="flex items-center gap-2 rounded border border-neutral-300 px-3 py-2 text-sm">
|
||||||
|
<input type="checkbox" name="isPriceVisible" />
|
||||||
|
Price visible
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
<Button type="submit">Create artwork</Button>
|
<Button type="submit">Create artwork</Button>
|
||||||
</form>
|
</form>
|
||||||
</section>
|
</section>
|
||||||
@@ -297,7 +454,7 @@ export default async function PortfolioPage({
|
|||||||
<section className="rounded-xl border border-neutral-200 p-6">
|
<section className="rounded-xl border border-neutral-200 p-6">
|
||||||
<h2 className="text-xl font-medium">Create Group Entity</h2>
|
<h2 className="text-xl font-medium">Create Group Entity</h2>
|
||||||
<form action={createGroupAction} className="mt-4 space-y-3">
|
<form action={createGroupAction} className="mt-4 space-y-3">
|
||||||
<div className="grid gap-3 md:grid-cols-3">
|
<div className="grid gap-3 md:grid-cols-5">
|
||||||
<select
|
<select
|
||||||
name="groupType"
|
name="groupType"
|
||||||
defaultValue="gallery"
|
defaultValue="gallery"
|
||||||
@@ -319,6 +476,18 @@ export default async function PortfolioPage({
|
|||||||
placeholder="Slug (optional)"
|
placeholder="Slug (optional)"
|
||||||
className="rounded border border-neutral-300 px-3 py-2 text-sm"
|
className="rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||||
/>
|
/>
|
||||||
|
<input
|
||||||
|
name="sortOrder"
|
||||||
|
type="number"
|
||||||
|
min={0}
|
||||||
|
defaultValue={0}
|
||||||
|
placeholder="Sort order"
|
||||||
|
className="rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||||
|
/>
|
||||||
|
<label className="flex items-center gap-2 rounded border border-neutral-300 px-3 py-2 text-sm">
|
||||||
|
<input type="checkbox" name="isVisible" defaultChecked />
|
||||||
|
Visible
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<textarea
|
<textarea
|
||||||
name="description"
|
name="description"
|
||||||
@@ -330,6 +499,89 @@ export default async function PortfolioPage({
|
|||||||
</form>
|
</form>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<section className="rounded-xl border border-neutral-200 p-6">
|
||||||
|
<h2 className="text-xl font-medium">Manage Group Entities</h2>
|
||||||
|
<div className="mt-4 grid gap-4">
|
||||||
|
{(
|
||||||
|
[
|
||||||
|
{ type: "gallery" as const, label: "Gallery", items: groups.galleries },
|
||||||
|
{ type: "album" as const, label: "Album", items: groups.albums },
|
||||||
|
{ type: "category" as const, label: "Category", items: groups.categories },
|
||||||
|
{ type: "tag" as const, label: "Tag", items: groups.tags },
|
||||||
|
] as const
|
||||||
|
).map((groupConfig) => (
|
||||||
|
<section
|
||||||
|
key={`manage-${groupConfig.type}`}
|
||||||
|
className="rounded border border-neutral-200 p-4"
|
||||||
|
>
|
||||||
|
<h3 className="text-sm font-semibold">{groupConfig.label} Entities</h3>
|
||||||
|
<div className="mt-3 space-y-3">
|
||||||
|
{groupConfig.items.length === 0 ? (
|
||||||
|
<p className="text-xs text-neutral-500">No entities created yet.</p>
|
||||||
|
) : (
|
||||||
|
groupConfig.items.map((group) => (
|
||||||
|
<form
|
||||||
|
key={`manage-${groupConfig.type}-${group.id}`}
|
||||||
|
action={updateGroupAction}
|
||||||
|
className="space-y-3 rounded border border-neutral-200 p-3"
|
||||||
|
>
|
||||||
|
<input type="hidden" name="groupType" value={groupConfig.type} />
|
||||||
|
<input type="hidden" name="groupId" value={group.id} />
|
||||||
|
<div className="grid gap-3 md:grid-cols-2 xl:grid-cols-4">
|
||||||
|
<input
|
||||||
|
name="name"
|
||||||
|
required
|
||||||
|
defaultValue={group.name}
|
||||||
|
className="rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
name="slug"
|
||||||
|
required
|
||||||
|
defaultValue={group.slug}
|
||||||
|
className="rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
name="sortOrder"
|
||||||
|
type="number"
|
||||||
|
min={0}
|
||||||
|
defaultValue={group.sortOrder}
|
||||||
|
className="rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||||
|
/>
|
||||||
|
<label className="flex items-center gap-2 rounded border border-neutral-300 px-3 py-2 text-sm">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
name="isVisible"
|
||||||
|
defaultChecked={group.isVisible}
|
||||||
|
/>
|
||||||
|
Visible
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<textarea
|
||||||
|
name="description"
|
||||||
|
rows={2}
|
||||||
|
defaultValue={group.description ?? ""}
|
||||||
|
placeholder="Description"
|
||||||
|
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||||
|
/>
|
||||||
|
<div className="flex flex-wrap gap-2">
|
||||||
|
<Button type="submit">Save group</Button>
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
formAction={deleteGroupAction}
|
||||||
|
className="rounded border border-red-300 px-3 py-2 text-sm text-red-700 hover:bg-red-50"
|
||||||
|
>
|
||||||
|
Delete group
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
<section className="rounded-xl border border-neutral-200 p-6">
|
<section className="rounded-xl border border-neutral-200 p-6">
|
||||||
<h2 className="text-xl font-medium">Link Artwork To Group</h2>
|
<h2 className="text-xl font-medium">Link Artwork To Group</h2>
|
||||||
<div className="mt-4 grid gap-4 lg:grid-cols-2">
|
<div className="mt-4 grid gap-4 lg:grid-cols-2">
|
||||||
@@ -405,6 +657,7 @@ export default async function PortfolioPage({
|
|||||||
<option value="thumbnail">thumbnail</option>
|
<option value="thumbnail">thumbnail</option>
|
||||||
<option value="card">card</option>
|
<option value="card">card</option>
|
||||||
<option value="full">full</option>
|
<option value="full">full</option>
|
||||||
|
<option value="retina">retina</option>
|
||||||
<option value="custom">custom</option>
|
<option value="custom">custom</option>
|
||||||
</select>
|
</select>
|
||||||
<input
|
<input
|
||||||
@@ -447,14 +700,16 @@ export default async function PortfolioPage({
|
|||||||
<th className="py-2 pr-4">Title</th>
|
<th className="py-2 pr-4">Title</th>
|
||||||
<th className="py-2 pr-4">Slug</th>
|
<th className="py-2 pr-4">Slug</th>
|
||||||
<th className="py-2 pr-4">Published</th>
|
<th className="py-2 pr-4">Published</th>
|
||||||
|
<th className="py-2 pr-4">Refinement</th>
|
||||||
<th className="py-2 pr-4">Renditions</th>
|
<th className="py-2 pr-4">Renditions</th>
|
||||||
<th className="py-2 pr-4">Groups</th>
|
<th className="py-2 pr-4">Groups</th>
|
||||||
|
<th className="py-2 pr-4">Actions</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{artworks.length === 0 ? (
|
{artworks.length === 0 ? (
|
||||||
<tr>
|
<tr>
|
||||||
<td className="py-3 text-neutral-500" colSpan={5}>
|
<td className="py-3 text-neutral-500" colSpan={7}>
|
||||||
No artworks yet. Add creation flows after media upload pipeline lands.
|
No artworks yet. Add creation flows after media upload pipeline lands.
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -464,11 +719,135 @@ export default async function PortfolioPage({
|
|||||||
<td className="py-3 pr-4">{artwork.title}</td>
|
<td className="py-3 pr-4">{artwork.title}</td>
|
||||||
<td className="py-3 pr-4 font-mono text-xs">{artwork.slug}</td>
|
<td className="py-3 pr-4 font-mono text-xs">{artwork.slug}</td>
|
||||||
<td className="py-3 pr-4">{artwork.isPublished ? "yes" : "no"}</td>
|
<td className="py-3 pr-4">{artwork.isPublished ? "yes" : "no"}</td>
|
||||||
<td className="py-3 pr-4">{artwork.renditions.length}</td>
|
<td className="py-3 pr-4 text-xs text-neutral-600">
|
||||||
|
{artwork.medium ? `medium: ${artwork.medium}` : "medium: -"}
|
||||||
|
<br />
|
||||||
|
{artwork.dimensions ? `dimensions: ${artwork.dimensions}` : "dimensions: -"}
|
||||||
|
<br />
|
||||||
|
{artwork.year ? `year: ${artwork.year}` : "year: -"}
|
||||||
|
<br />
|
||||||
|
{artwork.framing ? `framing: ${artwork.framing}` : "framing: -"}
|
||||||
|
<br />
|
||||||
|
{artwork.availability
|
||||||
|
? `availability: ${artwork.availability}`
|
||||||
|
: "availability: -"}
|
||||||
|
<br />
|
||||||
|
{artwork.priceAmountCents && artwork.priceCurrency
|
||||||
|
? `price: ${(artwork.priceAmountCents / 100).toFixed(2)} ${artwork.priceCurrency} (${artwork.isPriceVisible ? "visible" : "hidden"})`
|
||||||
|
: "price: -"}
|
||||||
|
</td>
|
||||||
|
<td className="py-3 pr-4">
|
||||||
|
<div className="space-y-1">
|
||||||
|
{artwork.renditions.length === 0 ? (
|
||||||
|
<span className="text-xs text-neutral-500">0</span>
|
||||||
|
) : (
|
||||||
|
artwork.renditions.map((rendition) => (
|
||||||
|
<form
|
||||||
|
key={rendition.id}
|
||||||
|
action={deleteRenditionAction}
|
||||||
|
className="flex items-center gap-2 text-xs"
|
||||||
|
>
|
||||||
|
<input type="hidden" name="renditionId" value={rendition.id} />
|
||||||
|
<span className="rounded bg-neutral-100 px-2 py-1 font-mono">
|
||||||
|
{rendition.slot}
|
||||||
|
</span>
|
||||||
|
<span className="text-neutral-500">
|
||||||
|
{rendition.width ?? "-"}x{rendition.height ?? "-"}
|
||||||
|
</span>
|
||||||
|
{rendition.isPrimary ? (
|
||||||
|
<span className="rounded bg-emerald-100 px-2 py-1 text-emerald-700">
|
||||||
|
primary
|
||||||
|
</span>
|
||||||
|
) : null}
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
className="rounded border border-red-300 px-2 py-1 text-red-700 hover:bg-red-50"
|
||||||
|
>
|
||||||
|
delete
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
<td className="py-3 pr-4 text-neutral-600">
|
<td className="py-3 pr-4 text-neutral-600">
|
||||||
g:{artwork.galleryLinks.length} a:{artwork.albumLinks.length} c:
|
g:{artwork.galleryLinks.length} a:{artwork.albumLinks.length} c:
|
||||||
{artwork.categoryLinks.length} t:{artwork.tagLinks.length}
|
{artwork.categoryLinks.length} t:{artwork.tagLinks.length}
|
||||||
</td>
|
</td>
|
||||||
|
<td className="py-3 pr-4">
|
||||||
|
<form action={updateArtworkAction} className="grid min-w-80 gap-2">
|
||||||
|
<input type="hidden" name="artworkId" value={artwork.id} />
|
||||||
|
<input
|
||||||
|
name="medium"
|
||||||
|
defaultValue={artwork.medium ?? ""}
|
||||||
|
placeholder="Medium"
|
||||||
|
className="rounded border border-neutral-300 px-2 py-1 text-xs"
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
name="dimensions"
|
||||||
|
defaultValue={artwork.dimensions ?? ""}
|
||||||
|
placeholder="Dimensions"
|
||||||
|
className="rounded border border-neutral-300 px-2 py-1 text-xs"
|
||||||
|
/>
|
||||||
|
<div className="grid grid-cols-2 gap-2">
|
||||||
|
<input
|
||||||
|
name="year"
|
||||||
|
type="number"
|
||||||
|
defaultValue={artwork.year ?? ""}
|
||||||
|
placeholder="Year"
|
||||||
|
className="rounded border border-neutral-300 px-2 py-1 text-xs"
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
name="framing"
|
||||||
|
defaultValue={artwork.framing ?? ""}
|
||||||
|
placeholder="Framing"
|
||||||
|
className="rounded border border-neutral-300 px-2 py-1 text-xs"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<input
|
||||||
|
name="availability"
|
||||||
|
defaultValue={artwork.availability ?? ""}
|
||||||
|
placeholder="Availability"
|
||||||
|
className="rounded border border-neutral-300 px-2 py-1 text-xs"
|
||||||
|
/>
|
||||||
|
<div className="grid grid-cols-2 gap-2">
|
||||||
|
<input
|
||||||
|
name="priceAmountCents"
|
||||||
|
type="number"
|
||||||
|
min={0}
|
||||||
|
defaultValue={artwork.priceAmountCents ?? ""}
|
||||||
|
placeholder="Price cents"
|
||||||
|
className="rounded border border-neutral-300 px-2 py-1 text-xs"
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
name="priceCurrency"
|
||||||
|
maxLength={3}
|
||||||
|
defaultValue={artwork.priceCurrency ?? ""}
|
||||||
|
placeholder="USD"
|
||||||
|
className="rounded border border-neutral-300 px-2 py-1 text-xs uppercase"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-3 text-xs">
|
||||||
|
<label className="inline-flex items-center gap-1">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
name="isPriceVisible"
|
||||||
|
defaultChecked={artwork.isPriceVisible}
|
||||||
|
/>
|
||||||
|
price visible
|
||||||
|
</label>
|
||||||
|
<label className="inline-flex items-center gap-1">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
name="isPublished"
|
||||||
|
defaultChecked={artwork.isPublished}
|
||||||
|
/>
|
||||||
|
published
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<Button type="submit">Save</Button>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
))
|
))
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,34 +1,425 @@
|
|||||||
import { AdminSectionPlaceholder } from "@/components/admin-section-placeholder"
|
import { hasPermission, normalizeRole, type Role } from "@cms/content/rbac"
|
||||||
|
import { db } from "@cms/db"
|
||||||
|
import { Button } from "@cms/ui/button"
|
||||||
|
import { revalidatePath } from "next/cache"
|
||||||
|
import { headers } from "next/headers"
|
||||||
|
import { redirect } from "next/navigation"
|
||||||
|
|
||||||
import { AdminShell } from "@/components/admin-shell"
|
import { AdminShell } from "@/components/admin-shell"
|
||||||
|
import {
|
||||||
|
auth,
|
||||||
|
canDeleteUserAccount,
|
||||||
|
createManagedUserAccount,
|
||||||
|
enforceOwnerInvariant,
|
||||||
|
} from "@/lib/auth/server"
|
||||||
import { requirePermissionForRoute } from "@/lib/route-guards"
|
import { requirePermissionForRoute } from "@/lib/route-guards"
|
||||||
|
|
||||||
export const dynamic = "force-dynamic"
|
export const dynamic = "force-dynamic"
|
||||||
|
|
||||||
export default async function UsersManagementPage() {
|
const MANAGED_ROLES: Role[] = ["admin", "editor", "manager"]
|
||||||
|
|
||||||
|
type SearchParamsInput = Record<string, string | string[] | undefined>
|
||||||
|
|
||||||
|
function readFirstValue(value: string | string[] | undefined): string | null {
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
return value[0] ?? null
|
||||||
|
}
|
||||||
|
|
||||||
|
return value ?? null
|
||||||
|
}
|
||||||
|
|
||||||
|
function readInputString(formData: FormData, field: string): string {
|
||||||
|
const value = formData.get(field)
|
||||||
|
return typeof value === "string" ? value.trim() : ""
|
||||||
|
}
|
||||||
|
|
||||||
|
function redirectWithState(params: { notice?: string; error?: string }) {
|
||||||
|
const query = new URLSearchParams()
|
||||||
|
|
||||||
|
if (params.notice) {
|
||||||
|
query.set("notice", params.notice)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (params.error) {
|
||||||
|
query.set("error", params.error)
|
||||||
|
}
|
||||||
|
|
||||||
|
const value = query.toString()
|
||||||
|
redirect(value ? `/users?${value}` : "/users")
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createUserAction(formData: FormData) {
|
||||||
|
"use server"
|
||||||
|
|
||||||
|
await requirePermissionForRoute({
|
||||||
|
nextPath: "/users",
|
||||||
|
permission: "users:write",
|
||||||
|
scope: "team",
|
||||||
|
})
|
||||||
|
|
||||||
|
const role = normalizeRole(readInputString(formData, "role"))
|
||||||
|
|
||||||
|
if (!role || !MANAGED_ROLES.includes(role)) {
|
||||||
|
return redirectWithState({ error: "Invalid role for managed user creation." })
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await createManagedUserAccount({
|
||||||
|
email: readInputString(formData, "email"),
|
||||||
|
username: readInputString(formData, "username") || undefined,
|
||||||
|
name: readInputString(formData, "name"),
|
||||||
|
password: readInputString(formData, "password"),
|
||||||
|
role,
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
const message = error instanceof Error ? error.message : "Failed to create user."
|
||||||
|
redirectWithState({ error: message })
|
||||||
|
}
|
||||||
|
|
||||||
|
revalidatePath("/users")
|
||||||
|
redirectWithState({ notice: "User account created." })
|
||||||
|
}
|
||||||
|
|
||||||
|
async function updateUserRoleAction(formData: FormData) {
|
||||||
|
"use server"
|
||||||
|
|
||||||
|
await requirePermissionForRoute({
|
||||||
|
nextPath: "/users",
|
||||||
|
permission: "users:manage_roles",
|
||||||
|
scope: "global",
|
||||||
|
})
|
||||||
|
|
||||||
|
const userId = readInputString(formData, "userId")
|
||||||
|
const role = normalizeRole(readInputString(formData, "role"))
|
||||||
|
|
||||||
|
if (!role || !MANAGED_ROLES.includes(role)) {
|
||||||
|
return redirectWithState({ error: "Only admin/editor/manager can be assigned here." })
|
||||||
|
}
|
||||||
|
|
||||||
|
const user = await db.user.findUnique({
|
||||||
|
where: { id: userId },
|
||||||
|
select: { id: true, isProtected: true, isSystem: true },
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!user) {
|
||||||
|
return redirectWithState({ error: "User not found." })
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user.isProtected || user.isSystem) {
|
||||||
|
return redirectWithState({ error: "Protected/system users cannot be role-edited." })
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await db.user.update({
|
||||||
|
where: { id: userId },
|
||||||
|
data: { role },
|
||||||
|
})
|
||||||
|
await enforceOwnerInvariant()
|
||||||
|
} catch {
|
||||||
|
redirectWithState({ error: "Failed to update user role." })
|
||||||
|
}
|
||||||
|
|
||||||
|
revalidatePath("/users")
|
||||||
|
redirectWithState({ notice: "User role updated." })
|
||||||
|
}
|
||||||
|
|
||||||
|
async function updateUserBanAction(formData: FormData) {
|
||||||
|
"use server"
|
||||||
|
|
||||||
|
await requirePermissionForRoute({
|
||||||
|
nextPath: "/users",
|
||||||
|
permission: "users:write",
|
||||||
|
scope: "team",
|
||||||
|
})
|
||||||
|
|
||||||
|
const userId = readInputString(formData, "userId")
|
||||||
|
const isBanned = readInputString(formData, "isBanned") === "true"
|
||||||
|
|
||||||
|
const user = await db.user.findUnique({
|
||||||
|
where: { id: userId },
|
||||||
|
select: { id: true, isProtected: true, isSystem: true },
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!user) {
|
||||||
|
return redirectWithState({ error: "User not found." })
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((user.isProtected || user.isSystem) && isBanned) {
|
||||||
|
return redirectWithState({ error: "Protected/system users cannot be banned." })
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await db.user.update({
|
||||||
|
where: { id: userId },
|
||||||
|
data: { isBanned },
|
||||||
|
})
|
||||||
|
await enforceOwnerInvariant()
|
||||||
|
} catch {
|
||||||
|
redirectWithState({ error: "Failed to update user status." })
|
||||||
|
}
|
||||||
|
|
||||||
|
revalidatePath("/users")
|
||||||
|
redirectWithState({ notice: isBanned ? "User banned." : "User unbanned." })
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteUserAction(formData: FormData) {
|
||||||
|
"use server"
|
||||||
|
|
||||||
|
await requirePermissionForRoute({
|
||||||
|
nextPath: "/users",
|
||||||
|
permission: "users:write",
|
||||||
|
scope: "team",
|
||||||
|
})
|
||||||
|
|
||||||
|
const userId = readInputString(formData, "userId")
|
||||||
|
const isAllowed = await canDeleteUserAccount(userId)
|
||||||
|
|
||||||
|
if (!isAllowed) {
|
||||||
|
return redirectWithState({
|
||||||
|
error: "User cannot be deleted due to protection or owner constraints.",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await db.user.delete({
|
||||||
|
where: { id: userId },
|
||||||
|
})
|
||||||
|
await enforceOwnerInvariant()
|
||||||
|
} catch {
|
||||||
|
redirectWithState({ error: "Failed to delete user." })
|
||||||
|
}
|
||||||
|
|
||||||
|
revalidatePath("/users")
|
||||||
|
redirectWithState({ notice: "User deleted." })
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function UsersManagementPage({
|
||||||
|
searchParams,
|
||||||
|
}: {
|
||||||
|
searchParams: Promise<SearchParamsInput>
|
||||||
|
}) {
|
||||||
const role = await requirePermissionForRoute({
|
const role = await requirePermissionForRoute({
|
||||||
nextPath: "/users",
|
nextPath: "/users",
|
||||||
permission: "users:read",
|
permission: "users:read",
|
||||||
scope: "own",
|
scope: "own",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const session = await auth.api
|
||||||
|
.getSession({
|
||||||
|
headers: await headers(),
|
||||||
|
})
|
||||||
|
.catch(() => null)
|
||||||
|
const viewerId = session?.user?.id ?? null
|
||||||
|
const canWriteUsers = hasPermission(role, "users:write", "team")
|
||||||
|
const canManageRoles = hasPermission(role, "users:manage_roles", "global")
|
||||||
|
const canReadGlobal = hasPermission(role, "users:read", "global")
|
||||||
|
|
||||||
|
const [resolvedSearchParams, users] = await Promise.all([
|
||||||
|
searchParams,
|
||||||
|
db.user.findMany({
|
||||||
|
where: canReadGlobal
|
||||||
|
? undefined
|
||||||
|
: viewerId
|
||||||
|
? {
|
||||||
|
id: viewerId,
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
id: "__none__",
|
||||||
|
},
|
||||||
|
orderBy: [{ createdAt: "desc" }],
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
email: true,
|
||||||
|
username: true,
|
||||||
|
name: true,
|
||||||
|
role: true,
|
||||||
|
isBanned: true,
|
||||||
|
isSystem: true,
|
||||||
|
isHidden: true,
|
||||||
|
isProtected: true,
|
||||||
|
createdAt: true,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
|
||||||
|
const notice = readFirstValue(resolvedSearchParams.notice)
|
||||||
|
const error = readFirstValue(resolvedSearchParams.error)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AdminShell
|
<AdminShell
|
||||||
role={role}
|
role={role}
|
||||||
activePath="/users"
|
activePath="/users"
|
||||||
badge="Admin App"
|
badge="Admin App"
|
||||||
title="Users"
|
title="Users"
|
||||||
description="Prepare user lifecycle and role management operations."
|
description="Manage internal users, roles, and account status."
|
||||||
>
|
>
|
||||||
<AdminSectionPlaceholder
|
{notice ? (
|
||||||
feature="Users Management"
|
<section className="rounded-xl border border-emerald-300 bg-emerald-50 px-4 py-3 text-sm text-emerald-800">
|
||||||
summary="This route sets the guardrail and UX entrypoint for role assignment, status, and invitation flows."
|
{notice}
|
||||||
requiredPermission="users:read (own)"
|
</section>
|
||||||
nextSteps={[
|
) : null}
|
||||||
"Add user list, filter, and detail views.",
|
{error ? (
|
||||||
"Add role and permission editing actions with owner/support safety rules.",
|
<section className="rounded-xl border border-red-300 bg-red-50 px-4 py-3 text-sm text-red-800">
|
||||||
"Add disable/ban and invite workflows.",
|
{error}
|
||||||
]}
|
</section>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{canWriteUsers ? (
|
||||||
|
<section className="rounded-xl border border-neutral-200 p-6">
|
||||||
|
<h2 className="text-xl font-medium">Create managed user</h2>
|
||||||
|
<form action={createUserAction} className="mt-4 grid gap-3 md:grid-cols-2 lg:grid-cols-3">
|
||||||
|
<input
|
||||||
|
name="name"
|
||||||
|
required
|
||||||
|
placeholder="Name"
|
||||||
|
className="rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||||
/>
|
/>
|
||||||
|
<input
|
||||||
|
name="email"
|
||||||
|
required
|
||||||
|
type="email"
|
||||||
|
placeholder="Email"
|
||||||
|
className="rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
name="username"
|
||||||
|
placeholder="Username (optional)"
|
||||||
|
className="rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
name="password"
|
||||||
|
required
|
||||||
|
type="password"
|
||||||
|
placeholder="Temporary password"
|
||||||
|
className="rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||||
|
/>
|
||||||
|
<select
|
||||||
|
name="role"
|
||||||
|
defaultValue="editor"
|
||||||
|
className="rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||||
|
>
|
||||||
|
<option value="editor">editor</option>
|
||||||
|
<option value="manager">manager</option>
|
||||||
|
<option value="admin">admin</option>
|
||||||
|
</select>
|
||||||
|
<div className="md:col-span-2 lg:col-span-3">
|
||||||
|
<Button type="submit">Create user</Button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
<section className="rounded-xl border border-neutral-200 p-6">
|
||||||
|
<h2 className="text-xl font-medium">User accounts</h2>
|
||||||
|
<div className="mt-4 overflow-x-auto">
|
||||||
|
<table className="min-w-full text-left text-sm">
|
||||||
|
<thead className="text-xs uppercase tracking-wide text-neutral-500">
|
||||||
|
<tr>
|
||||||
|
<th className="py-2 pr-4">User</th>
|
||||||
|
<th className="py-2 pr-4">Role</th>
|
||||||
|
<th className="py-2 pr-4">Status</th>
|
||||||
|
<th className="py-2 pr-4">Flags</th>
|
||||||
|
<th className="py-2 pr-4">Created</th>
|
||||||
|
<th className="py-2 pr-4">Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{users.length === 0 ? (
|
||||||
|
<tr>
|
||||||
|
<td className="py-3 text-neutral-500" colSpan={6}>
|
||||||
|
No users found.
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
) : (
|
||||||
|
users.map((user) => (
|
||||||
|
<tr key={user.id} className="border-t border-neutral-200 align-top">
|
||||||
|
<td className="py-3 pr-4">
|
||||||
|
<p className="font-medium">{user.name}</p>
|
||||||
|
<p className="text-xs text-neutral-600">{user.email}</p>
|
||||||
|
<p className="text-xs text-neutral-500">@{user.username ?? "no-username"}</p>
|
||||||
|
</td>
|
||||||
|
<td className="py-3 pr-4">{user.role}</td>
|
||||||
|
<td className="py-3 pr-4">{user.isBanned ? "banned" : "active"}</td>
|
||||||
|
<td className="py-3 pr-4 text-xs text-neutral-600">
|
||||||
|
{user.isProtected ? "protected " : ""}
|
||||||
|
{user.isSystem ? "system " : ""}
|
||||||
|
{user.isHidden ? "hidden" : ""}
|
||||||
|
</td>
|
||||||
|
<td className="py-3 pr-4 text-xs text-neutral-600">
|
||||||
|
{user.createdAt.toLocaleString("en-US")}
|
||||||
|
</td>
|
||||||
|
<td className="py-3 pr-4">
|
||||||
|
<div className="grid min-w-56 gap-2">
|
||||||
|
{canManageRoles ? (
|
||||||
|
<form action={updateUserRoleAction} className="flex gap-2">
|
||||||
|
<input type="hidden" name="userId" value={user.id} />
|
||||||
|
<select
|
||||||
|
name="role"
|
||||||
|
defaultValue={
|
||||||
|
MANAGED_ROLES.includes(user.role as Role) ? user.role : "editor"
|
||||||
|
}
|
||||||
|
disabled={user.isProtected || user.isSystem}
|
||||||
|
className="w-full rounded border border-neutral-300 px-2 py-1 text-xs"
|
||||||
|
>
|
||||||
|
<option value="editor">editor</option>
|
||||||
|
<option value="manager">manager</option>
|
||||||
|
<option value="admin">admin</option>
|
||||||
|
</select>
|
||||||
|
<Button
|
||||||
|
type="submit"
|
||||||
|
size="sm"
|
||||||
|
variant="secondary"
|
||||||
|
disabled={user.isProtected || user.isSystem}
|
||||||
|
>
|
||||||
|
Role
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{canWriteUsers ? (
|
||||||
|
<form action={updateUserBanAction} className="flex gap-2">
|
||||||
|
<input type="hidden" name="userId" value={user.id} />
|
||||||
|
<select
|
||||||
|
name="isBanned"
|
||||||
|
defaultValue={user.isBanned ? "true" : "false"}
|
||||||
|
disabled={user.isProtected || user.isSystem}
|
||||||
|
className="w-full rounded border border-neutral-300 px-2 py-1 text-xs"
|
||||||
|
>
|
||||||
|
<option value="false">active</option>
|
||||||
|
<option value="true">banned</option>
|
||||||
|
</select>
|
||||||
|
<Button
|
||||||
|
type="submit"
|
||||||
|
size="sm"
|
||||||
|
variant="secondary"
|
||||||
|
disabled={user.isProtected || user.isSystem}
|
||||||
|
>
|
||||||
|
Status
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{canWriteUsers ? (
|
||||||
|
<form action={deleteUserAction}>
|
||||||
|
<input type="hidden" name="userId" value={user.id} />
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
disabled={user.isProtected || user.isSystem}
|
||||||
|
className="rounded border border-red-300 px-3 py-1.5 text-xs text-red-700 disabled:cursor-not-allowed disabled:opacity-50"
|
||||||
|
>
|
||||||
|
Delete user
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
</AdminShell>
|
</AdminShell>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -149,6 +149,52 @@ export function MediaUploadForm() {
|
|||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="grid gap-3 md:grid-cols-2">
|
||||||
|
<label className="space-y-1">
|
||||||
|
<span className="text-xs text-neutral-600">License type</span>
|
||||||
|
<input
|
||||||
|
name="licenseType"
|
||||||
|
placeholder="e.g. CC BY-NC 4.0"
|
||||||
|
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label className="space-y-1">
|
||||||
|
<span className="text-xs text-neutral-600">License URL</span>
|
||||||
|
<input
|
||||||
|
name="licenseUrl"
|
||||||
|
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid gap-3 md:grid-cols-2">
|
||||||
|
<label className="space-y-1">
|
||||||
|
<span className="text-xs text-neutral-600">Usage context</span>
|
||||||
|
<input
|
||||||
|
name="usageContext"
|
||||||
|
placeholder="e.g. homepage hero, social preview"
|
||||||
|
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label className="space-y-1">
|
||||||
|
<span className="text-xs text-neutral-600">Location</span>
|
||||||
|
<input
|
||||||
|
name="location"
|
||||||
|
placeholder="e.g. Berlin studio"
|
||||||
|
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<label className="space-y-1">
|
||||||
|
<span className="text-xs text-neutral-600">Captured at</span>
|
||||||
|
<input
|
||||||
|
name="capturedAt"
|
||||||
|
type="datetime-local"
|
||||||
|
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
<label className="space-y-1">
|
<label className="space-y-1">
|
||||||
<span className="text-xs text-neutral-600">Tags (comma-separated)</span>
|
<span className="text-xs text-neutral-600">Tags (comma-separated)</span>
|
||||||
<input name="tags" className="w-full rounded border border-neutral-300 px-3 py-2 text-sm" />
|
<input name="tags" className="w-full rounded border border-neutral-300 px-3 py-2 text-sm" />
|
||||||
|
|||||||
@@ -11,7 +11,9 @@ describe("CreatePageForm", () => {
|
|||||||
|
|
||||||
expect((screen.getByLabelText("Title") as HTMLInputElement).name).toBe("title")
|
expect((screen.getByLabelText("Title") as HTMLInputElement).name).toBe("title")
|
||||||
expect((screen.getByLabelText("Slug") as HTMLInputElement).name).toBe("slug")
|
expect((screen.getByLabelText("Slug") as HTMLInputElement).name).toBe("slug")
|
||||||
expect((screen.getByLabelText("Content") as HTMLTextAreaElement).name).toBe("content")
|
const contentField = document.querySelector('input[name="content"]') as HTMLInputElement | null
|
||||||
|
expect(contentField).not.toBeNull()
|
||||||
|
expect(contentField?.value.startsWith("[")).toBe(true)
|
||||||
|
|
||||||
const status = screen.getByLabelText("Status") as HTMLSelectElement
|
const status = screen.getByLabelText("Status") as HTMLSelectElement
|
||||||
expect(status.value).toBe("draft")
|
expect(status.value).toBe("draft")
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
|
import { serializePageBlocks } from "@cms/content"
|
||||||
import { Button } from "@cms/ui/button"
|
import { Button } from "@cms/ui/button"
|
||||||
|
|
||||||
|
import { PageBlockEditor } from "./page-block-editor"
|
||||||
|
|
||||||
type CreatePageFormProps = {
|
type CreatePageFormProps = {
|
||||||
action: (formData: FormData) => void | Promise<void>
|
action: (formData: FormData) => void | Promise<void>
|
||||||
}
|
}
|
||||||
@@ -46,15 +49,16 @@ export function CreatePageForm({ action }: CreatePageFormProps) {
|
|||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<label className="space-y-1">
|
<PageBlockEditor
|
||||||
<span className="text-xs text-neutral-600">Content</span>
|
|
||||||
<textarea
|
|
||||||
name="content"
|
name="content"
|
||||||
rows={6}
|
initialContent={serializePageBlocks([
|
||||||
required
|
{
|
||||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
id: "initial-rich-text",
|
||||||
|
type: "rich_text",
|
||||||
|
body: "",
|
||||||
|
},
|
||||||
|
])}
|
||||||
/>
|
/>
|
||||||
</label>
|
|
||||||
|
|
||||||
<div className="grid gap-3 md:grid-cols-2">
|
<div className="grid gap-3 md:grid-cols-2">
|
||||||
<label className="space-y-1">
|
<label className="space-y-1">
|
||||||
|
|||||||
410
apps/admin/src/components/pages/page-block-editor.tsx
Normal file
410
apps/admin/src/components/pages/page-block-editor.tsx
Normal file
@@ -0,0 +1,410 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { type PageBlock, type PageBlocks, parsePageBlocks, serializePageBlocks } from "@cms/content"
|
||||||
|
import { useMemo, useState } from "react"
|
||||||
|
|
||||||
|
type PageBlockEditorProps = {
|
||||||
|
name: string
|
||||||
|
initialContent: string
|
||||||
|
label?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
function randomId(prefix: string): string {
|
||||||
|
return `${prefix}-${Math.random().toString(36).slice(2, 10)}`
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeInitialBlocks(initialContent: string): PageBlocks {
|
||||||
|
if (!initialContent.trim()) {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
id: randomId("rich"),
|
||||||
|
type: "rich_text",
|
||||||
|
body: "",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return parsePageBlocks(initialContent)
|
||||||
|
} catch {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
id: randomId("rich"),
|
||||||
|
type: "rich_text",
|
||||||
|
body: initialContent,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateBlock(blocks: PageBlocks, blockId: string, next: Partial<PageBlock>): PageBlocks {
|
||||||
|
return blocks.map((block) =>
|
||||||
|
block.id === blockId ? ({ ...block, ...next } as PageBlock) : block,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function moveBlock(blocks: PageBlocks, blockId: string, direction: "up" | "down"): PageBlocks {
|
||||||
|
const index = blocks.findIndex((entry) => entry.id === blockId)
|
||||||
|
|
||||||
|
if (index < 0) {
|
||||||
|
return blocks
|
||||||
|
}
|
||||||
|
|
||||||
|
const nextIndex = direction === "up" ? index - 1 : index + 1
|
||||||
|
if (nextIndex < 0 || nextIndex >= blocks.length) {
|
||||||
|
return blocks
|
||||||
|
}
|
||||||
|
|
||||||
|
const next = [...blocks]
|
||||||
|
const current = next[index]
|
||||||
|
next[index] = next[nextIndex]
|
||||||
|
next[nextIndex] = current
|
||||||
|
return next
|
||||||
|
}
|
||||||
|
|
||||||
|
export function PageBlockEditor({
|
||||||
|
name,
|
||||||
|
initialContent,
|
||||||
|
label = "Page Blocks",
|
||||||
|
}: PageBlockEditorProps) {
|
||||||
|
const [blocks, setBlocks] = useState<PageBlocks>(() => normalizeInitialBlocks(initialContent))
|
||||||
|
|
||||||
|
const serialized = useMemo(() => serializePageBlocks(blocks), [blocks])
|
||||||
|
|
||||||
|
function addBlock(type: PageBlock["type"]) {
|
||||||
|
if (type === "hero") {
|
||||||
|
setBlocks((prev) => [
|
||||||
|
...prev,
|
||||||
|
{
|
||||||
|
id: randomId("hero"),
|
||||||
|
type,
|
||||||
|
heading: "Hero heading",
|
||||||
|
subheading: null,
|
||||||
|
ctaHref: null,
|
||||||
|
ctaLabel: null,
|
||||||
|
},
|
||||||
|
])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === "rich_text") {
|
||||||
|
setBlocks((prev) => [...prev, { id: randomId("rich"), type, body: "" }])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === "gallery") {
|
||||||
|
setBlocks((prev) => [...prev, { id: randomId("gallery"), type, title: null, imageIds: [] }])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === "cta") {
|
||||||
|
setBlocks((prev) => [
|
||||||
|
...prev,
|
||||||
|
{ id: randomId("cta"), type, label: "Open", href: "/", variant: "primary" },
|
||||||
|
])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === "form") {
|
||||||
|
setBlocks((prev) => [
|
||||||
|
...prev,
|
||||||
|
{ id: randomId("form"), type, formKey: "contact", title: null, description: null },
|
||||||
|
])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
setBlocks((prev) => [
|
||||||
|
...prev,
|
||||||
|
{ id: randomId("price"), type: "price_cards", title: null, cards: [] },
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-3 rounded border border-neutral-200 p-3">
|
||||||
|
<input type="hidden" name={name} value={serialized} />
|
||||||
|
<div className="flex flex-wrap items-center gap-2">
|
||||||
|
<span className="text-xs text-neutral-600">{label}</span>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="rounded border px-2 py-1 text-xs"
|
||||||
|
onClick={() => addBlock("hero")}
|
||||||
|
>
|
||||||
|
+ Hero
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="rounded border px-2 py-1 text-xs"
|
||||||
|
onClick={() => addBlock("rich_text")}
|
||||||
|
>
|
||||||
|
+ Rich text
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="rounded border px-2 py-1 text-xs"
|
||||||
|
onClick={() => addBlock("gallery")}
|
||||||
|
>
|
||||||
|
+ Gallery
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="rounded border px-2 py-1 text-xs"
|
||||||
|
onClick={() => addBlock("cta")}
|
||||||
|
>
|
||||||
|
+ CTA
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="rounded border px-2 py-1 text-xs"
|
||||||
|
onClick={() => addBlock("form")}
|
||||||
|
>
|
||||||
|
+ Form
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="rounded border px-2 py-1 text-xs"
|
||||||
|
onClick={() => addBlock("price_cards")}
|
||||||
|
>
|
||||||
|
+ Price cards
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-3">
|
||||||
|
{blocks.map((block, index) => (
|
||||||
|
<article key={block.id} className="space-y-2 rounded border border-neutral-200 p-3">
|
||||||
|
<div className="flex items-center justify-between text-xs text-neutral-600">
|
||||||
|
<span>
|
||||||
|
#{index + 1} {block.type}
|
||||||
|
</span>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="rounded border px-2 py-1"
|
||||||
|
onClick={() => setBlocks((prev) => moveBlock(prev, block.id, "up"))}
|
||||||
|
>
|
||||||
|
Up
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="rounded border px-2 py-1"
|
||||||
|
onClick={() => setBlocks((prev) => moveBlock(prev, block.id, "down"))}
|
||||||
|
>
|
||||||
|
Down
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="rounded border px-2 py-1"
|
||||||
|
onClick={() => setBlocks((prev) => prev.filter((entry) => entry.id !== block.id))}
|
||||||
|
>
|
||||||
|
Remove
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{block.type === "hero" ? (
|
||||||
|
<div className="grid gap-2 md:grid-cols-2">
|
||||||
|
<input
|
||||||
|
value={block.heading}
|
||||||
|
onChange={(event) =>
|
||||||
|
setBlocks((prev) =>
|
||||||
|
updateBlock(prev, block.id, { heading: event.target.value }),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
placeholder="Heading"
|
||||||
|
className="rounded border border-neutral-300 px-2 py-1 text-sm"
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
value={block.subheading ?? ""}
|
||||||
|
onChange={(event) =>
|
||||||
|
setBlocks((prev) =>
|
||||||
|
updateBlock(prev, block.id, { subheading: event.target.value || null }),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
placeholder="Subheading"
|
||||||
|
className="rounded border border-neutral-300 px-2 py-1 text-sm"
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
value={block.ctaLabel ?? ""}
|
||||||
|
onChange={(event) =>
|
||||||
|
setBlocks((prev) =>
|
||||||
|
updateBlock(prev, block.id, { ctaLabel: event.target.value || null }),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
placeholder="CTA label"
|
||||||
|
className="rounded border border-neutral-300 px-2 py-1 text-sm"
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
value={block.ctaHref ?? ""}
|
||||||
|
onChange={(event) =>
|
||||||
|
setBlocks((prev) =>
|
||||||
|
updateBlock(prev, block.id, { ctaHref: event.target.value || null }),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
placeholder="CTA href"
|
||||||
|
className="rounded border border-neutral-300 px-2 py-1 text-sm"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{block.type === "rich_text" ? (
|
||||||
|
<textarea
|
||||||
|
rows={5}
|
||||||
|
value={block.body}
|
||||||
|
onChange={(event) =>
|
||||||
|
setBlocks((prev) => updateBlock(prev, block.id, { body: event.target.value }))
|
||||||
|
}
|
||||||
|
placeholder="Text"
|
||||||
|
className="w-full rounded border border-neutral-300 px-2 py-1 text-sm"
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{block.type === "gallery" ? (
|
||||||
|
<div className="space-y-2">
|
||||||
|
<input
|
||||||
|
value={block.title ?? ""}
|
||||||
|
onChange={(event) =>
|
||||||
|
setBlocks((prev) =>
|
||||||
|
updateBlock(prev, block.id, { title: event.target.value || null }),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
placeholder="Gallery title"
|
||||||
|
className="w-full rounded border border-neutral-300 px-2 py-1 text-sm"
|
||||||
|
/>
|
||||||
|
<textarea
|
||||||
|
rows={3}
|
||||||
|
value={block.imageIds.join(",")}
|
||||||
|
onChange={(event) =>
|
||||||
|
setBlocks((prev) =>
|
||||||
|
updateBlock(prev, block.id, {
|
||||||
|
imageIds: event.target.value
|
||||||
|
.split(",")
|
||||||
|
.map((entry) => entry.trim())
|
||||||
|
.filter((entry) => entry.length > 0),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
placeholder="Media asset IDs (comma separated UUIDs)"
|
||||||
|
className="w-full rounded border border-neutral-300 px-2 py-1 text-sm"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{block.type === "cta" ? (
|
||||||
|
<div className="grid gap-2 md:grid-cols-2">
|
||||||
|
<input
|
||||||
|
value={block.label}
|
||||||
|
onChange={(event) =>
|
||||||
|
setBlocks((prev) => updateBlock(prev, block.id, { label: event.target.value }))
|
||||||
|
}
|
||||||
|
placeholder="Button label"
|
||||||
|
className="rounded border border-neutral-300 px-2 py-1 text-sm"
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
value={block.href}
|
||||||
|
onChange={(event) =>
|
||||||
|
setBlocks((prev) => updateBlock(prev, block.id, { href: event.target.value }))
|
||||||
|
}
|
||||||
|
placeholder="Link href"
|
||||||
|
className="rounded border border-neutral-300 px-2 py-1 text-sm"
|
||||||
|
/>
|
||||||
|
<select
|
||||||
|
value={block.variant}
|
||||||
|
onChange={(event) =>
|
||||||
|
setBlocks((prev) =>
|
||||||
|
updateBlock(prev, block.id, {
|
||||||
|
variant: event.target.value as "primary" | "secondary",
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
className="rounded border border-neutral-300 px-2 py-1 text-sm"
|
||||||
|
>
|
||||||
|
<option value="primary">Primary</option>
|
||||||
|
<option value="secondary">Secondary</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{block.type === "form" ? (
|
||||||
|
<div className="space-y-2">
|
||||||
|
<input
|
||||||
|
value={block.formKey}
|
||||||
|
onChange={(event) =>
|
||||||
|
setBlocks((prev) =>
|
||||||
|
updateBlock(prev, block.id, { formKey: event.target.value }),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
placeholder="Form key (e.g. contact, commission)"
|
||||||
|
className="w-full rounded border border-neutral-300 px-2 py-1 text-sm"
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
value={block.title ?? ""}
|
||||||
|
onChange={(event) =>
|
||||||
|
setBlocks((prev) =>
|
||||||
|
updateBlock(prev, block.id, { title: event.target.value || null }),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
placeholder="Form title"
|
||||||
|
className="w-full rounded border border-neutral-300 px-2 py-1 text-sm"
|
||||||
|
/>
|
||||||
|
<textarea
|
||||||
|
rows={2}
|
||||||
|
value={block.description ?? ""}
|
||||||
|
onChange={(event) =>
|
||||||
|
setBlocks((prev) =>
|
||||||
|
updateBlock(prev, block.id, { description: event.target.value || null }),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
placeholder="Form description"
|
||||||
|
className="w-full rounded border border-neutral-300 px-2 py-1 text-sm"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{block.type === "price_cards" ? (
|
||||||
|
<div className="space-y-2">
|
||||||
|
<input
|
||||||
|
value={block.title ?? ""}
|
||||||
|
onChange={(event) =>
|
||||||
|
setBlocks((prev) =>
|
||||||
|
updateBlock(prev, block.id, { title: event.target.value || null }),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
placeholder="Price card section title"
|
||||||
|
className="w-full rounded border border-neutral-300 px-2 py-1 text-sm"
|
||||||
|
/>
|
||||||
|
<textarea
|
||||||
|
rows={4}
|
||||||
|
value={block.cards
|
||||||
|
.map((card) => [card.name, card.price ?? "", card.description ?? ""].join("|"))
|
||||||
|
.join("\n")}
|
||||||
|
onChange={(event) =>
|
||||||
|
setBlocks((prev) =>
|
||||||
|
updateBlock(prev, block.id, {
|
||||||
|
cards: event.target.value
|
||||||
|
.split("\n")
|
||||||
|
.map((line) => line.trim())
|
||||||
|
.filter((line) => line.length > 0)
|
||||||
|
.map((line, lineIndex) => {
|
||||||
|
const [name, price, description] = line
|
||||||
|
.split("|")
|
||||||
|
.map((entry) => entry.trim())
|
||||||
|
return {
|
||||||
|
id: `card-${lineIndex}`,
|
||||||
|
name: name || `Card ${lineIndex + 1}`,
|
||||||
|
price: price || null,
|
||||||
|
description: description || null,
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
placeholder="One card per line: Name|Price|Description"
|
||||||
|
className="w-full rounded border border-neutral-300 px-2 py-1 text-sm"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</article>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -375,6 +375,63 @@ export async function ensureSupportUserBootstrap(): Promise<void> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const MANAGED_USER_ROLE_ALLOWLIST = new Set<Role>(["admin", "editor", "manager"])
|
||||||
|
|
||||||
|
export async function createManagedUserAccount(input: {
|
||||||
|
email: string
|
||||||
|
username?: string | null
|
||||||
|
name: string
|
||||||
|
password: string
|
||||||
|
role: string
|
||||||
|
}): Promise<{ id: string; email: string; username: string | null; role: string }> {
|
||||||
|
const normalizedEmail = input.email.trim().toLowerCase()
|
||||||
|
const normalizedRole = normalizeRole(input.role)
|
||||||
|
|
||||||
|
if (!normalizedRole || !MANAGED_USER_ROLE_ALLOWLIST.has(normalizedRole)) {
|
||||||
|
throw new Error("Unsupported role for managed user account")
|
||||||
|
}
|
||||||
|
|
||||||
|
const existing = await db.user.findUnique({
|
||||||
|
where: { email: normalizedEmail },
|
||||||
|
select: { id: true, isProtected: true, isSystem: true },
|
||||||
|
})
|
||||||
|
|
||||||
|
if (existing) {
|
||||||
|
if (existing.isProtected || existing.isSystem) {
|
||||||
|
throw new Error("Cannot mutate protected/system account via managed user provisioning")
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error("A user with this email already exists")
|
||||||
|
}
|
||||||
|
|
||||||
|
const preferredUsername =
|
||||||
|
normalizeUsernameCandidate(input.username) ??
|
||||||
|
normalizeUsernameCandidate(extractEmailLocalPart(normalizedEmail)) ??
|
||||||
|
"user"
|
||||||
|
|
||||||
|
await ensureCredentialUser({
|
||||||
|
email: normalizedEmail,
|
||||||
|
username: preferredUsername,
|
||||||
|
name: input.name.trim(),
|
||||||
|
password: input.password,
|
||||||
|
role: normalizedRole,
|
||||||
|
isHidden: false,
|
||||||
|
isSystem: false,
|
||||||
|
isProtected: false,
|
||||||
|
})
|
||||||
|
|
||||||
|
const created = await db.user.findUnique({
|
||||||
|
where: { email: normalizedEmail },
|
||||||
|
select: { id: true, email: true, username: true, role: true },
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!created) {
|
||||||
|
throw new Error("Managed user provisioning failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
return created
|
||||||
|
}
|
||||||
|
|
||||||
const DEFAULT_E2E_ADMIN_EMAIL = "e2e-admin@cms.local"
|
const DEFAULT_E2E_ADMIN_EMAIL = "e2e-admin@cms.local"
|
||||||
const DEFAULT_E2E_ADMIN_USERNAME = "e2e-admin"
|
const DEFAULT_E2E_ADMIN_USERNAME = "e2e-admin"
|
||||||
const DEFAULT_E2E_ADMIN_PASSWORD = "e2e-admin-password"
|
const DEFAULT_E2E_ADMIN_PASSWORD = "e2e-admin-password"
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ export default async function LocaleLayout({ children, params }: LocaleLayoutPro
|
|||||||
<NextIntlClientProvider locale={locale}>
|
<NextIntlClientProvider locale={locale}>
|
||||||
<Providers>
|
<Providers>
|
||||||
<PublicHeaderBanner banner={banner} />
|
<PublicHeaderBanner banner={banner} />
|
||||||
<PublicAnnouncements placement="global_top" />
|
<PublicAnnouncements placement="global_top" locale={locale} />
|
||||||
<PublicSiteHeader />
|
<PublicSiteHeader />
|
||||||
<main>{children}</main>
|
<main>{children}</main>
|
||||||
<PublicSiteFooter />
|
<PublicSiteFooter />
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { getPublishedPageBySlugForLocale, listPosts } from "@cms/db"
|
import { getPublishedPageBySlugForLocale, listPostsForLocale } from "@cms/db"
|
||||||
import { getTranslations } from "next-intl/server"
|
import { getTranslations } from "next-intl/server"
|
||||||
import { PublicAnnouncements } from "@/components/public-announcements"
|
import { PublicAnnouncements } from "@/components/public-announcements"
|
||||||
import { PublicPageView } from "@/components/public-page-view"
|
import { PublicPageView } from "@/components/public-page-view"
|
||||||
@@ -15,14 +15,14 @@ export default async function HomePage({ params }: HomePageProps) {
|
|||||||
|
|
||||||
const [homePage, posts, t] = await Promise.all([
|
const [homePage, posts, t] = await Promise.all([
|
||||||
getPublishedPageBySlugForLocale("home", locale),
|
getPublishedPageBySlugForLocale("home", locale),
|
||||||
listPosts(),
|
listPostsForLocale(locale),
|
||||||
getTranslations("Home"),
|
getTranslations("Home"),
|
||||||
])
|
])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section>
|
<section>
|
||||||
{homePage ? <PublicPageView page={homePage} /> : null}
|
{homePage ? <PublicPageView page={homePage} /> : null}
|
||||||
<PublicAnnouncements placement="homepage" />
|
<PublicAnnouncements placement="homepage" locale={locale} />
|
||||||
|
|
||||||
<section className="mx-auto flex w-full max-w-6xl flex-col gap-6 px-6 py-6 pb-16">
|
<section className="mx-auto flex w-full max-w-6xl flex-col gap-6 px-6 py-6 pb-16">
|
||||||
<header className="space-y-3">
|
<header className="space-y-3">
|
||||||
|
|||||||
@@ -17,6 +17,17 @@ function formatLabelList(values: string[]) {
|
|||||||
return values.join(", ")
|
return values.join(", ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatArtworkPrice(priceAmountCents: number | null, priceCurrency: string | null) {
|
||||||
|
if (!priceAmountCents || !priceCurrency) {
|
||||||
|
return "-"
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Intl.NumberFormat("en-US", {
|
||||||
|
style: "currency",
|
||||||
|
currency: priceCurrency,
|
||||||
|
}).format(priceAmountCents / 100)
|
||||||
|
}
|
||||||
|
|
||||||
export default async function PublicArtworkPage({ params }: PublicArtworkPageProps) {
|
export default async function PublicArtworkPage({ params }: PublicArtworkPageProps) {
|
||||||
const [{ slug }, t] = await Promise.all([params, getTranslations("Portfolio")])
|
const [{ slug }, t] = await Promise.all([params, getTranslations("Portfolio")])
|
||||||
const artwork = await getPublishedArtworkBySlug(slug)
|
const artwork = await getPublishedArtworkBySlug(slug)
|
||||||
@@ -25,6 +36,8 @@ export default async function PublicArtworkPage({ params }: PublicArtworkPagePro
|
|||||||
notFound()
|
notFound()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const primaryMedia = artwork.renditions[0]?.mediaAsset ?? null
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className="mx-auto w-full max-w-5xl space-y-6 px-6 py-16">
|
<section className="mx-auto w-full max-w-5xl space-y-6 px-6 py-16">
|
||||||
<header className="space-y-2">
|
<header className="space-y-2">
|
||||||
@@ -76,6 +89,12 @@ export default async function PublicArtworkPage({ params }: PublicArtworkPagePro
|
|||||||
<p>
|
<p>
|
||||||
<strong>{t("fields.availability")}:</strong> {artwork.availability || "-"}
|
<strong>{t("fields.availability")}:</strong> {artwork.availability || "-"}
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
|
<strong>{t("fields.price")}:</strong>{" "}
|
||||||
|
{artwork.isPriceVisible
|
||||||
|
? formatArtworkPrice(artwork.priceAmountCents, artwork.priceCurrency)
|
||||||
|
: "-"}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="space-y-2 text-sm">
|
<div className="space-y-2 text-sm">
|
||||||
<p>
|
<p>
|
||||||
@@ -94,6 +113,22 @@ export default async function PublicArtworkPage({ params }: PublicArtworkPagePro
|
|||||||
<strong>{t("fields.tags")}:</strong>{" "}
|
<strong>{t("fields.tags")}:</strong>{" "}
|
||||||
{formatLabelList(artwork.tagLinks.map((entry) => entry.tag.name))}
|
{formatLabelList(artwork.tagLinks.map((entry) => entry.tag.name))}
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
|
<strong>{t("fields.licenseType")}:</strong> {primaryMedia?.licenseType || "-"}
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<strong>{t("fields.licenseUrl")}:</strong> {primaryMedia?.licenseUrl || "-"}
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<strong>{t("fields.usageContext")}:</strong> {primaryMedia?.usageContext || "-"}
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<strong>{t("fields.location")}:</strong> {primaryMedia?.location || "-"}
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<strong>{t("fields.capturedAt")}:</strong>{" "}
|
||||||
|
{primaryMedia?.capturedAt ? primaryMedia.capturedAt.toLocaleDateString("en-US") : "-"}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import Link from "next/link"
|
|||||||
|
|
||||||
type PublicAnnouncementsProps = {
|
type PublicAnnouncementsProps = {
|
||||||
placement: "global_top" | "homepage"
|
placement: "global_top" | "homepage"
|
||||||
|
locale?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
function AnnouncementCard({ announcement }: { announcement: PublicAnnouncement }) {
|
function AnnouncementCard({ announcement }: { announcement: PublicAnnouncement }) {
|
||||||
@@ -22,8 +23,8 @@ function AnnouncementCard({ announcement }: { announcement: PublicAnnouncement }
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function PublicAnnouncements({ placement }: PublicAnnouncementsProps) {
|
export async function PublicAnnouncements({ placement, locale }: PublicAnnouncementsProps) {
|
||||||
const announcements = await listActiveAnnouncements(placement)
|
const announcements = await listActiveAnnouncements(placement, new Date(), locale)
|
||||||
|
|
||||||
if (announcements.length === 0) {
|
if (announcements.length === 0) {
|
||||||
return null
|
return null
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
import { parsePageBlocks } from "@cms/content"
|
||||||
|
import Image from "next/image"
|
||||||
|
|
||||||
type PageEntity = {
|
type PageEntity = {
|
||||||
title: string
|
title: string
|
||||||
status: string
|
status: string
|
||||||
@@ -9,7 +12,31 @@ type PublicPageViewProps = {
|
|||||||
page: PageEntity
|
page: PageEntity
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resolveFormLink(formKey: string): { href: string; label: string } {
|
||||||
|
const normalized = formKey.trim().toLowerCase()
|
||||||
|
|
||||||
|
if (normalized === "commission" || normalized === "commissions") {
|
||||||
|
return { href: "/commissions", label: "Open commission form" }
|
||||||
|
}
|
||||||
|
|
||||||
|
return { href: `/#form-${normalized || "contact"}`, label: "Open contact form" }
|
||||||
|
}
|
||||||
|
|
||||||
export function PublicPageView({ page }: PublicPageViewProps) {
|
export function PublicPageView({ page }: PublicPageViewProps) {
|
||||||
|
const blocks = (() => {
|
||||||
|
try {
|
||||||
|
return parsePageBlocks(page.content)
|
||||||
|
} catch {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
id: "fallback-rich-text",
|
||||||
|
type: "rich_text" as const,
|
||||||
|
body: page.content,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<article className="mx-auto flex w-full max-w-4xl flex-col gap-6 px-6 py-16">
|
<article className="mx-auto flex w-full max-w-4xl flex-col gap-6 px-6 py-16">
|
||||||
<header className="space-y-3">
|
<header className="space-y-3">
|
||||||
@@ -18,8 +45,112 @@ export function PublicPageView({ page }: PublicPageViewProps) {
|
|||||||
{page.summary ? <p className="text-neutral-600">{page.summary}</p> : null}
|
{page.summary ? <p className="text-neutral-600">{page.summary}</p> : null}
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<section className="prose prose-neutral max-w-none whitespace-pre-wrap rounded-xl border border-neutral-200 bg-white p-6 text-neutral-800">
|
<section className="space-y-4 rounded-xl border border-neutral-200 bg-white p-6 text-neutral-800">
|
||||||
{page.content}
|
{blocks.map((block) => {
|
||||||
|
if (block.type === "hero") {
|
||||||
|
return (
|
||||||
|
<section key={block.id} className="space-y-2 rounded border border-neutral-200 p-4">
|
||||||
|
<h2 className="text-2xl font-semibold">{block.heading}</h2>
|
||||||
|
{block.subheading ? <p className="text-neutral-600">{block.subheading}</p> : null}
|
||||||
|
{block.ctaLabel && block.ctaHref ? (
|
||||||
|
<a
|
||||||
|
href={block.ctaHref}
|
||||||
|
className="inline-flex rounded bg-neutral-900 px-3 py-1.5 text-sm text-white"
|
||||||
|
>
|
||||||
|
{block.ctaLabel}
|
||||||
|
</a>
|
||||||
|
) : null}
|
||||||
|
</section>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (block.type === "rich_text") {
|
||||||
|
return (
|
||||||
|
<section
|
||||||
|
key={block.id}
|
||||||
|
className="prose prose-neutral max-w-none whitespace-pre-wrap"
|
||||||
|
>
|
||||||
|
{block.body}
|
||||||
|
</section>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (block.type === "gallery") {
|
||||||
|
return (
|
||||||
|
<section key={block.id} className="space-y-3">
|
||||||
|
{block.title ? <h3 className="text-lg font-medium">{block.title}</h3> : null}
|
||||||
|
<div className="grid gap-3 sm:grid-cols-2">
|
||||||
|
{block.imageIds.length === 0 ? (
|
||||||
|
<p className="text-sm text-neutral-500">No media linked yet.</p>
|
||||||
|
) : (
|
||||||
|
block.imageIds.map((imageId) => (
|
||||||
|
<Image
|
||||||
|
key={imageId}
|
||||||
|
src={`/api/media/file/${imageId}`}
|
||||||
|
alt=""
|
||||||
|
width={1200}
|
||||||
|
height={800}
|
||||||
|
className="h-48 w-full rounded border border-neutral-200 object-cover"
|
||||||
|
/>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (block.type === "cta") {
|
||||||
|
return (
|
||||||
|
<a
|
||||||
|
key={block.id}
|
||||||
|
href={block.href}
|
||||||
|
className={`inline-flex rounded px-3 py-2 text-sm ${
|
||||||
|
block.variant === "secondary"
|
||||||
|
? "border border-neutral-300 text-neutral-800"
|
||||||
|
: "bg-neutral-900 text-white"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{block.label}
|
||||||
|
</a>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (block.type === "form") {
|
||||||
|
const formLink = resolveFormLink(block.formKey)
|
||||||
|
return (
|
||||||
|
<section key={block.id} className="space-y-2 rounded border border-neutral-200 p-4">
|
||||||
|
<h3 className="text-lg font-medium">{block.title || "Form block"}</h3>
|
||||||
|
<p className="text-sm text-neutral-600">
|
||||||
|
{block.description || "Form integration pending."}
|
||||||
|
</p>
|
||||||
|
<p className="text-xs text-neutral-500">formKey: {block.formKey}</p>
|
||||||
|
<a
|
||||||
|
href={formLink.href}
|
||||||
|
className="inline-flex rounded border border-neutral-300 px-3 py-1.5 text-sm"
|
||||||
|
>
|
||||||
|
{formLink.label}
|
||||||
|
</a>
|
||||||
|
</section>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<section key={block.id} className="space-y-2 rounded border border-neutral-200 p-4">
|
||||||
|
{block.title ? <h3 className="text-lg font-medium">{block.title}</h3> : null}
|
||||||
|
<div className="grid gap-3 md:grid-cols-2">
|
||||||
|
{block.cards.map((card) => (
|
||||||
|
<article key={card.id} className="rounded border border-neutral-200 p-3">
|
||||||
|
<h4 className="font-medium">{card.name}</h4>
|
||||||
|
{card.price ? <p className="text-sm text-neutral-700">{card.price}</p> : null}
|
||||||
|
{card.description ? (
|
||||||
|
<p className="text-sm text-neutral-600">{card.description}</p>
|
||||||
|
) : null}
|
||||||
|
</article>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
)
|
||||||
|
})}
|
||||||
</section>
|
</section>
|
||||||
</article>
|
</article>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -84,10 +84,16 @@
|
|||||||
"dimensions": "Abmessungen",
|
"dimensions": "Abmessungen",
|
||||||
"year": "Jahr",
|
"year": "Jahr",
|
||||||
"availability": "Verfügbarkeit",
|
"availability": "Verfügbarkeit",
|
||||||
|
"price": "Preis",
|
||||||
"galleries": "Galerien",
|
"galleries": "Galerien",
|
||||||
"albums": "Alben",
|
"albums": "Alben",
|
||||||
"categories": "Kategorien",
|
"categories": "Kategorien",
|
||||||
"tags": "Tags"
|
"tags": "Tags",
|
||||||
|
"licenseType": "Lizenztyp",
|
||||||
|
"licenseUrl": "Lizenz-URL",
|
||||||
|
"usageContext": "Nutzungskontext",
|
||||||
|
"location": "Ort",
|
||||||
|
"capturedAt": "Aufgenommen am"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,10 +84,16 @@
|
|||||||
"dimensions": "Dimensions",
|
"dimensions": "Dimensions",
|
||||||
"year": "Year",
|
"year": "Year",
|
||||||
"availability": "Availability",
|
"availability": "Availability",
|
||||||
|
"price": "Price",
|
||||||
"galleries": "Galleries",
|
"galleries": "Galleries",
|
||||||
"albums": "Albums",
|
"albums": "Albums",
|
||||||
"categories": "Categories",
|
"categories": "Categories",
|
||||||
"tags": "Tags"
|
"tags": "Tags",
|
||||||
|
"licenseType": "License type",
|
||||||
|
"licenseUrl": "License URL",
|
||||||
|
"usageContext": "Usage context",
|
||||||
|
"location": "Location",
|
||||||
|
"capturedAt": "Captured at"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,10 +84,16 @@
|
|||||||
"dimensions": "Dimensiones",
|
"dimensions": "Dimensiones",
|
||||||
"year": "Año",
|
"year": "Año",
|
||||||
"availability": "Disponibilidad",
|
"availability": "Disponibilidad",
|
||||||
|
"price": "Precio",
|
||||||
"galleries": "Galerías",
|
"galleries": "Galerías",
|
||||||
"albums": "Álbumes",
|
"albums": "Álbumes",
|
||||||
"categories": "Categorías",
|
"categories": "Categorías",
|
||||||
"tags": "Etiquetas"
|
"tags": "Etiquetas",
|
||||||
|
"licenseType": "Tipo de licencia",
|
||||||
|
"licenseUrl": "URL de licencia",
|
||||||
|
"usageContext": "Contexto de uso",
|
||||||
|
"location": "Ubicación",
|
||||||
|
"capturedAt": "Capturado el"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,10 +84,16 @@
|
|||||||
"dimensions": "Dimensions",
|
"dimensions": "Dimensions",
|
||||||
"year": "Année",
|
"year": "Année",
|
||||||
"availability": "Disponibilité",
|
"availability": "Disponibilité",
|
||||||
|
"price": "Prix",
|
||||||
"galleries": "Galeries",
|
"galleries": "Galeries",
|
||||||
"albums": "Albums",
|
"albums": "Albums",
|
||||||
"categories": "Catégories",
|
"categories": "Catégories",
|
||||||
"tags": "Tags"
|
"tags": "Tags",
|
||||||
|
"licenseType": "Type de licence",
|
||||||
|
"licenseUrl": "URL de licence",
|
||||||
|
"usageContext": "Contexte d'utilisation",
|
||||||
|
"location": "Lieu",
|
||||||
|
"capturedAt": "Capturé le"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
export const announcementPlacementSchema = z.enum(["global_top", "homepage"])
|
export const announcementPlacementSchema = z.enum(["global_top", "homepage"])
|
||||||
|
export const announcementLocaleSchema = z.enum(["de", "en", "es", "fr"])
|
||||||
|
|
||||||
export const createAnnouncementInputSchema = z.object({
|
export const createAnnouncementInputSchema = z.object({
|
||||||
title: z.string().min(1).max(180),
|
title: z.string().min(1).max(180),
|
||||||
message: z.string().min(1).max(500),
|
message: z.string().min(1).max(500),
|
||||||
placement: announcementPlacementSchema.default("global_top"),
|
placement: announcementPlacementSchema.default("global_top"),
|
||||||
|
targetLocales: z.array(announcementLocaleSchema).default([]),
|
||||||
priority: z.number().int().min(0).default(100),
|
priority: z.number().int().min(0).default(100),
|
||||||
ctaLabel: z.string().max(120).nullable().optional(),
|
ctaLabel: z.string().max(120).nullable().optional(),
|
||||||
ctaHref: z.string().max(500).nullable().optional(),
|
ctaHref: z.string().max(500).nullable().optional(),
|
||||||
@@ -19,6 +21,7 @@ export const updateAnnouncementInputSchema = z.object({
|
|||||||
title: z.string().min(1).max(180).optional(),
|
title: z.string().min(1).max(180).optional(),
|
||||||
message: z.string().min(1).max(500).optional(),
|
message: z.string().min(1).max(500).optional(),
|
||||||
placement: announcementPlacementSchema.optional(),
|
placement: announcementPlacementSchema.optional(),
|
||||||
|
targetLocales: z.array(announcementLocaleSchema).optional(),
|
||||||
priority: z.number().int().min(0).optional(),
|
priority: z.number().int().min(0).optional(),
|
||||||
ctaLabel: z.string().max(120).nullable().optional(),
|
ctaLabel: z.string().max(120).nullable().optional(),
|
||||||
ctaHref: z.string().max(500).nullable().optional(),
|
ctaHref: z.string().max(500).nullable().optional(),
|
||||||
|
|||||||
@@ -23,7 +23,21 @@ export const createCommissionInputSchema = z.object({
|
|||||||
description: z.string().max(4000).nullable().optional(),
|
description: z.string().max(4000).nullable().optional(),
|
||||||
status: commissionStatusSchema.default("new"),
|
status: commissionStatusSchema.default("new"),
|
||||||
customerId: z.string().uuid().nullable().optional(),
|
customerId: z.string().uuid().nullable().optional(),
|
||||||
assignedUserId: z.string().max(120).nullable().optional(),
|
assignedUserId: z.string().uuid().nullable().optional(),
|
||||||
|
linkedArtworkIds: z.array(z.string().uuid()).default([]),
|
||||||
|
budgetMin: z.number().nonnegative().nullable().optional(),
|
||||||
|
budgetMax: z.number().nonnegative().nullable().optional(),
|
||||||
|
dueAt: z.date().nullable().optional(),
|
||||||
|
})
|
||||||
|
|
||||||
|
export const updateCommissionInputSchema = z.object({
|
||||||
|
id: z.string().uuid(),
|
||||||
|
title: z.string().min(1).max(180).optional(),
|
||||||
|
description: z.string().max(4000).nullable().optional(),
|
||||||
|
status: commissionStatusSchema.optional(),
|
||||||
|
customerId: z.string().uuid().nullable().optional(),
|
||||||
|
assignedUserId: z.string().uuid().nullable().optional(),
|
||||||
|
linkedArtworkIds: z.array(z.string().uuid()).optional(),
|
||||||
budgetMin: z.number().nonnegative().nullable().optional(),
|
budgetMin: z.number().nonnegative().nullable().optional(),
|
||||||
budgetMax: z.number().nonnegative().nullable().optional(),
|
budgetMax: z.number().nonnegative().nullable().optional(),
|
||||||
dueAt: z.date().nullable().optional(),
|
dueAt: z.date().nullable().optional(),
|
||||||
@@ -57,6 +71,7 @@ export const updateCommissionStatusInputSchema = z.object({
|
|||||||
export type CommissionStatus = z.infer<typeof commissionStatusSchema>
|
export type CommissionStatus = z.infer<typeof commissionStatusSchema>
|
||||||
export type CreateCustomerInput = z.infer<typeof createCustomerInputSchema>
|
export type CreateCustomerInput = z.infer<typeof createCustomerInputSchema>
|
||||||
export type CreateCommissionInput = z.infer<typeof createCommissionInputSchema>
|
export type CreateCommissionInput = z.infer<typeof createCommissionInputSchema>
|
||||||
|
export type UpdateCommissionInput = z.infer<typeof updateCommissionInputSchema>
|
||||||
export type CreatePublicCommissionRequestInput = z.infer<
|
export type CreatePublicCommissionRequestInput = z.infer<
|
||||||
typeof createPublicCommissionRequestInputSchema
|
typeof createPublicCommissionRequestInputSchema
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import {
|
|||||||
createCustomerInputSchema,
|
createCustomerInputSchema,
|
||||||
createNavigationMenuInputSchema,
|
createNavigationMenuInputSchema,
|
||||||
createPageInputSchema,
|
createPageInputSchema,
|
||||||
|
parsePageBlocks,
|
||||||
|
serializePageBlocks,
|
||||||
updateCommissionStatusInputSchema,
|
updateCommissionStatusInputSchema,
|
||||||
updateNavigationItemInputSchema,
|
updateNavigationItemInputSchema,
|
||||||
} from "./index"
|
} from "./index"
|
||||||
@@ -64,4 +66,23 @@ describe("domain schemas", () => {
|
|||||||
expect(menu.success).toBe(true)
|
expect(menu.success).toBe(true)
|
||||||
expect(navUpdate.success).toBe(false)
|
expect(navUpdate.success).toBe(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("parses and serializes page blocks with legacy fallback", () => {
|
||||||
|
const legacy = parsePageBlocks("Legacy body")
|
||||||
|
expect(legacy[0]?.type).toBe("rich_text")
|
||||||
|
|
||||||
|
const serialized = serializePageBlocks([
|
||||||
|
{
|
||||||
|
id: "hero-1",
|
||||||
|
type: "hero",
|
||||||
|
heading: "Hello",
|
||||||
|
subheading: null,
|
||||||
|
ctaLabel: null,
|
||||||
|
ctaHref: null,
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
const parsed = parsePageBlocks(serialized)
|
||||||
|
expect(parsed[0]?.type).toBe("hero")
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -12,10 +12,14 @@ describe("media schemas", () => {
|
|||||||
const parsed = createMediaAssetInputSchema.parse({
|
const parsed = createMediaAssetInputSchema.parse({
|
||||||
type: "artwork",
|
type: "artwork",
|
||||||
title: "Artwork",
|
title: "Artwork",
|
||||||
|
licenseType: "CC BY",
|
||||||
|
usageContext: "homepage hero",
|
||||||
|
capturedAt: new Date("2026-01-02T10:30:00.000Z"),
|
||||||
tags: ["tag-a"],
|
tags: ["tag-a"],
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(parsed.type).toBe("artwork")
|
expect(parsed.type).toBe("artwork")
|
||||||
|
expect(parsed.licenseType).toBe("CC BY")
|
||||||
expect(parsed.tags).toEqual(["tag-a"])
|
expect(parsed.tags).toEqual(["tag-a"])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,57 @@ export const mediaAssetTypeSchema = z.enum([
|
|||||||
"generic",
|
"generic",
|
||||||
])
|
])
|
||||||
|
|
||||||
export const artworkRenditionSlotSchema = z.enum(["thumbnail", "card", "full", "custom"])
|
export type MediaUploadRule = {
|
||||||
|
maxBytes: number
|
||||||
|
allowedMimePrefix?: string
|
||||||
|
allowedMimeExact?: string[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export const mediaUploadRulesByType: Record<MediaAssetType, MediaUploadRule> = {
|
||||||
|
artwork: {
|
||||||
|
maxBytes: 40 * 1024 * 1024,
|
||||||
|
allowedMimePrefix: "image/",
|
||||||
|
},
|
||||||
|
banner: {
|
||||||
|
maxBytes: 20 * 1024 * 1024,
|
||||||
|
allowedMimePrefix: "image/",
|
||||||
|
},
|
||||||
|
promotion: {
|
||||||
|
maxBytes: 20 * 1024 * 1024,
|
||||||
|
allowedMimePrefix: "image/",
|
||||||
|
},
|
||||||
|
video: {
|
||||||
|
maxBytes: 250 * 1024 * 1024,
|
||||||
|
allowedMimePrefix: "video/",
|
||||||
|
},
|
||||||
|
gif: {
|
||||||
|
maxBytes: 40 * 1024 * 1024,
|
||||||
|
allowedMimeExact: ["image/gif"],
|
||||||
|
},
|
||||||
|
generic: {
|
||||||
|
maxBytes: 50 * 1024 * 1024,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isMimeAllowedForMediaType(type: MediaAssetType, mimeType: string): boolean {
|
||||||
|
const rule = mediaUploadRulesByType[type]
|
||||||
|
|
||||||
|
if (rule.allowedMimeExact?.includes(mimeType)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rule.allowedMimePrefix) {
|
||||||
|
return mimeType.startsWith(rule.allowedMimePrefix)
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getMediaUploadMaxBytes(type: MediaAssetType): number {
|
||||||
|
return mediaUploadRulesByType[type].maxBytes
|
||||||
|
}
|
||||||
|
|
||||||
|
export const artworkRenditionSlotSchema = z.enum(["thumbnail", "card", "full", "retina", "custom"])
|
||||||
|
|
||||||
export const createMediaAssetInputSchema = z.object({
|
export const createMediaAssetInputSchema = z.object({
|
||||||
id: z.string().uuid().optional(),
|
id: z.string().uuid().optional(),
|
||||||
@@ -20,6 +70,11 @@ export const createMediaAssetInputSchema = z.object({
|
|||||||
source: z.string().max(500).optional(),
|
source: z.string().max(500).optional(),
|
||||||
copyright: z.string().max(500).optional(),
|
copyright: z.string().max(500).optional(),
|
||||||
author: z.string().max(180).optional(),
|
author: z.string().max(180).optional(),
|
||||||
|
licenseType: z.string().max(120).optional(),
|
||||||
|
licenseUrl: z.string().max(500).optional(),
|
||||||
|
usageContext: z.string().max(300).optional(),
|
||||||
|
location: z.string().max(180).optional(),
|
||||||
|
capturedAt: z.date().optional(),
|
||||||
tags: z.array(z.string().min(1).max(100)).default([]),
|
tags: z.array(z.string().min(1).max(100)).default([]),
|
||||||
storageKey: z.string().max(500).optional(),
|
storageKey: z.string().max(500).optional(),
|
||||||
mimeType: z.string().max(180).optional(),
|
mimeType: z.string().max(180).optional(),
|
||||||
@@ -38,6 +93,11 @@ export const updateMediaAssetInputSchema = z.object({
|
|||||||
source: z.string().max(500).nullable().optional(),
|
source: z.string().max(500).nullable().optional(),
|
||||||
copyright: z.string().max(500).nullable().optional(),
|
copyright: z.string().max(500).nullable().optional(),
|
||||||
author: z.string().max(180).nullable().optional(),
|
author: z.string().max(180).nullable().optional(),
|
||||||
|
licenseType: z.string().max(120).nullable().optional(),
|
||||||
|
licenseUrl: z.string().max(500).nullable().optional(),
|
||||||
|
usageContext: z.string().max(300).nullable().optional(),
|
||||||
|
location: z.string().max(180).nullable().optional(),
|
||||||
|
capturedAt: z.date().nullable().optional(),
|
||||||
tags: z.array(z.string().min(1).max(100)).optional(),
|
tags: z.array(z.string().min(1).max(100)).optional(),
|
||||||
mimeType: z.string().max(180).nullable().optional(),
|
mimeType: z.string().max(180).nullable().optional(),
|
||||||
width: z.number().int().positive().nullable().optional(),
|
width: z.number().int().positive().nullable().optional(),
|
||||||
@@ -55,6 +115,25 @@ export const createArtworkInputSchema = z.object({
|
|||||||
year: z.number().int().min(1000).max(9999).optional(),
|
year: z.number().int().min(1000).max(9999).optional(),
|
||||||
framing: z.string().max(180).optional(),
|
framing: z.string().max(180).optional(),
|
||||||
availability: z.string().max(180).optional(),
|
availability: z.string().max(180).optional(),
|
||||||
|
priceAmountCents: z.number().int().min(0).optional(),
|
||||||
|
priceCurrency: z.string().min(3).max(3).optional(),
|
||||||
|
isPriceVisible: z.boolean().optional(),
|
||||||
|
})
|
||||||
|
|
||||||
|
export const updateArtworkInputSchema = z.object({
|
||||||
|
id: z.string().uuid(),
|
||||||
|
title: z.string().min(1).max(180).optional(),
|
||||||
|
slug: z.string().min(1).max(180).optional(),
|
||||||
|
description: z.string().max(5000).nullable().optional(),
|
||||||
|
medium: z.string().max(180).nullable().optional(),
|
||||||
|
dimensions: z.string().max(180).nullable().optional(),
|
||||||
|
year: z.number().int().min(1000).max(9999).nullable().optional(),
|
||||||
|
framing: z.string().max(180).nullable().optional(),
|
||||||
|
availability: z.string().max(180).nullable().optional(),
|
||||||
|
priceAmountCents: z.number().int().min(0).nullable().optional(),
|
||||||
|
priceCurrency: z.string().min(3).max(3).nullable().optional(),
|
||||||
|
isPriceVisible: z.boolean().optional(),
|
||||||
|
isPublished: z.boolean().optional(),
|
||||||
})
|
})
|
||||||
|
|
||||||
export const createGroupingInputSchema = z.object({
|
export const createGroupingInputSchema = z.object({
|
||||||
@@ -65,6 +144,21 @@ export const createGroupingInputSchema = z.object({
|
|||||||
isVisible: z.boolean().default(true),
|
isVisible: z.boolean().default(true),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const updateGroupingInputSchema = z.object({
|
||||||
|
groupType: z.enum(["gallery", "album", "category", "tag"]),
|
||||||
|
groupId: z.string().uuid(),
|
||||||
|
name: z.string().min(1).max(180),
|
||||||
|
slug: z.string().min(1).max(180),
|
||||||
|
description: z.string().max(5000).nullable().optional(),
|
||||||
|
sortOrder: z.number().int().min(0),
|
||||||
|
isVisible: z.boolean(),
|
||||||
|
})
|
||||||
|
|
||||||
|
export const deleteGroupingInputSchema = z.object({
|
||||||
|
groupType: z.enum(["gallery", "album", "category", "tag"]),
|
||||||
|
groupId: z.string().uuid(),
|
||||||
|
})
|
||||||
|
|
||||||
export const linkArtworkGroupingInputSchema = z.object({
|
export const linkArtworkGroupingInputSchema = z.object({
|
||||||
artworkId: z.string().uuid(),
|
artworkId: z.string().uuid(),
|
||||||
groupType: z.enum(["gallery", "album", "category", "tag"]),
|
groupType: z.enum(["gallery", "album", "category", "tag"]),
|
||||||
@@ -85,6 +179,9 @@ export type ArtworkRenditionSlot = z.infer<typeof artworkRenditionSlotSchema>
|
|||||||
export type CreateMediaAssetInput = z.infer<typeof createMediaAssetInputSchema>
|
export type CreateMediaAssetInput = z.infer<typeof createMediaAssetInputSchema>
|
||||||
export type UpdateMediaAssetInput = z.infer<typeof updateMediaAssetInputSchema>
|
export type UpdateMediaAssetInput = z.infer<typeof updateMediaAssetInputSchema>
|
||||||
export type CreateArtworkInput = z.infer<typeof createArtworkInputSchema>
|
export type CreateArtworkInput = z.infer<typeof createArtworkInputSchema>
|
||||||
|
export type UpdateArtworkInput = z.infer<typeof updateArtworkInputSchema>
|
||||||
export type CreateGroupingInput = z.infer<typeof createGroupingInputSchema>
|
export type CreateGroupingInput = z.infer<typeof createGroupingInputSchema>
|
||||||
|
export type UpdateGroupingInput = z.infer<typeof updateGroupingInputSchema>
|
||||||
|
export type DeleteGroupingInput = z.infer<typeof deleteGroupingInputSchema>
|
||||||
export type LinkArtworkGroupingInput = z.infer<typeof linkArtworkGroupingInputSchema>
|
export type LinkArtworkGroupingInput = z.infer<typeof linkArtworkGroupingInputSchema>
|
||||||
export type AttachArtworkRenditionInput = z.infer<typeof attachArtworkRenditionInputSchema>
|
export type AttachArtworkRenditionInput = z.infer<typeof attachArtworkRenditionInputSchema>
|
||||||
|
|||||||
@@ -3,6 +3,98 @@ import { z } from "zod"
|
|||||||
export const pageStatusSchema = z.enum(["draft", "published"])
|
export const pageStatusSchema = z.enum(["draft", "published"])
|
||||||
export const pageLocaleSchema = z.enum(["de", "en", "es", "fr"])
|
export const pageLocaleSchema = z.enum(["de", "en", "es", "fr"])
|
||||||
|
|
||||||
|
const pageBlockBaseSchema = z.object({
|
||||||
|
id: z.string().min(1),
|
||||||
|
})
|
||||||
|
|
||||||
|
export const heroPageBlockSchema = pageBlockBaseSchema.extend({
|
||||||
|
type: z.literal("hero"),
|
||||||
|
heading: z.string().min(1).max(180),
|
||||||
|
subheading: z.string().max(500).nullable().optional(),
|
||||||
|
ctaLabel: z.string().max(80).nullable().optional(),
|
||||||
|
ctaHref: z.string().max(500).nullable().optional(),
|
||||||
|
})
|
||||||
|
|
||||||
|
export const richTextPageBlockSchema = pageBlockBaseSchema.extend({
|
||||||
|
type: z.literal("rich_text"),
|
||||||
|
body: z.string().min(1),
|
||||||
|
})
|
||||||
|
|
||||||
|
export const galleryPageBlockSchema = pageBlockBaseSchema.extend({
|
||||||
|
type: z.literal("gallery"),
|
||||||
|
title: z.string().max(180).nullable().optional(),
|
||||||
|
imageIds: z.array(z.string().uuid()).default([]),
|
||||||
|
})
|
||||||
|
|
||||||
|
export const ctaPageBlockSchema = pageBlockBaseSchema.extend({
|
||||||
|
type: z.literal("cta"),
|
||||||
|
label: z.string().min(1).max(80),
|
||||||
|
href: z.string().max(500),
|
||||||
|
variant: z.enum(["primary", "secondary"]).default("primary"),
|
||||||
|
})
|
||||||
|
|
||||||
|
export const formPageBlockSchema = pageBlockBaseSchema.extend({
|
||||||
|
type: z.literal("form"),
|
||||||
|
formKey: z.string().min(1).max(120),
|
||||||
|
title: z.string().max(180).nullable().optional(),
|
||||||
|
description: z.string().max(500).nullable().optional(),
|
||||||
|
})
|
||||||
|
|
||||||
|
export const priceCardsPageBlockSchema = pageBlockBaseSchema.extend({
|
||||||
|
type: z.literal("price_cards"),
|
||||||
|
title: z.string().max(180).nullable().optional(),
|
||||||
|
cards: z
|
||||||
|
.array(
|
||||||
|
z.object({
|
||||||
|
id: z.string().min(1),
|
||||||
|
name: z.string().min(1).max(180),
|
||||||
|
price: z.string().max(80).nullable().optional(),
|
||||||
|
description: z.string().max(500).nullable().optional(),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.default([]),
|
||||||
|
})
|
||||||
|
|
||||||
|
export const pageBlockSchema = z.discriminatedUnion("type", [
|
||||||
|
heroPageBlockSchema,
|
||||||
|
richTextPageBlockSchema,
|
||||||
|
galleryPageBlockSchema,
|
||||||
|
ctaPageBlockSchema,
|
||||||
|
formPageBlockSchema,
|
||||||
|
priceCardsPageBlockSchema,
|
||||||
|
])
|
||||||
|
|
||||||
|
export const pageBlocksSchema = z.array(pageBlockSchema)
|
||||||
|
|
||||||
|
function isJsonLike(value: string): boolean {
|
||||||
|
const trimmed = value.trim()
|
||||||
|
return trimmed.startsWith("{") || trimmed.startsWith("[")
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parsePageBlocks(content: string): z.infer<typeof pageBlocksSchema> {
|
||||||
|
if (!isJsonLike(content)) {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
id: "legacy-rich-text",
|
||||||
|
type: "rich_text",
|
||||||
|
body: content,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
const parsed = JSON.parse(content)
|
||||||
|
|
||||||
|
if (!Array.isArray(parsed)) {
|
||||||
|
throw new Error("Page block payload must be an array.")
|
||||||
|
}
|
||||||
|
|
||||||
|
return pageBlocksSchema.parse(parsed)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function serializePageBlocks(blocks: z.infer<typeof pageBlocksSchema>): string {
|
||||||
|
return JSON.stringify(pageBlocksSchema.parse(blocks))
|
||||||
|
}
|
||||||
|
|
||||||
export const createPageInputSchema = z.object({
|
export const createPageInputSchema = z.object({
|
||||||
title: z.string().min(1).max(180),
|
title: z.string().min(1).max(180),
|
||||||
slug: z.string().min(1).max(180),
|
slug: z.string().min(1).max(180),
|
||||||
@@ -41,6 +133,14 @@ export const createNavigationMenuInputSchema = z.object({
|
|||||||
isVisible: z.boolean().default(true),
|
isVisible: z.boolean().default(true),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const updateNavigationMenuInputSchema = z.object({
|
||||||
|
id: z.string().uuid(),
|
||||||
|
name: z.string().min(1).max(180).optional(),
|
||||||
|
slug: z.string().min(1).max(180).optional(),
|
||||||
|
location: z.string().min(1).max(80).optional(),
|
||||||
|
isVisible: z.boolean().optional(),
|
||||||
|
})
|
||||||
|
|
||||||
export const createNavigationItemInputSchema = z.object({
|
export const createNavigationItemInputSchema = z.object({
|
||||||
menuId: z.string().uuid(),
|
menuId: z.string().uuid(),
|
||||||
label: z.string().min(1).max(180),
|
label: z.string().min(1).max(180),
|
||||||
@@ -65,5 +165,8 @@ export type CreatePageInput = z.infer<typeof createPageInputSchema>
|
|||||||
export type UpdatePageInput = z.infer<typeof updatePageInputSchema>
|
export type UpdatePageInput = z.infer<typeof updatePageInputSchema>
|
||||||
export type UpsertPageTranslationInput = z.infer<typeof upsertPageTranslationInputSchema>
|
export type UpsertPageTranslationInput = z.infer<typeof upsertPageTranslationInputSchema>
|
||||||
export type CreateNavigationMenuInput = z.infer<typeof createNavigationMenuInputSchema>
|
export type CreateNavigationMenuInput = z.infer<typeof createNavigationMenuInputSchema>
|
||||||
|
export type UpdateNavigationMenuInput = z.infer<typeof updateNavigationMenuInputSchema>
|
||||||
export type CreateNavigationItemInput = z.infer<typeof createNavigationItemInputSchema>
|
export type CreateNavigationItemInput = z.infer<typeof createNavigationItemInputSchema>
|
||||||
export type UpdateNavigationItemInput = z.infer<typeof updateNavigationItemInputSchema>
|
export type UpdateNavigationItemInput = z.infer<typeof updateNavigationItemInputSchema>
|
||||||
|
export type PageBlock = z.infer<typeof pageBlockSchema>
|
||||||
|
export type PageBlocks = z.infer<typeof pageBlocksSchema>
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
ALTER TABLE "MediaAsset"
|
||||||
|
ADD COLUMN "licenseType" TEXT,
|
||||||
|
ADD COLUMN "licenseUrl" TEXT,
|
||||||
|
ADD COLUMN "usageContext" TEXT,
|
||||||
|
ADD COLUMN "location" TEXT,
|
||||||
|
ADD COLUMN "capturedAt" TIMESTAMP(3);
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
ALTER TABLE "Tag"
|
||||||
|
ADD COLUMN "description" TEXT,
|
||||||
|
ADD COLUMN "sortOrder" INTEGER NOT NULL DEFAULT 0,
|
||||||
|
ADD COLUMN "isVisible" BOOLEAN NOT NULL DEFAULT true;
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
ALTER TABLE "Artwork"
|
||||||
|
ADD COLUMN "priceAmountCents" INTEGER,
|
||||||
|
ADD COLUMN "priceCurrency" TEXT,
|
||||||
|
ADD COLUMN "isPriceVisible" BOOLEAN NOT NULL DEFAULT false;
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE "Commission"
|
||||||
|
ADD COLUMN "linkedArtworkIds" TEXT[] NOT NULL DEFAULT ARRAY[]::TEXT[];
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE "Announcement"
|
||||||
|
ADD COLUMN "targetLocales" TEXT[] NOT NULL DEFAULT ARRAY[]::TEXT[];
|
||||||
@@ -123,6 +123,11 @@ model MediaAsset {
|
|||||||
source String?
|
source String?
|
||||||
copyright String?
|
copyright String?
|
||||||
author String?
|
author String?
|
||||||
|
licenseType String?
|
||||||
|
licenseUrl String?
|
||||||
|
usageContext String?
|
||||||
|
location String?
|
||||||
|
capturedAt DateTime?
|
||||||
tags String[]
|
tags String[]
|
||||||
storageKey String? @unique
|
storageKey String? @unique
|
||||||
mimeType String?
|
mimeType String?
|
||||||
@@ -148,6 +153,9 @@ model Artwork {
|
|||||||
year Int?
|
year Int?
|
||||||
framing String?
|
framing String?
|
||||||
availability String?
|
availability String?
|
||||||
|
priceAmountCents Int?
|
||||||
|
priceCurrency String?
|
||||||
|
isPriceVisible Boolean @default(false)
|
||||||
isPublished Boolean @default(false)
|
isPublished Boolean @default(false)
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
@@ -217,6 +225,9 @@ model Tag {
|
|||||||
id String @id @default(uuid())
|
id String @id @default(uuid())
|
||||||
name String
|
name String
|
||||||
slug String @unique
|
slug String @unique
|
||||||
|
description String?
|
||||||
|
sortOrder Int @default(0)
|
||||||
|
isVisible Boolean @default(true)
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
artworkLinks ArtworkTag[]
|
artworkLinks ArtworkTag[]
|
||||||
@@ -375,6 +386,7 @@ model Commission {
|
|||||||
status String
|
status String
|
||||||
customerId String?
|
customerId String?
|
||||||
assignedUserId String?
|
assignedUserId String?
|
||||||
|
linkedArtworkIds String[] @default([])
|
||||||
budgetMin Float?
|
budgetMin Float?
|
||||||
budgetMax Float?
|
budgetMax Float?
|
||||||
dueAt DateTime?
|
dueAt DateTime?
|
||||||
@@ -393,6 +405,7 @@ model Announcement {
|
|||||||
title String
|
title String
|
||||||
message String
|
message String
|
||||||
placement String
|
placement String
|
||||||
|
targetLocales String[] @default([])
|
||||||
priority Int @default(100)
|
priority Int @default(100)
|
||||||
ctaLabel String?
|
ctaLabel String?
|
||||||
ctaHref String?
|
ctaHref String?
|
||||||
|
|||||||
@@ -41,13 +41,18 @@ describe("announcements service", () => {
|
|||||||
it("queries only visible announcements in the given placement", async () => {
|
it("queries only visible announcements in the given placement", async () => {
|
||||||
mockDb.announcement.findMany.mockResolvedValue([])
|
mockDb.announcement.findMany.mockResolvedValue([])
|
||||||
|
|
||||||
await listActiveAnnouncements("homepage")
|
await listActiveAnnouncements("homepage", new Date("2026-02-12T10:00:00.000Z"), "en")
|
||||||
|
|
||||||
expect(mockDb.announcement.findMany).toHaveBeenCalledTimes(1)
|
expect(mockDb.announcement.findMany).toHaveBeenCalledTimes(1)
|
||||||
expect(mockDb.announcement.findMany.mock.calls[0]?.[0]).toMatchObject({
|
expect(mockDb.announcement.findMany.mock.calls[0]?.[0]).toMatchObject({
|
||||||
where: {
|
where: {
|
||||||
placement: "homepage",
|
placement: "homepage",
|
||||||
isVisible: true,
|
isVisible: true,
|
||||||
|
AND: [
|
||||||
|
{
|
||||||
|
OR: [{ targetLocales: { isEmpty: true } }, { targetLocales: { has: "en" } }],
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ export type PublicAnnouncement = {
|
|||||||
ctaLabel: string | null
|
ctaLabel: string | null
|
||||||
ctaHref: string | null
|
ctaHref: string | null
|
||||||
placement: string
|
placement: string
|
||||||
|
targetLocales: string[]
|
||||||
priority: number
|
priority: number
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,13 +51,26 @@ export async function deleteAnnouncement(id: string) {
|
|||||||
export async function listActiveAnnouncements(
|
export async function listActiveAnnouncements(
|
||||||
placement: AnnouncementPlacement,
|
placement: AnnouncementPlacement,
|
||||||
now = new Date(),
|
now = new Date(),
|
||||||
|
locale?: string,
|
||||||
): Promise<PublicAnnouncement[]> {
|
): Promise<PublicAnnouncement[]> {
|
||||||
|
const localeFilter =
|
||||||
|
locale && locale.length > 0
|
||||||
|
? {
|
||||||
|
AND: [
|
||||||
|
{
|
||||||
|
OR: [{ targetLocales: { isEmpty: true } }, { targetLocales: { has: locale } }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
: undefined
|
||||||
|
|
||||||
const announcements = await db.announcement.findMany({
|
const announcements = await db.announcement.findMany({
|
||||||
where: {
|
where: {
|
||||||
placement,
|
placement,
|
||||||
isVisible: true,
|
isVisible: true,
|
||||||
OR: [{ startsAt: null }, { startsAt: { lte: now } }],
|
OR: [{ startsAt: null }, { startsAt: { lte: now } }],
|
||||||
AND: [{ OR: [{ endsAt: null }, { endsAt: { gte: now } }] }],
|
AND: [{ OR: [{ endsAt: null }, { endsAt: { gte: now } }] }],
|
||||||
|
...(localeFilter ?? {}),
|
||||||
},
|
},
|
||||||
orderBy: [{ priority: "asc" }, { createdAt: "desc" }],
|
orderBy: [{ priority: "asc" }, { createdAt: "desc" }],
|
||||||
select: {
|
select: {
|
||||||
@@ -66,6 +80,7 @@ export async function listActiveAnnouncements(
|
|||||||
ctaLabel: true,
|
ctaLabel: true,
|
||||||
ctaHref: true,
|
ctaHref: true,
|
||||||
placement: true,
|
placement: true,
|
||||||
|
targetLocales: true,
|
||||||
priority: true,
|
priority: true,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {
|
|||||||
createCommissionInputSchema,
|
createCommissionInputSchema,
|
||||||
createCustomerInputSchema,
|
createCustomerInputSchema,
|
||||||
createPublicCommissionRequestInputSchema,
|
createPublicCommissionRequestInputSchema,
|
||||||
|
updateCommissionInputSchema,
|
||||||
updateCommissionStatusInputSchema,
|
updateCommissionStatusInputSchema,
|
||||||
} from "@cms/content"
|
} from "@cms/content"
|
||||||
|
|
||||||
@@ -57,6 +58,16 @@ export async function createCommission(input: unknown) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function updateCommission(input: unknown) {
|
||||||
|
const payload = updateCommissionInputSchema.parse(input)
|
||||||
|
const { id, ...data } = payload
|
||||||
|
|
||||||
|
return db.commission.update({
|
||||||
|
where: { id },
|
||||||
|
data,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export async function createPublicCommissionRequest(input: unknown) {
|
export async function createPublicCommissionRequest(input: unknown) {
|
||||||
const payload = createPublicCommissionRequestInputSchema.parse(input)
|
const payload = createPublicCommissionRequestInputSchema.parse(input)
|
||||||
const normalizedEmail = payload.customerEmail.trim().toLowerCase()
|
const normalizedEmail = payload.customerEmail.trim().toLowerCase()
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ export {
|
|||||||
createPublicCommissionRequest,
|
createPublicCommissionRequest,
|
||||||
listCommissions,
|
listCommissions,
|
||||||
listCustomers,
|
listCustomers,
|
||||||
|
updateCommission,
|
||||||
updateCommissionStatus,
|
updateCommissionStatus,
|
||||||
} from "./commissions"
|
} from "./commissions"
|
||||||
export {
|
export {
|
||||||
@@ -24,6 +25,8 @@ export {
|
|||||||
createGallery,
|
createGallery,
|
||||||
createMediaAsset,
|
createMediaAsset,
|
||||||
createTag,
|
createTag,
|
||||||
|
deleteArtworkRendition,
|
||||||
|
deleteGrouping,
|
||||||
deleteMediaAsset,
|
deleteMediaAsset,
|
||||||
getMediaAssetById,
|
getMediaAssetById,
|
||||||
getMediaFoundationSummary,
|
getMediaFoundationSummary,
|
||||||
@@ -34,6 +37,8 @@ export {
|
|||||||
listMediaFoundationGroups,
|
listMediaFoundationGroups,
|
||||||
listPublishedArtworks,
|
listPublishedArtworks,
|
||||||
listPublishedPortfolioGroups,
|
listPublishedPortfolioGroups,
|
||||||
|
updateArtwork,
|
||||||
|
updateGrouping,
|
||||||
updateMediaAsset,
|
updateMediaAsset,
|
||||||
} from "./media-foundation"
|
} from "./media-foundation"
|
||||||
export type { PublicNavigationItem } from "./pages-navigation"
|
export type { PublicNavigationItem } from "./pages-navigation"
|
||||||
@@ -42,6 +47,7 @@ export {
|
|||||||
createNavigationMenu,
|
createNavigationMenu,
|
||||||
createPage,
|
createPage,
|
||||||
deleteNavigationItem,
|
deleteNavigationItem,
|
||||||
|
deleteNavigationMenu,
|
||||||
deletePage,
|
deletePage,
|
||||||
getPageById,
|
getPageById,
|
||||||
getPublishedPageBySlug,
|
getPublishedPageBySlug,
|
||||||
@@ -52,6 +58,7 @@ export {
|
|||||||
listPublicNavigation,
|
listPublicNavigation,
|
||||||
listPublishedPageSlugs,
|
listPublishedPageSlugs,
|
||||||
updateNavigationItem,
|
updateNavigationItem,
|
||||||
|
updateNavigationMenu,
|
||||||
updatePage,
|
updatePage,
|
||||||
upsertNavigationItemTranslation,
|
upsertNavigationItemTranslation,
|
||||||
upsertPageTranslation,
|
upsertPageTranslation,
|
||||||
|
|||||||
@@ -3,7 +3,10 @@ import {
|
|||||||
createArtworkInputSchema,
|
createArtworkInputSchema,
|
||||||
createGroupingInputSchema,
|
createGroupingInputSchema,
|
||||||
createMediaAssetInputSchema,
|
createMediaAssetInputSchema,
|
||||||
|
deleteGroupingInputSchema,
|
||||||
linkArtworkGroupingInputSchema,
|
linkArtworkGroupingInputSchema,
|
||||||
|
updateArtworkInputSchema,
|
||||||
|
updateGroupingInputSchema,
|
||||||
updateMediaAssetInputSchema,
|
updateMediaAssetInputSchema,
|
||||||
} from "@cms/content"
|
} from "@cms/content"
|
||||||
|
|
||||||
@@ -30,10 +33,14 @@ export async function listArtworks(limit = 24) {
|
|||||||
take: limit,
|
take: limit,
|
||||||
include: {
|
include: {
|
||||||
renditions: {
|
renditions: {
|
||||||
|
orderBy: [{ isPrimary: "desc" }, { updatedAt: "desc" }],
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
slot: true,
|
slot: true,
|
||||||
mediaAssetId: true,
|
mediaAssetId: true,
|
||||||
|
width: true,
|
||||||
|
height: true,
|
||||||
|
isPrimary: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
galleryLinks: {
|
galleryLinks: {
|
||||||
@@ -96,7 +103,7 @@ export async function listMediaFoundationGroups() {
|
|||||||
orderBy: [{ sortOrder: "asc" }, { name: "asc" }],
|
orderBy: [{ sortOrder: "asc" }, { name: "asc" }],
|
||||||
}),
|
}),
|
||||||
db.tag.findMany({
|
db.tag.findMany({
|
||||||
orderBy: { name: "asc" },
|
orderBy: [{ sortOrder: "asc" }, { name: "asc" }],
|
||||||
}),
|
}),
|
||||||
])
|
])
|
||||||
|
|
||||||
@@ -146,6 +153,16 @@ export async function createArtwork(input: unknown) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function updateArtwork(input: unknown) {
|
||||||
|
const payload = updateArtworkInputSchema.parse(input)
|
||||||
|
const { id, ...data } = payload
|
||||||
|
|
||||||
|
return db.artwork.update({
|
||||||
|
where: { id },
|
||||||
|
data,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export async function createGallery(input: unknown) {
|
export async function createGallery(input: unknown) {
|
||||||
const payload = createGroupingInputSchema.parse(input)
|
const payload = createGroupingInputSchema.parse(input)
|
||||||
|
|
||||||
@@ -171,18 +188,76 @@ export async function createCategory(input: unknown) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function createTag(input: unknown) {
|
export async function createTag(input: unknown) {
|
||||||
const payload = createGroupingInputSchema
|
const payload = createGroupingInputSchema.parse(input)
|
||||||
.pick({
|
|
||||||
name: true,
|
|
||||||
slug: true,
|
|
||||||
})
|
|
||||||
.parse(input)
|
|
||||||
|
|
||||||
return db.tag.create({
|
return db.tag.create({
|
||||||
data: payload,
|
data: payload,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function updateGrouping(input: unknown) {
|
||||||
|
const payload = updateGroupingInputSchema.parse(input)
|
||||||
|
const data = {
|
||||||
|
name: payload.name,
|
||||||
|
slug: payload.slug,
|
||||||
|
description: payload.description ?? null,
|
||||||
|
sortOrder: payload.sortOrder,
|
||||||
|
isVisible: payload.isVisible,
|
||||||
|
}
|
||||||
|
|
||||||
|
if (payload.groupType === "gallery") {
|
||||||
|
return db.gallery.update({
|
||||||
|
where: { id: payload.groupId },
|
||||||
|
data,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (payload.groupType === "album") {
|
||||||
|
return db.album.update({
|
||||||
|
where: { id: payload.groupId },
|
||||||
|
data,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (payload.groupType === "category") {
|
||||||
|
return db.category.update({
|
||||||
|
where: { id: payload.groupId },
|
||||||
|
data,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return db.tag.update({
|
||||||
|
where: { id: payload.groupId },
|
||||||
|
data,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function deleteGrouping(input: unknown) {
|
||||||
|
const payload = deleteGroupingInputSchema.parse(input)
|
||||||
|
|
||||||
|
if (payload.groupType === "gallery") {
|
||||||
|
return db.gallery.delete({
|
||||||
|
where: { id: payload.groupId },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (payload.groupType === "album") {
|
||||||
|
return db.album.delete({
|
||||||
|
where: { id: payload.groupId },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (payload.groupType === "category") {
|
||||||
|
return db.category.delete({
|
||||||
|
where: { id: payload.groupId },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return db.tag.delete({
|
||||||
|
where: { id: payload.groupId },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export async function linkArtworkToGrouping(input: unknown) {
|
export async function linkArtworkToGrouping(input: unknown) {
|
||||||
const payload = linkArtworkGroupingInputSchema.parse(input)
|
const payload = linkArtworkGroupingInputSchema.parse(input)
|
||||||
|
|
||||||
@@ -269,6 +344,12 @@ export async function attachArtworkRendition(input: unknown) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function deleteArtworkRendition(id: string) {
|
||||||
|
return db.artworkRendition.delete({
|
||||||
|
where: { id },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export async function getMediaFoundationSummary() {
|
export async function getMediaFoundationSummary() {
|
||||||
const [mediaAssets, artworks, galleries, albums, categories, tags] = await Promise.all([
|
const [mediaAssets, artworks, galleries, albums, categories, tags] = await Promise.all([
|
||||||
db.mediaAsset.count(),
|
db.mediaAsset.count(),
|
||||||
@@ -325,7 +406,10 @@ export async function listPublishedPortfolioGroups() {
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
db.tag.findMany({
|
db.tag.findMany({
|
||||||
orderBy: [{ name: "asc" }],
|
where: {
|
||||||
|
isVisible: true,
|
||||||
|
},
|
||||||
|
orderBy: [{ sortOrder: "asc" }, { name: "asc" }],
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
name: true,
|
name: true,
|
||||||
@@ -381,6 +465,7 @@ export async function listPublishedArtworks(input: ListPublishedArtworksInput =
|
|||||||
some: {
|
some: {
|
||||||
tag: {
|
tag: {
|
||||||
slug: input.groupSlug,
|
slug: input.groupSlug,
|
||||||
|
isVisible: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -398,6 +483,7 @@ export async function listPublishedArtworks(input: ListPublishedArtworksInput =
|
|||||||
isPublished: true,
|
isPublished: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
orderBy: [{ isPrimary: "desc" }, { updatedAt: "desc" }],
|
||||||
include: {
|
include: {
|
||||||
mediaAsset: {
|
mediaAsset: {
|
||||||
select: {
|
select: {
|
||||||
@@ -472,6 +558,7 @@ export async function getPublishedArtworkBySlug(slug: string) {
|
|||||||
isPublished: true,
|
isPublished: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
orderBy: [{ isPrimary: "desc" }, { updatedAt: "desc" }],
|
||||||
include: {
|
include: {
|
||||||
mediaAsset: {
|
mediaAsset: {
|
||||||
select: {
|
select: {
|
||||||
@@ -484,6 +571,11 @@ export async function getPublishedArtworkBySlug(slug: string) {
|
|||||||
source: true,
|
source: true,
|
||||||
author: true,
|
author: true,
|
||||||
copyright: true,
|
copyright: true,
|
||||||
|
licenseType: true,
|
||||||
|
licenseUrl: true,
|
||||||
|
usageContext: true,
|
||||||
|
location: true,
|
||||||
|
capturedAt: true,
|
||||||
tags: true,
|
tags: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {
|
|||||||
createNavigationMenuInputSchema,
|
createNavigationMenuInputSchema,
|
||||||
createPageInputSchema,
|
createPageInputSchema,
|
||||||
updateNavigationItemInputSchema,
|
updateNavigationItemInputSchema,
|
||||||
|
updateNavigationMenuInputSchema,
|
||||||
updatePageInputSchema,
|
updatePageInputSchema,
|
||||||
upsertPageTranslationInputSchema,
|
upsertPageTranslationInputSchema,
|
||||||
} from "@cms/content"
|
} from "@cms/content"
|
||||||
@@ -297,6 +298,22 @@ export async function createNavigationMenu(input: unknown) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function updateNavigationMenu(input: unknown) {
|
||||||
|
const payload = updateNavigationMenuInputSchema.parse(input)
|
||||||
|
const { id, ...data } = payload
|
||||||
|
|
||||||
|
return db.navigationMenu.update({
|
||||||
|
where: { id },
|
||||||
|
data,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function deleteNavigationMenu(id: string) {
|
||||||
|
return db.navigationMenu.delete({
|
||||||
|
where: { id },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export async function createNavigationItem(input: unknown) {
|
export async function createNavigationItem(input: unknown) {
|
||||||
const payload = createNavigationItemInputSchema.parse(input)
|
const payload = createNavigationItemInputSchema.parse(input)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user