Compare commits
25 Commits
todo/mvp1-
...
todo/mvp1-
| Author | SHA1 | Date | |
|---|---|---|---|
|
a2bea6326e
|
|||
|
60c9035743
|
|||
|
741883465c
|
|||
|
7a82934fe7
|
|||
|
473433b220
|
|||
|
987843d96b
|
|||
|
c6ebf3759a
|
|||
|
81983cfe40
|
|||
|
697b3ab5e7
|
|||
|
984511f166
|
|||
|
b9424c8a8b
|
|||
|
6e9c0ad4e5
|
|||
|
d016650463
|
|||
|
be6969c30f
|
|||
|
1f29594b7a
|
|||
|
47e59d2926
|
|||
|
958f3ad723
|
|||
|
1fddb6d858
|
|||
|
dc0a41a5ae
|
|||
|
a7895e4dd9
|
|||
|
618319dbc2
|
|||
|
506e2feb10
|
|||
|
749fb80083
|
|||
|
ec4f85e1d0
|
|||
|
6b282ce56b
|
@@ -10,6 +10,11 @@ CMS_SUPPORT_EMAIL="support@cms.local"
|
||||
CMS_SUPPORT_PASSWORD="change-me-support-password"
|
||||
CMS_SUPPORT_NAME="Technical Support"
|
||||
CMS_SUPPORT_LOGIN_KEY="support-access-change-me"
|
||||
# Optional deterministic e2e admin user (seeded by `bun run test:e2e:prepare`)
|
||||
# CMS_E2E_ADMIN_EMAIL="e2e-admin@cms.local"
|
||||
# CMS_E2E_ADMIN_USERNAME="e2e-admin"
|
||||
# CMS_E2E_ADMIN_PASSWORD="e2e-admin-password"
|
||||
# CMS_E2E_ADMIN_NAME="E2E Admin"
|
||||
CMS_MEDIA_STORAGE_PROVIDER="s3"
|
||||
CMS_MEDIA_STORAGE_TENANT_ID="default"
|
||||
CMS_MEDIA_UPLOAD_MAX_BYTES="26214400"
|
||||
|
||||
@@ -55,7 +55,7 @@ jobs:
|
||||
run: bun run commitlint
|
||||
|
||||
quality:
|
||||
name: Lint Typecheck Unit E2E
|
||||
name: Lint Typecheck (Testing Paused)
|
||||
needs: governance
|
||||
runs-on: node22-bun
|
||||
services:
|
||||
@@ -90,9 +90,6 @@ jobs:
|
||||
echo "NEXT_PUBLIC_APP_VERSION=$version" >> "$GITHUB_ENV"
|
||||
echo "NEXT_PUBLIC_GIT_SHA=${GITHUB_SHA}" >> "$GITHUB_ENV"
|
||||
|
||||
- name: Install Playwright browser deps
|
||||
run: bunx playwright install --with-deps chromium
|
||||
|
||||
- name: Lint and format checks
|
||||
run: bun run check
|
||||
|
||||
@@ -101,9 +98,3 @@ jobs:
|
||||
|
||||
- name: Typecheck
|
||||
run: bun run typecheck
|
||||
|
||||
- name: Unit and integration tests
|
||||
run: bun run test
|
||||
|
||||
- name: E2E tests
|
||||
run: bun run test:e2e
|
||||
|
||||
53
CHANGELOG.md
53
CHANGELOG.md
@@ -1,3 +1,56 @@
|
||||
## Unreleased (2026-02-12)
|
||||
|
||||
* test(admin): cover support fallback route and mark todo complete ([4ac74101487e0bb220215328510fd4344c9110e3](https://git.fellies.net/Citali/cms.fellies.org/commits/4ac74101487e0bb220215328510fd4344c9110e3))
|
||||
* test(auth): add registration policy route-flow integration tests ([39178c2d8d9c203ceca63a36012b58173d21d4d4](https://git.fellies.net/Citali/cms.fellies.org/commits/39178c2d8d9c203ceca63a36012b58173d21d4d4))
|
||||
* test(ci): add quality gates, e2e data prep, and i18n integration coverage ([4d4b583cf4dcb0f3b99f74c666af15d3b1a0fc59](https://git.fellies.net/Citali/cms.fellies.org/commits/4d4b583cf4dcb0f3b99f74c666af15d3b1a0fc59))
|
||||
* test(crud): finalize MVP1 gate CRUD contract coverage ([36b09cd9d76049219569bb4828aa292aec78a935](https://git.fellies.net/Citali/cms.fellies.org/commits/36b09cd9d76049219569bb4828aa292aec78a935))
|
||||
* test(e2e): add mvp1 happy path scenarios ([7c4b667bc79a022518d03a52a98060a9c86c673c](https://git.fellies.net/Citali/cms.fellies.org/commits/7c4b667bc79a022518d03a52a98060a9c86c673c))
|
||||
* test(mvp0): complete remaining i18n, RBAC, and CRUD coverage ([3b130568e9bfff9e428c3650c37dd8b1abfbed57](https://git.fellies.net/Citali/cms.fellies.org/commits/3b130568e9bfff9e428c3650c37dd8b1abfbed57))
|
||||
* test(mvp1): add owner invariants and media form coverage ([37f62a8007d6b50e7b53e5785365965c00c74a5b](https://git.fellies.net/Citali/cms.fellies.org/commits/37f62a8007d6b50e7b53e5785365965c00c74a5b))
|
||||
* test(mvp1): expand domain schema and service unit coverage ([24676bd384c39d954b791ff2322a4469ab86a83a](https://git.fellies.net/Citali/cms.fellies.org/commits/24676bd384c39d954b791ff2322a4469ab86a83a))
|
||||
* feat(admin-auth): add first-start onboarding flow and dev db reset command ([7b665ae633e869560654cf1c115d12dc05af1c45](https://git.fellies.net/Citali/cms.fellies.org/commits/7b665ae633e869560654cf1c115d12dc05af1c45))
|
||||
* feat(admin-auth): support username login and add dashboard logout ([b96cd6d8005aea50c49a70540e0fd2afff94c682](https://git.fellies.net/Citali/cms.fellies.org/commits/b96cd6d8005aea50c49a70540e0fd2afff94c682))
|
||||
* feat(admin-i18n): add cookie-based locale runtime and switcher baseline ([b618c8cb5161eef46e80d622156a1e53a732ea35](https://git.fellies.net/Citali/cms.fellies.org/commits/b618c8cb5161eef46e80d622156a1e53a732ea35))
|
||||
* feat(admin): add IA shell and protected section skeleton routes ([bf1a92d129b89811b58d6920a4e09482816988a0](https://git.fellies.net/Citali/cms.fellies.org/commits/bf1a92d129b89811b58d6920a4e09482816988a0))
|
||||
* feat(admin): add posts CRUD sandbox and shared CRUD foundation ([07e5f53793da5aa0b17e62a3a9b99c23a56dbcf0](https://git.fellies.net/Citali/cms.fellies.org/commits/07e5f53793da5aa0b17e62a3a9b99c23a56dbcf0))
|
||||
* feat(admin): add registration policy settings and disabled register state ([d0f731743c789ef836e4573eadece2f4c67c973d](https://git.fellies.net/Citali/cms.fellies.org/commits/d0f731743c789ef836e4573eadece2f4c67c973d))
|
||||
* feat(auth): block protected account deletion in auth endpoints ([0e2248b5c7f72684e4db6d4ab8f306b10f50ac66](https://git.fellies.net/Citali/cms.fellies.org/commits/0e2248b5c7f72684e4db6d4ab8f306b10f50ac66))
|
||||
* feat(auth): bootstrap protected support and first owner users ([411861419f160e3573a71ea67d57af7e0e91de7d](https://git.fellies.net/Citali/cms.fellies.org/commits/411861419f160e3573a71ea67d57af7e0e91de7d))
|
||||
* feat(auth): enforce single-owner invariant in bootstrap flow ([29a6e38ff3b725e4232736c4b5b007a2989acb82](https://git.fellies.net/Citali/cms.fellies.org/commits/29a6e38ff3b725e4232736c4b5b007a2989acb82))
|
||||
* feat(ci): stamp build metadata and validate footer version hash ([af52b8581f7dbe320c92752fcc56b73e37f0c2ba](https://git.fellies.net/Citali/cms.fellies.org/commits/af52b8581f7dbe320c92752fcc56b73e37f0c2ba))
|
||||
* feat(commissions): add customer records and kanban workflow baseline ([994b33e081c3507cbf88820028b819a4fc4b07a0](https://git.fellies.net/Citali/cms.fellies.org/commits/994b33e081c3507cbf88820028b819a4fc4b07a0))
|
||||
* feat(content): add announcements and public news flows ([dbf817c25511b3038b7abe81e4577d3518fd3f19](https://git.fellies.net/Citali/cms.fellies.org/commits/dbf817c25511b3038b7abe81e4577d3518fd3f19))
|
||||
* feat(media): add admin media CRUD preview and storage cleanup ([7d9bc9dca9197e87cc590ad6b49837c5774fcd4f](https://git.fellies.net/Citali/cms.fellies.org/commits/7d9bc9dca9197e87cc590ad6b49837c5774fcd4f))
|
||||
* feat(media): add mvp1 upload pipeline baseline ([5becba602c3aaefbe24ec71414f62b29a155d158](https://git.fellies.net/Citali/cms.fellies.org/commits/5becba602c3aaefbe24ec71414f62b29a155d158))
|
||||
* feat(media): complete mvp1 media foundation workflows ([ad351ed73ab7c76a9e751348ebf943aec5f0d084](https://git.fellies.net/Citali/cms.fellies.org/commits/ad351ed73ab7c76a9e751348ebf943aec5f0d084))
|
||||
* feat(media): default to s3 with local upload fallback ([86a8af25d8c28c2ab19039b56b1c69263c7450c5](https://git.fellies.net/Citali/cms.fellies.org/commits/86a8af25d8c28c2ab19039b56b1c69263c7450c5))
|
||||
* feat(media): scaffold mvp1 media and portfolio foundation ([d727ab8b5b896e5471829a6a1880dc33da28d070](https://git.fellies.net/Citali/cms.fellies.org/commits/d727ab8b5b896e5471829a6a1880dc33da28d070))
|
||||
* feat(media): support local and s3 upload providers ([19738b77d8842f3263e7f049aa47063dcfbd4ae6](https://git.fellies.net/Citali/cms.fellies.org/commits/19738b77d8842f3263e7f049aa47063dcfbd4ae6))
|
||||
* feat(pages): add pages and navigation builder baseline ([281b1d7a1be72af4cff790ca7e97d51cafcd8139](https://git.fellies.net/Citali/cms.fellies.org/commits/281b1d7a1be72af4cff790ca7e97d51cafcd8139))
|
||||
* feat(release): publish gitea release notes and enable production rollback ([ccac669454b46a3918b34df1d3c5f0e5f00aa1d9](https://git.fellies.net/Citali/cms.fellies.org/commits/ccac669454b46a3918b34df1d3c5f0e5f00aa1d9))
|
||||
* feat(settings): manage public header banner in admin ([d1face36c540673486b494d276f5af1621b6e6cb](https://git.fellies.net/Citali/cms.fellies.org/commits/d1face36c540673486b494d276f5af1621b6e6cb))
|
||||
* feat(versioning): show runtime version and git hash in app footers ([3de4d5732e26e06e825986e58ec271d0f0ff4007](https://git.fellies.net/Citali/cms.fellies.org/commits/3de4d5732e26e06e825986e58ec271d0f0ff4007))
|
||||
* feat(web-i18n): add es/fr locales and expand switcher locale set ([de26cb7647cf537a783cc9c77ae447a0f8a09ef6](https://git.fellies.net/Citali/cms.fellies.org/commits/de26cb7647cf537a783cc9c77ae447a0f8a09ef6))
|
||||
* feat(web): complete MVP0 public layout, banner, and SEO baseline ([8390689c8dd81dca5662b842c827a4759a9025e1](https://git.fellies.net/Citali/cms.fellies.org/commits/8390689c8dd81dca5662b842c827a4759a9025e1))
|
||||
* feat(web): render cms pages and navigation from db ([f65a9ea03f39c21ee9b31e7f9100e3a1f522525f](https://git.fellies.net/Citali/cms.fellies.org/commits/f65a9ea03f39c21ee9b31e7f9100e3a1f522525f))
|
||||
* refactor(db): simplify to single prisma schema workflow ([df1280af4a1d24bd9374fc9a005cea9142745d46](https://git.fellies.net/Citali/cms.fellies.org/commits/df1280af4a1d24bd9374fc9a005cea9142745d46))
|
||||
* refactor(media): use asset-centric storage key layout ([3e4f0b6c75c59422675637bf658b6682c22f4a89](https://git.fellies.net/Citali/cms.fellies.org/commits/3e4f0b6c75c59422675637bf658b6682c22f4a89))
|
||||
* docs(adr): add glossary pages and ADR baseline structure ([cec87679ca5efcf70883b6c78245f8197a8a4432](https://git.fellies.net/Citali/cms.fellies.org/commits/cec87679ca5efcf70883b6c78245f8197a8a4432))
|
||||
* docs(crud): add implementation examples and complete docs task ([7b4b23fc4ffdd7e6be8af9da6b2026067acbd35e](https://git.fellies.net/Citali/cms.fellies.org/commits/7b4b23fc4ffdd7e6be8af9da6b2026067acbd35e))
|
||||
* docs(gitflow): add branch protection verification checklist ([f9f2b4eb15bd42690891bdc8e4d34c5e55c343dc](https://git.fellies.net/Citali/cms.fellies.org/commits/f9f2b4eb15bd42690891bdc8e4d34c5e55c343dc))
|
||||
* docs(i18n): add conventions guide and wire docs navigation ([5872593b014e527ef884ea89053f9cf191edf5dc](https://git.fellies.net/Citali/cms.fellies.org/commits/5872593b014e527ef884ea89053f9cf191edf5dc))
|
||||
* docs(ops): add environment and deployment runbook ([4d6e17a13b3ee4a00d93713a223871e96ee94550](https://git.fellies.net/Citali/cms.fellies.org/commits/4d6e17a13b3ee4a00d93713a223871e96ee94550))
|
||||
* docs(ops): add staging deployment checklist and evidence template ([637dfd2651a8ad7b0900c0a87c714da7750aaae2](https://git.fellies.net/Citali/cms.fellies.org/commits/637dfd2651a8ad7b0900c0a87c714da7750aaae2))
|
||||
* docs(product): add cms feature topics, package catalog, and inspiration notes ([5b47fafe89e7d1e4fb42646f8bac0e2423828c07](https://git.fellies.net/Citali/cms.fellies.org/commits/5b47fafe89e7d1e4fb42646f8bac0e2423828c07))
|
||||
* docs(versioning): define release policy and close MVP0 pipeline tasks ([516b7730128951a9f0527b89291b21e14e35aca2](https://git.fellies.net/Citali/cms.fellies.org/commits/516b7730128951a9f0527b89291b21e14e35aca2))
|
||||
* chore(ci): add gitea actions runner compose setup ([334a5e35264bf57f1f3586bd78364a5b1d704876](https://git.fellies.net/Citali/cms.fellies.org/commits/334a5e35264bf57f1f3586bd78364a5b1d704876))
|
||||
* chore(repo): remove theoretical workflow and fix prisma ci generation ([a57464d818c10caa2732c1aac113d9a251342de1](https://git.fellies.net/Citali/cms.fellies.org/commits/a57464d818c10caa2732c1aac113d9a251342de1))
|
||||
* chore(repo): update turbo dependency ([37fabad1f8ceb6224c892facb60b5aa2bca02cc5](https://git.fellies.net/Citali/cms.fellies.org/commits/37fabad1f8ceb6224c892facb60b5aa2bca02cc5))
|
||||
* fix(ci): gitea workflows ([c174f840bcfa297937fa40bc3ce4593ddc8ca599](https://git.fellies.net/Citali/cms.fellies.org/commits/c174f840bcfa297937fa40bc3ce4593ddc8ca599))
|
||||
* fix(db): organize imports for biome check ([14c3df623a84a3307d4e825bbf36cccfd882eb49](https://git.fellies.net/Citali/cms.fellies.org/commits/14c3df623a84a3307d4e825bbf36cccfd882eb49))
|
||||
* ci(delivery): add deploy and release workflow scaffolds ([969e88670f5cb3dd0156e4a53bd84d729be4fe82](https://git.fellies.net/Citali/cms.fellies.org/commits/969e88670f5cb3dd0156e4a53bd84d729be4fe82))
|
||||
* ci(gitflow): enforce branch and PR governance checks ([21cc55a1b93f9c7d5ec0db7643f6fe895312a325](https://git.fellies.net/Citali/cms.fellies.org/commits/21cc55a1b93f9c7d5ec0db7643f6fe895312a325))
|
||||
|
||||
## 0.1.0 (2026-02-10)
|
||||
|
||||
### Features
|
||||
|
||||
@@ -46,7 +46,7 @@ Rules:
|
||||
## Changelog Process
|
||||
|
||||
- Keep commit messages conventional.
|
||||
- Generate/update `CHANGELOG.md` with:
|
||||
- Generate/update `CHANGELOG.md` with release-focused sections (includes `Unreleased`):
|
||||
|
||||
```bash
|
||||
bun run changelog:release
|
||||
@@ -57,3 +57,10 @@ bun run changelog:release
|
||||
```bash
|
||||
bun run changelog:preview
|
||||
```
|
||||
|
||||
- For exhaustive output across all allowed commit types (`feat`, `fix`, `docs`, `test`, `ci`, `chore`, `refactor`, etc.):
|
||||
|
||||
```bash
|
||||
bun run changelog:full:preview
|
||||
bun run changelog:full:release
|
||||
```
|
||||
|
||||
@@ -138,7 +138,7 @@ docker compose --env-file .env.gitea-runner -f docker-compose.gitea-runner.yml u
|
||||
|
||||
- Changelog file: `CHANGELOG.md`
|
||||
- Commit schema: Conventional Commits (see `CONTRIBUTING.md`)
|
||||
- Generate/update changelog from git commits:
|
||||
- Generate/update changelog from git commits (release-focused sections + `Unreleased`):
|
||||
|
||||
```bash
|
||||
bun run changelog:release
|
||||
@@ -150,6 +150,13 @@ bun run changelog:release
|
||||
bun run changelog:preview
|
||||
```
|
||||
|
||||
- Generate exhaustive changelog output across all supported commit types:
|
||||
|
||||
```bash
|
||||
bun run changelog:full:preview
|
||||
bun run changelog:full:release
|
||||
```
|
||||
|
||||
## Docs Tool
|
||||
|
||||
- Docs tool: VitePress
|
||||
|
||||
175
TODO.md
175
TODO.md
@@ -59,15 +59,7 @@ This file is the single source of truth for roadmap and delivery progress.
|
||||
|
||||
### Testing
|
||||
|
||||
- [x] [P1] Vitest + Testing Library + MSW baseline
|
||||
- [x] [P1] Playwright baseline with web/admin projects
|
||||
- [x] [P1] CI workflow for lint/typecheck/unit/e2e gates
|
||||
- [x] [P1] Test data strategy (seed fixtures + isolated e2e data)
|
||||
- [x] [P1] RBAC policy unit tests and permission regression suite
|
||||
- [x] [P1] i18n unit tests (locale resolution, fallback, message key loading)
|
||||
- [x] [P1] i18n integration tests (admin/public locale switch and persistence)
|
||||
- [x] [P1] i18n e2e smoke tests (localized headings/content per route)
|
||||
- [x] [P1] CRUD contract tests for shared service patterns
|
||||
- [~] [P1] Testing workstream moved to `MVP 3: Testing and Quality` and temporarily paused to prioritize feature delivery
|
||||
|
||||
### Documentation
|
||||
|
||||
@@ -126,9 +118,9 @@ 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)
|
||||
- [~] [P1] `todo/mvp1-commissions-customers`:
|
||||
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
|
||||
- [~] [P1] `todo/mvp1-public-rendering-integration`:
|
||||
- [x] [P1] `todo/mvp1-public-rendering-integration`:
|
||||
public rendering for pages/navigation/media/portfolio/announcements and commissioning entrypoints
|
||||
- [~] [P1] `todo/mvp1-e2e-happy-paths`:
|
||||
end-to-end scenarios for page publish, media flow, announcement display, commission flow
|
||||
@@ -145,81 +137,92 @@ This file is the single source of truth for roadmap and delivery progress.
|
||||
### Admin App (Primary Focus)
|
||||
|
||||
- [~] [P1] Page management (create/edit/publish/unpublish/schedule)
|
||||
- [ ] [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] Page builder with reusable content blocks (hero, rich text, gallery, CTA, forms, price cards)
|
||||
- [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 enrichment metadata (alt text, copyright, author, source, tags, licensing, usage context)
|
||||
- [ ] [P1] Portfolio grouping primitives (galleries, albums, categories, tags) with ordering/visibility controls
|
||||
- [ ] [P1] Artwork refinement fields (medium, dimensions, year, framing, availability, price visibility)
|
||||
- [ ] [P1] Artwork rendition management (thumbnail, card, full, retina/custom sizes)
|
||||
- [ ] [P1] Type-specific processing presets (artwork/banner/promo/video/gif) with validation rules
|
||||
- [ ] [P1] Users management (invite, roles, status)
|
||||
- [ ] [P1] Disable/ban user function and enforcement in auth/session checks
|
||||
- [~] [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)
|
||||
- [~] [P1] Customer records (contact profile, notes, consent flags, recurrence marker)
|
||||
- [~] [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] Media enrichment metadata (alt text, copyright, author, source, tags, licensing, usage context)
|
||||
- [x] [P1] Portfolio grouping primitives (galleries, albums, categories, tags) with ordering/visibility controls
|
||||
- [x] [P1] Artwork refinement fields (medium, dimensions, year, framing, availability, price visibility)
|
||||
- [x] [P1] Artwork rendition management (thumbnail, card, full, retina/custom sizes)
|
||||
- [x] [P1] Type-specific processing presets (artwork/banner/promo/video/gif) with validation rules
|
||||
- [x] [P1] Users management (invite, roles, status)
|
||||
- [x] [P1] Disable/ban user function and enforcement in auth/session checks
|
||||
- [x] [P1] Owner/support protection rules in user management actions (cannot delete/demote)
|
||||
- [x] [P1] Commissions management (request intake, owner, due date, notes, linked customer, linked artworks)
|
||||
- [x] [P1] Customer records (contact profile, notes, consent flags, recurrence marker)
|
||||
- [x] [P1] Customer-to-commission linkage and reuse workflow (no re-entry for recurring customers)
|
||||
- [x] [P1] Kanban workflow for commissions (new, scoped, in-progress, review, done)
|
||||
- [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)
|
||||
|
||||
### Public App
|
||||
|
||||
- [~] [P1] Dynamic page rendering from CMS page entities
|
||||
- [~] [P1] Navigation rendering from managed menu structure
|
||||
- [ ] [P1] Media entity rendering with enrichment data
|
||||
- [ ] [P1] Portfolio views (gallery/album/category/tag) for artworks with filter and sort controls
|
||||
- [ ] [P1] Rendition-aware media delivery (thumbnail/card/full) per template slot
|
||||
- [ ] [P1] Translation-ready content model for public entities (pages/news/navigation labels)
|
||||
- [x] [P1] Dynamic page rendering from CMS page entities
|
||||
- [x] [P1] Navigation rendering from managed menu structure
|
||||
- [x] [P1] Media entity rendering with enrichment data
|
||||
- [x] [P1] Portfolio views (gallery/album/category/tag) for artworks with filter and sort controls
|
||||
- [x] [P1] Rendition-aware media delivery (thumbnail/card/full) per template slot
|
||||
- [x] [P1] Translation-ready content model for public entities (pages/news/navigation labels)
|
||||
- [ ] [P2] Artwork views and listing filters
|
||||
- [ ] [P1] Commission request submission flow
|
||||
- [x] [P1] Commission request submission flow
|
||||
- [x] [P1] Header banner render logic and fallbacks
|
||||
- [ ] [P1] Announcement render slots (homepage + optional global/top banner position)
|
||||
- [x] [P1] Announcement render slots (homepage + optional global/top banner position)
|
||||
|
||||
### News / Blog (Secondary Track)
|
||||
|
||||
- [~] [P1] News/blog content type (editorial content for artist updates and process posts)
|
||||
- [~] [P1] Admin list/editor for news posts
|
||||
- [~] [P1] Public news index + detail pages
|
||||
- [x] [P1] News/blog content type (editorial content for artist updates and process posts)
|
||||
- [x] [P1] Admin list/editor for news posts
|
||||
- [x] [P1] Public news index + detail pages
|
||||
- [ ] [P2] Tag/category and basic archive support
|
||||
|
||||
### Testing
|
||||
|
||||
- [x] [P1] Unit tests for content schemas and service logic
|
||||
- [~] [P1] Component tests for admin forms (pages/media/navigation)
|
||||
- [x] [P1] Integration tests for owner invariant and hidden support-user protection
|
||||
- [x] [P1] Integration tests for registration allow/deny behavior
|
||||
- [ ] [P1] Integration tests for translated content CRUD and locale-specific validation
|
||||
- [~] [P1] E2E happy paths: create page, publish, see on public app
|
||||
- [~] [P1] E2E happy paths: media upload + artwork refinement display
|
||||
- [~] [P1] E2E happy paths: commissions kanban transitions
|
||||
- [~] [P1] Testing workstream moved to `MVP 3: Testing and Quality` and temporarily paused to prioritize feature delivery
|
||||
|
||||
### Code Documentation And Handover
|
||||
|
||||
- [ ] [P1] Create architecture map per package/app (`what exists`, `why`, `how to extend`) for `@cms/db`, `@cms/content`, `@cms/crud`, `@cms/ui`, `apps/admin`, `apps/web`
|
||||
- [ ] [P1] Add module-level ownership docs for auth, media, pages/navigation, commissions, announcements/news flows
|
||||
- [ ] [P1] Document critical invariants (single owner rule, protected support user, registration policy gates, media storage key contract)
|
||||
- [ ] [P1] Add “request lifecycle” docs for key flows (auth sign-in/up, media upload, page publish, commission status change)
|
||||
- [ ] [P1] Add coding handover playbook: local setup, migration workflow, test strategy, branch/release process, common failure recovery
|
||||
- [x] [P1] Create architecture map per package/app (`what exists`, `why`, `how to extend`) for `@cms/db`, `@cms/content`, `@cms/crud`, `@cms/ui`, `apps/admin`, `apps/web`
|
||||
- [x] [P1] Add module-level ownership docs for auth, media, pages/navigation, commissions, announcements/news flows
|
||||
- [x] [P1] Document critical invariants (single owner rule, protected support user, registration policy gates, media storage key contract)
|
||||
- [x] [P1] Add “request lifecycle” docs for key flows (auth sign-in/up, media upload, page publish, commission status change)
|
||||
- [x] [P1] Add coding handover playbook: local setup, migration workflow, test strategy, branch/release process, common failure recovery
|
||||
- [ ] [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
|
||||
|
||||
## 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
|
||||
- [ ] [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
|
||||
- [ ] [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
|
||||
- [ ] [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)
|
||||
- [ ] [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
|
||||
- [ ] [P2] `todo/mvp15-visual-regression-baseline`:
|
||||
- [ ] [P2] `todo/mvp3-visual-regression-baseline`:
|
||||
add screenshot baselines for critical admin/public routes to guard layout regressions
|
||||
|
||||
### Deliverables
|
||||
@@ -229,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] Core routes have visual-regression coverage for the new layout baseline
|
||||
|
||||
## MVP 2: Production Readiness
|
||||
## MVP 4: Production Readiness
|
||||
|
||||
### Admin App
|
||||
|
||||
@@ -268,6 +271,38 @@ This file is the single source of truth for roadmap and delivery progress.
|
||||
|
||||
### Testing
|
||||
|
||||
- [~] [P1] Testing workstream moved to `MVP 5: Testing and Quality` and temporarily paused to prioritize feature delivery
|
||||
|
||||
## MVP 5: Testing and Quality
|
||||
|
||||
### Status
|
||||
|
||||
- [~] [P1] Temporary freeze for active testing execution in local scripts and CI while MVP feature delivery is prioritized
|
||||
- [ ] [P1] Re-enable root package test scripts (`test`, `test:*`) after MVP feature catch-up
|
||||
- [ ] [P1] Re-enable CI quality test gates (unit + integration + e2e) in `.gitea/workflows/ci.yml`
|
||||
|
||||
### Baseline And Regression
|
||||
|
||||
- [x] [P1] Vitest + Testing Library + MSW baseline
|
||||
- [x] [P1] Playwright baseline with web/admin projects
|
||||
- [x] [P1] CI workflow for lint/typecheck/unit/e2e gates
|
||||
- [x] [P1] Test data strategy (seed fixtures + isolated e2e data)
|
||||
- [x] [P1] RBAC policy unit tests and permission regression suite
|
||||
- [x] [P1] i18n unit tests (locale resolution, fallback, message key loading)
|
||||
- [x] [P1] i18n integration tests (admin/public locale switch and persistence)
|
||||
- [x] [P1] i18n e2e smoke tests (localized headings/content per route)
|
||||
- [x] [P1] CRUD contract tests for shared service patterns
|
||||
- [x] [P1] Unit tests for content schemas and service logic
|
||||
- [x] [P1] Component tests for admin forms (pages/media/navigation)
|
||||
- [x] [P1] Integration tests for owner invariant and hidden support-user protection
|
||||
- [x] [P1] Integration tests for registration allow/deny behavior
|
||||
- [x] [P1] Integration tests for translated content CRUD and locale-specific validation
|
||||
- [~] [P1] E2E happy paths: create page, publish, see on public app
|
||||
- [~] [P1] E2E happy paths: media upload + artwork refinement display
|
||||
- [~] [P1] E2E happy paths: commissions kanban transitions
|
||||
|
||||
### Advanced Quality Work
|
||||
|
||||
- [ ] [P2] Visual regression workflow for critical templates
|
||||
- [ ] [P2] Load/perf tests for key public routes
|
||||
- [ ] [P2] Flake tracking and quarantine policy for e2e
|
||||
@@ -299,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] 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] 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] 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.
|
||||
@@ -308,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] 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] 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] 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.
|
||||
@@ -319,6 +355,25 @@ This file is the single source of truth for roadmap and delivery progress.
|
||||
- [2026-02-12] Admin settings now manage public header banner (enabled/message/CTA), backed by `system_setting` and consumed by public layout rendering.
|
||||
- [2026-02-12] Added owner/support invariant integration tests for auth guards (`apps/admin/src/lib/auth/server.test.ts`), covering protected-user deletion blocking and one-owner repair/promotion rules.
|
||||
- [2026-02-12] Started admin form component tests with media upload behavior coverage (`apps/admin/src/components/media/media-upload-form.test.tsx`).
|
||||
- [2026-02-12] Added code handover documentation baseline: architecture map, critical invariants, request lifecycles, and onboarding playbook under `docs/product-engineering/`.
|
||||
- [2026-02-12] Completed admin form component coverage for pages/navigation/media using isolated form components and tests.
|
||||
- [2026-02-12] Added page translation CRUD baseline (`PageTranslation`) with locale validation (`de/en/es/fr`) and integration coverage for localized read + fallback behavior.
|
||||
- [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 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 rendering integration completed: portfolio now supports locale-aware tag filters and explicit sort controls, while db/service sorting and rendition selection align public listing/detail media delivery.
|
||||
- [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] 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`.
|
||||
|
||||
## How We Use This File
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"build": "bun --env-file=../../.env next build",
|
||||
"start": "bun --env-file=../../.env next start --port 3001",
|
||||
"auth:seed:support": "bun --env-file=../../.env ./scripts/seed-support-user.ts",
|
||||
"auth:seed:e2e-admin": "bun --env-file=../../.env ./scripts/seed-e2e-admin-user.ts",
|
||||
"lint": "biome check src",
|
||||
"typecheck": "tsc -p tsconfig.json --noEmit"
|
||||
},
|
||||
|
||||
11
apps/admin/scripts/seed-e2e-admin-user.ts
Normal file
11
apps/admin/scripts/seed-e2e-admin-user.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { ensureE2EAdminBootstrap } from "../src/lib/auth/server"
|
||||
|
||||
async function main() {
|
||||
await ensureE2EAdminBootstrap()
|
||||
console.log("E2E admin bootstrap completed")
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
console.error(error)
|
||||
process.exit(1)
|
||||
})
|
||||
@@ -14,6 +14,7 @@ import { requirePermissionForRoute } from "@/lib/route-guards"
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
type SearchParamsInput = Record<string, string | string[] | undefined>
|
||||
const SUPPORTED_LOCALES = ["de", "en", "es", "fr"] as const
|
||||
|
||||
function readFirstValue(value: string | string[] | undefined): string | null {
|
||||
if (Array.isArray(value)) {
|
||||
@@ -49,6 +50,22 @@ function readNullableDate(formData: FormData, field: string): Date | null {
|
||||
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 {
|
||||
const value = readInputString(formData, field)
|
||||
|
||||
@@ -94,6 +111,7 @@ async function createAnnouncementAction(formData: FormData) {
|
||||
title: readInputString(formData, "title"),
|
||||
message: readInputString(formData, "message"),
|
||||
placement: readInputString(formData, "placement"),
|
||||
targetLocales: readLocaleSelections(formData, "targetLocales"),
|
||||
priority: readInt(formData, "priority", 100),
|
||||
ctaLabel: readNullableString(formData, "ctaLabel"),
|
||||
ctaHref: readNullableString(formData, "ctaHref"),
|
||||
@@ -125,6 +143,7 @@ async function updateAnnouncementAction(formData: FormData) {
|
||||
title: readInputString(formData, "title"),
|
||||
message: readInputString(formData, "message"),
|
||||
placement: readInputString(formData, "placement"),
|
||||
targetLocales: readLocaleSelections(formData, "targetLocales"),
|
||||
priority: readInt(formData, "priority", 100),
|
||||
ctaLabel: readNullableString(formData, "ctaLabel"),
|
||||
ctaHref: readNullableString(formData, "ctaHref"),
|
||||
@@ -277,6 +296,20 @@ export default async function AnnouncementsPage({
|
||||
/>
|
||||
</label>
|
||||
</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">
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs text-neutral-600">Starts at</span>
|
||||
@@ -390,6 +423,26 @@ export default async function AnnouncementsPage({
|
||||
/>
|
||||
</label>
|
||||
</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">
|
||||
<label className="inline-flex items-center gap-2 text-sm text-neutral-700">
|
||||
<input
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import { randomUUID } from "node:crypto"
|
||||
import {
|
||||
getMediaUploadMaxBytes,
|
||||
isMimeAllowedForMediaType,
|
||||
mediaAssetTypeSchema,
|
||||
} from "@cms/content"
|
||||
import { hasPermission } from "@cms/content/rbac"
|
||||
import { createMediaAsset } from "@cms/db"
|
||||
|
||||
@@ -7,33 +12,7 @@ import { storeUpload } from "@/lib/media/storage"
|
||||
|
||||
export const runtime = "nodejs"
|
||||
|
||||
const MAX_UPLOAD_BYTES = Number(process.env.CMS_MEDIA_UPLOAD_MAX_BYTES ?? 25 * 1024 * 1024)
|
||||
|
||||
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: "",
|
||||
},
|
||||
}
|
||||
const MAX_UPLOAD_BYTES_OVERRIDE = Number(process.env.CMS_MEDIA_UPLOAD_MAX_BYTES ?? 0)
|
||||
|
||||
function parseTextField(formData: FormData, field: string): string {
|
||||
const value = formData.get(field)
|
||||
@@ -58,6 +37,22 @@ function parseTags(formData: FormData): string[] {
|
||||
.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 {
|
||||
const trimmed = fileName.trim()
|
||||
|
||||
@@ -72,24 +67,6 @@ function deriveTitleFromFilename(fileName: string): string {
|
||||
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 {
|
||||
return Response.json(
|
||||
{
|
||||
@@ -131,12 +108,13 @@ export async function POST(request: Request): Promise<Response> {
|
||||
return badRequest("Invalid form payload.")
|
||||
}
|
||||
|
||||
const type = parseTextField(formData, "type")
|
||||
const parsedType = mediaAssetTypeSchema.safeParse(parseTextField(formData, "type"))
|
||||
const fileEntry = formData.get("file")
|
||||
|
||||
if (!type) {
|
||||
if (!parsedType.success) {
|
||||
return badRequest("Type is required.")
|
||||
}
|
||||
const type = parsedType.data
|
||||
|
||||
if (!(fileEntry instanceof File)) {
|
||||
return badRequest("File is required.")
|
||||
@@ -146,13 +124,17 @@ export async function POST(request: Request): Promise<Response> {
|
||||
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(
|
||||
`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}.`)
|
||||
}
|
||||
|
||||
@@ -178,6 +160,11 @@ export async function POST(request: Request): Promise<Response> {
|
||||
source: parseOptionalField(formData, "source"),
|
||||
copyright: parseOptionalField(formData, "copyright"),
|
||||
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),
|
||||
storageKey: stored.storageKey,
|
||||
mimeType: fileEntry.type || undefined,
|
||||
|
||||
@@ -2,8 +2,11 @@ import {
|
||||
commissionKanbanOrder,
|
||||
createCommission,
|
||||
createCustomer,
|
||||
db,
|
||||
listArtworks,
|
||||
listCommissions,
|
||||
listCustomers,
|
||||
updateCommission,
|
||||
updateCommissionStatus,
|
||||
} from "@cms/db"
|
||||
import { Button } from "@cms/ui/button"
|
||||
@@ -67,6 +70,19 @@ function readNullableDate(formData: FormData, field: string): Date | null {
|
||||
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 }) {
|
||||
const query = new URLSearchParams()
|
||||
|
||||
@@ -124,6 +140,7 @@ async function createCommissionAction(formData: FormData) {
|
||||
status: readInputString(formData, "status"),
|
||||
customerId: readNullableString(formData, "customerId"),
|
||||
assignedUserId: readNullableString(formData, "assignedUserId"),
|
||||
linkedArtworkIds: readUuidList(formData, "linkedArtworkIds"),
|
||||
budgetMin: readNullableNumber(formData, "budgetMin"),
|
||||
budgetMax: readNullableNumber(formData, "budgetMax"),
|
||||
dueAt: readNullableDate(formData, "dueAt"),
|
||||
@@ -136,6 +153,35 @@ async function createCommissionAction(formData: FormData) {
|
||||
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) {
|
||||
"use server"
|
||||
|
||||
@@ -166,6 +212,14 @@ function formatDate(value: Date | null) {
|
||||
return value.toLocaleDateString("en-US")
|
||||
}
|
||||
|
||||
function formatDateInput(value: Date | null) {
|
||||
if (!value) {
|
||||
return ""
|
||||
}
|
||||
|
||||
return value.toISOString().slice(0, 10)
|
||||
}
|
||||
|
||||
export default async function CommissionsManagementPage({
|
||||
searchParams,
|
||||
}: {
|
||||
@@ -177,10 +231,22 @@ export default async function CommissionsManagementPage({
|
||||
scope: "own",
|
||||
})
|
||||
|
||||
const [resolvedSearchParams, customers, commissions] = await Promise.all([
|
||||
const [resolvedSearchParams, customers, commissions, assignees, artworks] = await Promise.all([
|
||||
searchParams,
|
||||
listCustomers(200),
|
||||
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)
|
||||
@@ -309,11 +375,18 @@ export default async function CommissionsManagementPage({
|
||||
</div>
|
||||
<div className="grid gap-3 md:grid-cols-3">
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs text-neutral-600">Assigned user id</span>
|
||||
<input
|
||||
<span className="text-xs text-neutral-600">Assigned user</span>
|
||||
<select
|
||||
name="assignedUserId"
|
||||
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 className="space-y-1">
|
||||
<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"
|
||||
/>
|
||||
</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>
|
||||
</form>
|
||||
</article>
|
||||
@@ -383,6 +464,9 @@ export default async function CommissionsManagementPage({
|
||||
<p className="text-xs text-neutral-600">
|
||||
{commission.customer?.name ?? "No customer"}
|
||||
</p>
|
||||
<p className="text-xs text-neutral-500">
|
||||
Assignee: {commission.assignedUser?.name ?? "none"}
|
||||
</p>
|
||||
<p className="text-xs text-neutral-500">
|
||||
Due: {formatDate(commission.dueAt)}
|
||||
</p>
|
||||
@@ -406,6 +490,99 @@ export default async function CommissionsManagementPage({
|
||||
Move
|
||||
</button>
|
||||
</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>
|
||||
))
|
||||
)}
|
||||
@@ -449,6 +626,24 @@ export default async function CommissionsManagementPage({
|
||||
</table>
|
||||
</div>
|
||||
</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>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -50,6 +50,22 @@ function readNullableInt(formData: FormData, field: string): number | null {
|
||||
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[] {
|
||||
const raw = readInputString(formData, "tags")
|
||||
|
||||
@@ -127,6 +143,11 @@ export default async function MediaAssetEditorPage({ params, searchParams }: Pag
|
||||
source: readNullableString(formData, "source"),
|
||||
copyright: readNullableString(formData, "copyright"),
|
||||
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),
|
||||
mimeType: readNullableString(formData, "mimeType"),
|
||||
width: readNullableInt(formData, "width"),
|
||||
@@ -320,6 +341,56 @@ export default async function MediaAssetEditorPage({ params, searchParams }: Pag
|
||||
</label>
|
||||
</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">
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs text-neutral-600">MIME type</span>
|
||||
|
||||
@@ -2,20 +2,28 @@ import {
|
||||
createNavigationItem,
|
||||
createNavigationMenu,
|
||||
deleteNavigationItem,
|
||||
deleteNavigationMenu,
|
||||
listNavigationMenus,
|
||||
listPages,
|
||||
updateNavigationItem,
|
||||
updateNavigationMenu,
|
||||
upsertNavigationItemTranslation,
|
||||
} from "@cms/db"
|
||||
import { Button } from "@cms/ui/button"
|
||||
import { revalidatePath } from "next/cache"
|
||||
import { redirect } from "next/navigation"
|
||||
|
||||
import { AdminShell } from "@/components/admin-shell"
|
||||
import { CreateMenuForm } from "@/components/navigation/create-menu-form"
|
||||
import { CreateNavigationItemForm } from "@/components/navigation/create-navigation-item-form"
|
||||
import { requirePermissionForRoute } from "@/lib/route-guards"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
type SearchParamsInput = Record<string, string | string[] | undefined>
|
||||
const SUPPORTED_LOCALES = ["de", "en", "es", "fr"] as const
|
||||
|
||||
type SupportedLocale = (typeof SUPPORTED_LOCALES)[number]
|
||||
|
||||
function readFirstValue(value: string | string[] | undefined): string | null {
|
||||
if (Array.isArray(value)) {
|
||||
@@ -51,6 +59,14 @@ function readInt(formData: FormData, field: string, fallback = 0): number {
|
||||
return parsed
|
||||
}
|
||||
|
||||
function normalizeLocale(input: string | null): SupportedLocale {
|
||||
if (input && SUPPORTED_LOCALES.includes(input as SupportedLocale)) {
|
||||
return input as SupportedLocale
|
||||
}
|
||||
|
||||
return "en"
|
||||
}
|
||||
|
||||
function redirectWithState(params: { notice?: string; error?: string }) {
|
||||
const query = new URLSearchParams()
|
||||
|
||||
@@ -117,6 +133,50 @@ async function createItemAction(formData: FormData) {
|
||||
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) {
|
||||
"use server"
|
||||
|
||||
@@ -163,6 +223,31 @@ async function deleteItemAction(formData: FormData) {
|
||||
redirectWithState({ notice: "Navigation item deleted." })
|
||||
}
|
||||
|
||||
async function upsertItemTranslationAction(formData: FormData) {
|
||||
"use server"
|
||||
|
||||
await requirePermissionForRoute({
|
||||
nextPath: "/navigation",
|
||||
permission: "navigation:write",
|
||||
scope: "team",
|
||||
})
|
||||
|
||||
const locale = normalizeLocale(readInputString(formData, "locale"))
|
||||
|
||||
try {
|
||||
await upsertNavigationItemTranslation({
|
||||
navigationItemId: readInputString(formData, "navigationItemId"),
|
||||
locale,
|
||||
label: readInputString(formData, "label"),
|
||||
})
|
||||
} catch {
|
||||
redirectWithState({ error: "Failed to save item translation." })
|
||||
}
|
||||
|
||||
revalidatePath("/navigation")
|
||||
redirectWithState({ notice: "Navigation item translation saved." })
|
||||
}
|
||||
|
||||
export default async function NavigationManagementPage({
|
||||
searchParams,
|
||||
}: {
|
||||
@@ -182,6 +267,7 @@ export default async function NavigationManagementPage({
|
||||
|
||||
const notice = readFirstValue(resolvedSearchParams.notice)
|
||||
const error = readFirstValue(resolvedSearchParams.error)
|
||||
const selectedLocale = normalizeLocale(readFirstValue(resolvedSearchParams.locale))
|
||||
|
||||
return (
|
||||
<AdminShell
|
||||
@@ -206,127 +292,32 @@ export default async function NavigationManagementPage({
|
||||
<section className="grid gap-4 lg:grid-cols-2">
|
||||
<article className="rounded-xl border border-neutral-200 p-6">
|
||||
<h2 className="text-xl font-medium">Create Menu</h2>
|
||||
<form action={createMenuAction} className="mt-4 space-y-3">
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs text-neutral-600">Name</span>
|
||||
<input
|
||||
name="name"
|
||||
required
|
||||
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"
|
||||
required
|
||||
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="primary"
|
||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
/>
|
||||
</label>
|
||||
<label className="inline-flex items-center gap-2 text-sm text-neutral-700">
|
||||
<input
|
||||
name="isVisible"
|
||||
type="checkbox"
|
||||
value="true"
|
||||
defaultChecked
|
||||
className="size-4"
|
||||
/>
|
||||
Visible
|
||||
</label>
|
||||
<Button type="submit">Create menu</Button>
|
||||
</form>
|
||||
<CreateMenuForm action={createMenuAction} />
|
||||
</article>
|
||||
|
||||
<article className="rounded-xl border border-neutral-200 p-6">
|
||||
<h2 className="text-xl font-medium">Create Navigation Item</h2>
|
||||
<form action={createItemAction} className="mt-4 space-y-3">
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs text-neutral-600">Menu</span>
|
||||
<select
|
||||
name="menuId"
|
||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
>
|
||||
{menus.map((menu) => (
|
||||
<option key={menu.id} value={menu.id}>
|
||||
{menu.name} ({menu.location})
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs text-neutral-600">Label</span>
|
||||
<input
|
||||
name="label"
|
||||
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">
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs text-neutral-600">Custom href</span>
|
||||
<input
|
||||
name="href"
|
||||
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">Linked page</span>
|
||||
<select
|
||||
name="pageId"
|
||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
>
|
||||
<option value="">(none)</option>
|
||||
{pages.map((page) => (
|
||||
<option key={page.id} value={page.id}>
|
||||
{page.title} (/{page.slug})
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
<div className="grid gap-3 md:grid-cols-2">
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs text-neutral-600">Parent item id</span>
|
||||
<input
|
||||
name="parentId"
|
||||
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">Sort order</span>
|
||||
<input
|
||||
name="sortOrder"
|
||||
defaultValue="0"
|
||||
type="number"
|
||||
min={0}
|
||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<label className="inline-flex items-center gap-2 text-sm text-neutral-700">
|
||||
<input
|
||||
name="isVisible"
|
||||
type="checkbox"
|
||||
value="true"
|
||||
defaultChecked
|
||||
className="size-4"
|
||||
/>
|
||||
Visible
|
||||
</label>
|
||||
<Button type="submit">Create item</Button>
|
||||
</form>
|
||||
<CreateNavigationItemForm action={createItemAction} menus={menus} pages={pages} />
|
||||
</article>
|
||||
</section>
|
||||
|
||||
<section className="space-y-4">
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{SUPPORTED_LOCALES.map((locale) => (
|
||||
<a
|
||||
key={locale}
|
||||
href={`/navigation?locale=${locale}`}
|
||||
className={`inline-flex rounded border px-3 py-1.5 text-xs ${
|
||||
selectedLocale === locale
|
||||
? "border-neutral-800 bg-neutral-900 text-white"
|
||||
: "border-neutral-300 text-neutral-700"
|
||||
}`}
|
||||
>
|
||||
{locale.toUpperCase()}
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{menus.length === 0 ? (
|
||||
<article className="rounded-xl border border-neutral-200 p-6 text-sm text-neutral-600">
|
||||
No navigation menus yet.
|
||||
@@ -334,107 +325,192 @@ export default async function NavigationManagementPage({
|
||||
) : (
|
||||
menus.map((menu) => (
|
||||
<article key={menu.id} className="rounded-xl border border-neutral-200 p-6">
|
||||
<div className="flex flex-wrap items-center justify-between gap-2">
|
||||
<h3 className="text-lg font-medium">
|
||||
{menu.name} <span className="text-sm text-neutral-500">({menu.location})</span>
|
||||
</h3>
|
||||
<span className="text-xs text-neutral-500">
|
||||
{menu.isVisible ? "visible" : "hidden"}
|
||||
</span>
|
||||
</div>
|
||||
<form action={updateMenuAction} className="rounded border border-neutral-200 p-3">
|
||||
<input type="hidden" name="id" value={menu.id} />
|
||||
<div className="grid gap-3 md:grid-cols-4">
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs text-neutral-600">Menu name</span>
|
||||
<input
|
||||
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 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">
|
||||
{menu.items.length === 0 ? (
|
||||
<p className="text-sm text-neutral-600">No items in this menu.</p>
|
||||
) : (
|
||||
menu.items.map((item) => (
|
||||
<form
|
||||
key={item.id}
|
||||
action={updateItemAction}
|
||||
className="rounded-lg border border-neutral-200 p-3"
|
||||
>
|
||||
<input type="hidden" name="id" value={item.id} />
|
||||
<div className="grid gap-3 md:grid-cols-5">
|
||||
<label className="space-y-1 md:col-span-2">
|
||||
<span className="text-xs text-neutral-600">Label</span>
|
||||
<input
|
||||
name="label"
|
||||
defaultValue={item.label}
|
||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
/>
|
||||
</label>
|
||||
<label className="space-y-1 md:col-span-2">
|
||||
<span className="text-xs text-neutral-600">Href</span>
|
||||
<input
|
||||
name="href"
|
||||
defaultValue={item.href ?? ""}
|
||||
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">Sort</span>
|
||||
<input
|
||||
name="sortOrder"
|
||||
type="number"
|
||||
min={0}
|
||||
defaultValue={item.sortOrder}
|
||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
menu.items.map((item) => {
|
||||
const translation = item.translations.find(
|
||||
(entry) => entry.locale === selectedLocale,
|
||||
)
|
||||
|
||||
<div className="mt-3 grid gap-3 md:grid-cols-2">
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs text-neutral-600">Linked page</span>
|
||||
<select
|
||||
name="pageId"
|
||||
defaultValue={item.pageId ?? ""}
|
||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
>
|
||||
<option value="">(none)</option>
|
||||
{pages.map((page) => (
|
||||
<option key={page.id} value={page.id}>
|
||||
{page.title} (/{page.slug})
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs text-neutral-600">Parent id</span>
|
||||
<input
|
||||
name="parentId"
|
||||
defaultValue={item.parentId ?? ""}
|
||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
return (
|
||||
<div key={item.id} className="rounded-lg border border-neutral-200 p-3">
|
||||
<form action={updateItemAction}>
|
||||
<input type="hidden" name="id" value={item.id} />
|
||||
<div className="grid gap-3 md:grid-cols-5">
|
||||
<label className="space-y-1 md:col-span-2">
|
||||
<span className="text-xs text-neutral-600">Label</span>
|
||||
<input
|
||||
name="label"
|
||||
defaultValue={item.label}
|
||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
/>
|
||||
</label>
|
||||
<label className="space-y-1 md:col-span-2">
|
||||
<span className="text-xs text-neutral-600">Href</span>
|
||||
<input
|
||||
name="href"
|
||||
defaultValue={item.href ?? ""}
|
||||
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">Sort</span>
|
||||
<input
|
||||
name="sortOrder"
|
||||
type="number"
|
||||
min={0}
|
||||
defaultValue={item.sortOrder}
|
||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<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">
|
||||
<input
|
||||
type="checkbox"
|
||||
name="isVisible"
|
||||
value="true"
|
||||
defaultChecked={item.isVisible}
|
||||
className="size-4"
|
||||
/>
|
||||
Visible
|
||||
</label>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button type="submit" size="sm">
|
||||
Save item
|
||||
</Button>
|
||||
<button
|
||||
type="submit"
|
||||
formAction={deleteItemAction}
|
||||
className="rounded-md border border-red-300 px-3 py-2 text-sm text-red-700"
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
</div>
|
||||
<div className="mt-3 grid gap-3 md:grid-cols-2">
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs text-neutral-600">Linked page</span>
|
||||
<select
|
||||
name="pageId"
|
||||
defaultValue={item.pageId ?? ""}
|
||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
>
|
||||
<option value="">(none)</option>
|
||||
{pages.map((page) => (
|
||||
<option key={page.id} value={page.id}>
|
||||
{page.title} (/{page.slug})
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs text-neutral-600">Parent id</span>
|
||||
<select
|
||||
name="parentId"
|
||||
defaultValue={item.parentId ?? ""}
|
||||
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>
|
||||
</div>
|
||||
|
||||
<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">
|
||||
<input
|
||||
type="checkbox"
|
||||
name="isVisible"
|
||||
value="true"
|
||||
defaultChecked={item.isVisible}
|
||||
className="size-4"
|
||||
/>
|
||||
Visible
|
||||
</label>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button type="submit" size="sm">
|
||||
Save item
|
||||
</Button>
|
||||
<button
|
||||
type="submit"
|
||||
formAction={deleteItemAction}
|
||||
className="rounded-md border border-red-300 px-3 py-2 text-sm text-red-700"
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<form
|
||||
action={upsertItemTranslationAction}
|
||||
className="mt-3 rounded border border-neutral-200 p-3"
|
||||
>
|
||||
<input type="hidden" name="navigationItemId" value={item.id} />
|
||||
<input type="hidden" name="locale" value={selectedLocale} />
|
||||
|
||||
<p className="text-xs text-neutral-600">
|
||||
Translation ({selectedLocale.toUpperCase()}) - saved locales:{" "}
|
||||
{item.translations.length > 0
|
||||
? item.translations
|
||||
.map((entry) => entry.locale.toUpperCase())
|
||||
.join(", ")
|
||||
: "none"}
|
||||
</p>
|
||||
|
||||
<div className="mt-2 flex gap-2">
|
||||
<input
|
||||
name="label"
|
||||
defaultValue={translation?.label ?? item.label}
|
||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
/>
|
||||
<Button type="submit" size="sm" variant="secondary">
|
||||
Save translation
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</form>
|
||||
))
|
||||
)
|
||||
})
|
||||
)}
|
||||
</div>
|
||||
</article>
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
import { createPost, deletePost, listPosts, updatePost } from "@cms/db"
|
||||
import {
|
||||
createPost,
|
||||
deletePost,
|
||||
listPostsWithTranslations,
|
||||
updatePost,
|
||||
upsertPostTranslation,
|
||||
} from "@cms/db"
|
||||
import { Button } from "@cms/ui/button"
|
||||
import { revalidatePath } from "next/cache"
|
||||
import { redirect } from "next/navigation"
|
||||
@@ -9,6 +15,9 @@ import { requirePermissionForRoute } from "@/lib/route-guards"
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
type SearchParamsInput = Record<string, string | string[] | undefined>
|
||||
const SUPPORTED_LOCALES = ["de", "en", "es", "fr"] as const
|
||||
|
||||
type SupportedLocale = (typeof SUPPORTED_LOCALES)[number]
|
||||
|
||||
function readFirstValue(value: string | string[] | undefined): string | null {
|
||||
if (Array.isArray(value)) {
|
||||
@@ -28,6 +37,14 @@ function readNullableString(formData: FormData, field: string): string | undefin
|
||||
return value.length > 0 ? value : undefined
|
||||
}
|
||||
|
||||
function normalizeLocale(input: string | null): SupportedLocale {
|
||||
if (input && SUPPORTED_LOCALES.includes(input as SupportedLocale)) {
|
||||
return input as SupportedLocale
|
||||
}
|
||||
|
||||
return "en"
|
||||
}
|
||||
|
||||
function redirectWithState(params: { notice?: string; error?: string }) {
|
||||
const query = new URLSearchParams()
|
||||
|
||||
@@ -115,6 +132,34 @@ async function deleteNewsAction(formData: FormData) {
|
||||
redirectWithState({ notice: "Post deleted." })
|
||||
}
|
||||
|
||||
async function upsertNewsTranslationAction(formData: FormData) {
|
||||
"use server"
|
||||
|
||||
await requirePermissionForRoute({
|
||||
nextPath: "/news",
|
||||
permission: "news:write",
|
||||
scope: "team",
|
||||
})
|
||||
|
||||
const locale = normalizeLocale(readInputString(formData, "locale"))
|
||||
|
||||
try {
|
||||
await upsertPostTranslation({
|
||||
postId: readInputString(formData, "postId"),
|
||||
locale,
|
||||
title: readInputString(formData, "title"),
|
||||
excerpt: readNullableString(formData, "excerpt") ?? null,
|
||||
body: readInputString(formData, "body"),
|
||||
})
|
||||
} catch {
|
||||
redirectWithState({ error: "Failed to save translation." })
|
||||
}
|
||||
|
||||
revalidatePath("/news")
|
||||
revalidatePath("/")
|
||||
redirectWithState({ notice: "Post translation saved." })
|
||||
}
|
||||
|
||||
export default async function NewsManagementPage({
|
||||
searchParams,
|
||||
}: {
|
||||
@@ -126,10 +171,14 @@ export default async function NewsManagementPage({
|
||||
scope: "team",
|
||||
})
|
||||
|
||||
const [resolvedSearchParams, posts] = await Promise.all([searchParams, listPosts()])
|
||||
const [resolvedSearchParams, posts] = await Promise.all([
|
||||
searchParams,
|
||||
listPostsWithTranslations(),
|
||||
])
|
||||
|
||||
const notice = readFirstValue(resolvedSearchParams.notice)
|
||||
const error = readFirstValue(resolvedSearchParams.error)
|
||||
const selectedLocale = normalizeLocale(readFirstValue(resolvedSearchParams.locale))
|
||||
|
||||
return (
|
||||
<AdminShell
|
||||
@@ -204,72 +253,146 @@ export default async function NewsManagementPage({
|
||||
</section>
|
||||
|
||||
<section className="space-y-3">
|
||||
{posts.map((post) => (
|
||||
<form
|
||||
key={post.id}
|
||||
action={updateNewsAction}
|
||||
className="rounded-xl border border-neutral-200 p-6"
|
||||
>
|
||||
<input type="hidden" name="id" value={post.id} />
|
||||
<div className="grid gap-3 md:grid-cols-2">
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs text-neutral-600">Title</span>
|
||||
<input
|
||||
name="title"
|
||||
defaultValue={post.title}
|
||||
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={post.slug}
|
||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<label className="mt-3 block space-y-1">
|
||||
<span className="text-xs text-neutral-600">Excerpt</span>
|
||||
<input
|
||||
name="excerpt"
|
||||
defaultValue={post.excerpt ?? ""}
|
||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
/>
|
||||
</label>
|
||||
<label className="mt-3 block space-y-1">
|
||||
<span className="text-xs text-neutral-600">Body</span>
|
||||
<textarea
|
||||
name="body"
|
||||
rows={4}
|
||||
defaultValue={post.body}
|
||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
/>
|
||||
</label>
|
||||
<div className="mt-3 flex flex-wrap items-center justify-between gap-3">
|
||||
<select
|
||||
name="status"
|
||||
defaultValue={post.status}
|
||||
className="rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{SUPPORTED_LOCALES.map((locale) => (
|
||||
<a
|
||||
key={locale}
|
||||
href={`/news?locale=${locale}`}
|
||||
className={`inline-flex rounded border px-3 py-1.5 text-xs ${
|
||||
selectedLocale === locale
|
||||
? "border-neutral-800 bg-neutral-900 text-white"
|
||||
: "border-neutral-300 text-neutral-700"
|
||||
}`}
|
||||
>
|
||||
{locale.toUpperCase()}
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{posts.map((post) => {
|
||||
const translation = post.translations.find((entry) => entry.locale === selectedLocale)
|
||||
|
||||
return (
|
||||
<div key={post.id} className="rounded-xl border border-neutral-200 p-6">
|
||||
<form action={updateNewsAction}>
|
||||
<input type="hidden" name="id" value={post.id} />
|
||||
<div className="grid gap-3 md:grid-cols-2">
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs text-neutral-600">Title</span>
|
||||
<input
|
||||
name="title"
|
||||
defaultValue={post.title}
|
||||
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={post.slug}
|
||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<label className="mt-3 block space-y-1">
|
||||
<span className="text-xs text-neutral-600">Excerpt</span>
|
||||
<input
|
||||
name="excerpt"
|
||||
defaultValue={post.excerpt ?? ""}
|
||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
/>
|
||||
</label>
|
||||
<label className="mt-3 block space-y-1">
|
||||
<span className="text-xs text-neutral-600">Body</span>
|
||||
<textarea
|
||||
name="body"
|
||||
rows={4}
|
||||
defaultValue={post.body}
|
||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
/>
|
||||
</label>
|
||||
<div className="mt-3 flex flex-wrap items-center justify-between gap-3">
|
||||
<select
|
||||
name="status"
|
||||
defaultValue={post.status}
|
||||
className="rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
>
|
||||
<option value="draft">draft</option>
|
||||
<option value="published">published</option>
|
||||
</select>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button type="submit" size="sm">
|
||||
Save
|
||||
</Button>
|
||||
<button
|
||||
type="submit"
|
||||
formAction={deleteNewsAction}
|
||||
className="rounded-md border border-red-300 px-3 py-2 text-sm text-red-700"
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<form
|
||||
action={upsertNewsTranslationAction}
|
||||
className="mt-4 rounded-lg border border-neutral-200 p-4"
|
||||
>
|
||||
<option value="draft">draft</option>
|
||||
<option value="published">published</option>
|
||||
</select>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button type="submit" size="sm">
|
||||
Save
|
||||
</Button>
|
||||
<button
|
||||
type="submit"
|
||||
formAction={deleteNewsAction}
|
||||
className="rounded-md border border-red-300 px-3 py-2 text-sm text-red-700"
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
</div>
|
||||
<input type="hidden" name="postId" value={post.id} />
|
||||
<input type="hidden" name="locale" value={selectedLocale} />
|
||||
|
||||
<h3 className="text-sm font-medium">
|
||||
Translation ({selectedLocale.toUpperCase()})
|
||||
</h3>
|
||||
<p className="mt-1 text-xs text-neutral-600">
|
||||
Missing fields fall back to base post content on public pages.
|
||||
</p>
|
||||
{post.translations.length > 0 ? (
|
||||
<p className="mt-2 text-xs text-neutral-600">
|
||||
Saved locales:{" "}
|
||||
{post.translations.map((entry) => entry.locale.toUpperCase()).join(", ")}
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
<div className="mt-3 grid gap-3 md:grid-cols-2">
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs text-neutral-600">Title</span>
|
||||
<input
|
||||
name="title"
|
||||
defaultValue={translation?.title ?? post.title}
|
||||
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">Excerpt</span>
|
||||
<input
|
||||
name="excerpt"
|
||||
defaultValue={translation?.excerpt ?? post.excerpt ?? ""}
|
||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<label className="mt-3 block space-y-1">
|
||||
<span className="text-xs text-neutral-600">Body</span>
|
||||
<textarea
|
||||
name="body"
|
||||
rows={4}
|
||||
defaultValue={translation?.body ?? post.body}
|
||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
/>
|
||||
</label>
|
||||
|
||||
<div className="mt-3">
|
||||
<Button type="submit" size="sm">
|
||||
Save translation
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</form>
|
||||
))}
|
||||
)
|
||||
})}
|
||||
</section>
|
||||
</AdminShell>
|
||||
)
|
||||
|
||||
@@ -1,14 +1,23 @@
|
||||
import { deletePage, getPageById, updatePage } from "@cms/db"
|
||||
import {
|
||||
deletePage,
|
||||
getPageById,
|
||||
listPageTranslations,
|
||||
updatePage,
|
||||
upsertPageTranslation,
|
||||
} from "@cms/db"
|
||||
import { Button } from "@cms/ui/button"
|
||||
import Link from "next/link"
|
||||
import { redirect } from "next/navigation"
|
||||
|
||||
import { AdminShell } from "@/components/admin-shell"
|
||||
import { PageBlockEditor } from "@/components/pages/page-block-editor"
|
||||
import { requirePermissionForRoute } from "@/lib/route-guards"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
type SearchParamsInput = Record<string, string | string[] | undefined>
|
||||
const SUPPORTED_LOCALES = ["de", "en", "es", "fr"] as const
|
||||
type SupportedLocale = (typeof SUPPORTED_LOCALES)[number]
|
||||
|
||||
type PageProps = {
|
||||
params: Promise<{ id: string }>
|
||||
@@ -48,6 +57,14 @@ function redirectWithState(pageId: string, params: { notice?: string; error?: st
|
||||
redirect(value ? `/pages/${pageId}?${value}` : `/pages/${pageId}`)
|
||||
}
|
||||
|
||||
function normalizeLocale(input: string | null): SupportedLocale {
|
||||
if (input && SUPPORTED_LOCALES.includes(input as SupportedLocale)) {
|
||||
return input as SupportedLocale
|
||||
}
|
||||
|
||||
return "en"
|
||||
}
|
||||
|
||||
export default async function PageEditorPage({ params, searchParams }: PageProps) {
|
||||
const role = await requirePermissionForRoute({
|
||||
nextPath: "/pages",
|
||||
@@ -57,7 +74,11 @@ export default async function PageEditorPage({ params, searchParams }: PageProps
|
||||
const resolvedParams = await params
|
||||
const pageId = resolvedParams.id
|
||||
|
||||
const [resolvedSearchParams, pageRecord] = await Promise.all([searchParams, getPageById(pageId)])
|
||||
const [resolvedSearchParams, pageRecord, translations] = await Promise.all([
|
||||
searchParams,
|
||||
getPageById(pageId),
|
||||
listPageTranslations(pageId),
|
||||
])
|
||||
|
||||
if (!pageRecord) {
|
||||
redirect("/pages?error=Page+not+found")
|
||||
@@ -66,6 +87,8 @@ export default async function PageEditorPage({ params, searchParams }: PageProps
|
||||
const page = pageRecord
|
||||
const notice = readFirstValue(resolvedSearchParams.notice)
|
||||
const error = readFirstValue(resolvedSearchParams.error)
|
||||
const selectedLocale = normalizeLocale(readFirstValue(resolvedSearchParams.locale))
|
||||
const selectedTranslation = translations.find((entry) => entry.locale === selectedLocale)
|
||||
|
||||
async function updatePageAction(formData: FormData) {
|
||||
"use server"
|
||||
@@ -118,6 +141,34 @@ export default async function PageEditorPage({ params, searchParams }: PageProps
|
||||
redirect("/pages?notice=Page+deleted")
|
||||
}
|
||||
|
||||
async function upsertPageTranslationAction(formData: FormData) {
|
||||
"use server"
|
||||
|
||||
await requirePermissionForRoute({
|
||||
nextPath: "/pages",
|
||||
permission: "pages:write",
|
||||
scope: "team",
|
||||
})
|
||||
|
||||
const locale = normalizeLocale(readInputString(formData, "locale"))
|
||||
|
||||
try {
|
||||
await upsertPageTranslation({
|
||||
pageId,
|
||||
locale,
|
||||
title: readInputString(formData, "title"),
|
||||
summary: readNullableString(formData, "summary"),
|
||||
content: readInputString(formData, "content"),
|
||||
seoTitle: readNullableString(formData, "seoTitle"),
|
||||
seoDescription: readNullableString(formData, "seoDescription"),
|
||||
})
|
||||
} catch {
|
||||
redirect(`/pages/${pageId}?error=Failed+to+save+translation.&locale=${locale}`)
|
||||
}
|
||||
|
||||
redirect(`/pages/${pageId}?notice=Translation+saved.&locale=${locale}`)
|
||||
}
|
||||
|
||||
return (
|
||||
<AdminShell
|
||||
role={role}
|
||||
@@ -192,16 +243,7 @@ export default async function PageEditorPage({ params, searchParams }: PageProps
|
||||
/>
|
||||
</label>
|
||||
|
||||
<label className="space-y-1">
|
||||
<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>
|
||||
<PageBlockEditor name="content" initialContent={page.content} />
|
||||
|
||||
<div className="grid gap-3 md:grid-cols-2">
|
||||
<label className="space-y-1">
|
||||
@@ -226,6 +268,127 @@ export default async function PageEditorPage({ params, searchParams }: PageProps
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section className="rounded-xl border border-neutral-200 p-6">
|
||||
<div className="space-y-1">
|
||||
<h3 className="text-xl font-medium">Translations</h3>
|
||||
<p className="text-sm text-neutral-600">
|
||||
Add locale-specific page content. Missing locales fall back to base page fields.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="mt-4 flex flex-wrap gap-2">
|
||||
{SUPPORTED_LOCALES.map((locale) => {
|
||||
const isActive = locale === selectedLocale
|
||||
const hasTranslation = translations.some((entry) => entry.locale === locale)
|
||||
|
||||
return (
|
||||
<Link
|
||||
key={locale}
|
||||
href={`/pages/${pageId}?locale=${locale}`}
|
||||
className={`inline-flex items-center gap-2 rounded border px-3 py-1.5 text-xs ${
|
||||
isActive
|
||||
? "border-neutral-800 bg-neutral-900 text-white"
|
||||
: "border-neutral-300 text-neutral-700"
|
||||
}`}
|
||||
>
|
||||
<span>{locale.toUpperCase()}</span>
|
||||
<span className={isActive ? "text-neutral-200" : "text-neutral-500"}>
|
||||
{hasTranslation ? "saved" : "missing"}
|
||||
</span>
|
||||
</Link>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
|
||||
{translations.length > 0 ? (
|
||||
<div className="mt-4 rounded border border-neutral-200">
|
||||
<table className="min-w-full text-left text-sm">
|
||||
<thead className="text-xs uppercase tracking-wide text-neutral-500">
|
||||
<tr>
|
||||
<th className="px-3 py-2">Locale</th>
|
||||
<th className="px-3 py-2">Title</th>
|
||||
<th className="px-3 py-2">Updated</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{translations.map((translation) => (
|
||||
<tr key={translation.id} className="border-t border-neutral-200">
|
||||
<td className="px-3 py-2">{translation.locale.toUpperCase()}</td>
|
||||
<td className="px-3 py-2">{translation.title}</td>
|
||||
<td className="px-3 py-2 text-neutral-600">
|
||||
{translation.updatedAt.toLocaleDateString("en-US")}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<form action={upsertPageTranslationAction} className="mt-6 space-y-3">
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs text-neutral-600">Locale</span>
|
||||
<select
|
||||
name="locale"
|
||||
defaultValue={selectedLocale}
|
||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
>
|
||||
{SUPPORTED_LOCALES.map((locale) => (
|
||||
<option key={locale} value={locale}>
|
||||
{locale.toUpperCase()}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs text-neutral-600">Title</span>
|
||||
<input
|
||||
name="title"
|
||||
defaultValue={selectedTranslation?.title ?? page.title}
|
||||
required
|
||||
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">Summary</span>
|
||||
<input
|
||||
name="summary"
|
||||
defaultValue={selectedTranslation?.summary ?? page.summary ?? ""}
|
||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
/>
|
||||
</label>
|
||||
|
||||
<PageBlockEditor
|
||||
name="content"
|
||||
initialContent={selectedTranslation?.content ?? page.content}
|
||||
label="Translation Blocks"
|
||||
/>
|
||||
|
||||
<div className="grid gap-3 md:grid-cols-2">
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs text-neutral-600">SEO title</span>
|
||||
<input
|
||||
name="seoTitle"
|
||||
defaultValue={selectedTranslation?.seoTitle ?? page.seoTitle ?? ""}
|
||||
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">SEO description</span>
|
||||
<input
|
||||
name="seoDescription"
|
||||
defaultValue={selectedTranslation?.seoDescription ?? page.seoDescription ?? ""}
|
||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<Button type="submit">Save translation</Button>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section className="rounded-xl border border-red-300 bg-red-50 p-6">
|
||||
<h3 className="text-lg font-medium text-red-800">Danger Zone</h3>
|
||||
<p className="mt-1 text-sm text-red-700">
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { createPage, listPages } from "@cms/db"
|
||||
import { Button } from "@cms/ui/button"
|
||||
import { revalidatePath } from "next/cache"
|
||||
import Link from "next/link"
|
||||
import { redirect } from "next/navigation"
|
||||
|
||||
import { AdminShell } from "@/components/admin-shell"
|
||||
import { CreatePageForm } from "@/components/pages/create-page-form"
|
||||
import { requirePermissionForRoute } from "@/lib/route-guards"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
@@ -110,75 +110,7 @@ export default async function PagesManagementPage({
|
||||
|
||||
<section className="rounded-xl border border-neutral-200 p-6">
|
||||
<h2 className="text-xl font-medium">Create Page</h2>
|
||||
<form action={createPageAction} className="mt-4 space-y-3">
|
||||
<div className="grid gap-3 md:grid-cols-3">
|
||||
<label className="space-y-1 md:col-span-2">
|
||||
<span className="text-xs text-neutral-600">Title</span>
|
||||
<input
|
||||
name="title"
|
||||
required
|
||||
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">Status</span>
|
||||
<select
|
||||
name="status"
|
||||
defaultValue="draft"
|
||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
>
|
||||
<option value="draft">draft</option>
|
||||
<option value="published">published</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs text-neutral-600">Slug</span>
|
||||
<input
|
||||
name="slug"
|
||||
required
|
||||
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">Summary</span>
|
||||
<input
|
||||
name="summary"
|
||||
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">Content</span>
|
||||
<textarea
|
||||
name="content"
|
||||
rows={6}
|
||||
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">
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs text-neutral-600">SEO title</span>
|
||||
<input
|
||||
name="seoTitle"
|
||||
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">SEO description</span>
|
||||
<input
|
||||
name="seoDescription"
|
||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<Button type="submit">Create page</Button>
|
||||
</form>
|
||||
<CreatePageForm action={createPageAction} />
|
||||
</section>
|
||||
|
||||
<section className="rounded-xl border border-neutral-200 p-6">
|
||||
|
||||
@@ -5,10 +5,14 @@ import {
|
||||
createCategory,
|
||||
createGallery,
|
||||
createTag,
|
||||
deleteArtworkRendition,
|
||||
deleteGrouping,
|
||||
linkArtworkToGrouping,
|
||||
listArtworks,
|
||||
listMediaAssets,
|
||||
listMediaFoundationGroups,
|
||||
updateArtwork,
|
||||
updateGrouping,
|
||||
} from "@cms/db"
|
||||
import { Button } from "@cms/ui/button"
|
||||
import { revalidatePath } from "next/cache"
|
||||
@@ -32,6 +36,30 @@ function readOptionalField(formData: FormData, key: string): string | 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 {
|
||||
if (Array.isArray(value)) {
|
||||
return value[0] ?? null
|
||||
@@ -89,6 +117,15 @@ async function createArtworkAction(formData: FormData) {
|
||||
dimensions: readOptionalField(formData, "dimensions"),
|
||||
framing: readOptionalField(formData, "framing"),
|
||||
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: (() => {
|
||||
const raw = readField(formData, "year")
|
||||
return raw ? Number(raw) : undefined
|
||||
@@ -102,6 +139,41 @@ async function createArtworkAction(formData: FormData) {
|
||||
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) {
|
||||
"use server"
|
||||
|
||||
@@ -117,23 +189,32 @@ async function createGroupAction(formData: FormData) {
|
||||
name,
|
||||
slug,
|
||||
description: readOptionalField(formData, "description"),
|
||||
sortOrder: readNonNegativeInt(formData, "sortOrder"),
|
||||
isVisible: readBooleanField(formData, "isVisible"),
|
||||
})
|
||||
} else if (type === "album") {
|
||||
await createAlbum({
|
||||
name,
|
||||
slug,
|
||||
description: readOptionalField(formData, "description"),
|
||||
sortOrder: readNonNegativeInt(formData, "sortOrder"),
|
||||
isVisible: readBooleanField(formData, "isVisible"),
|
||||
})
|
||||
} else if (type === "category") {
|
||||
await createCategory({
|
||||
name,
|
||||
slug,
|
||||
description: readOptionalField(formData, "description"),
|
||||
sortOrder: readNonNegativeInt(formData, "sortOrder"),
|
||||
isVisible: readBooleanField(formData, "isVisible"),
|
||||
})
|
||||
} else {
|
||||
await createTag({
|
||||
name,
|
||||
slug,
|
||||
description: readOptionalField(formData, "description"),
|
||||
sortOrder: readNonNegativeInt(formData, "sortOrder"),
|
||||
isVisible: readBooleanField(formData, "isVisible"),
|
||||
})
|
||||
}
|
||||
} catch {
|
||||
@@ -144,6 +225,47 @@ async function createGroupAction(formData: FormData) {
|
||||
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) {
|
||||
"use server"
|
||||
|
||||
@@ -195,6 +317,21 @@ async function attachRenditionAction(formData: FormData) {
|
||||
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({
|
||||
searchParams,
|
||||
}: {
|
||||
@@ -290,6 +427,26 @@ export default async function PortfolioPage({
|
||||
placeholder="Availability"
|
||||
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>
|
||||
</form>
|
||||
</section>
|
||||
@@ -297,7 +454,7 @@ export default async function PortfolioPage({
|
||||
<section className="rounded-xl border border-neutral-200 p-6">
|
||||
<h2 className="text-xl font-medium">Create Group Entity</h2>
|
||||
<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
|
||||
name="groupType"
|
||||
defaultValue="gallery"
|
||||
@@ -319,6 +476,18 @@ export default async function PortfolioPage({
|
||||
placeholder="Slug (optional)"
|
||||
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>
|
||||
<textarea
|
||||
name="description"
|
||||
@@ -330,6 +499,89 @@ export default async function PortfolioPage({
|
||||
</form>
|
||||
</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">
|
||||
<h2 className="text-xl font-medium">Link Artwork To Group</h2>
|
||||
<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="card">card</option>
|
||||
<option value="full">full</option>
|
||||
<option value="retina">retina</option>
|
||||
<option value="custom">custom</option>
|
||||
</select>
|
||||
<input
|
||||
@@ -447,14 +700,16 @@ export default async function PortfolioPage({
|
||||
<th className="py-2 pr-4">Title</th>
|
||||
<th className="py-2 pr-4">Slug</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">Groups</th>
|
||||
<th className="py-2 pr-4">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{artworks.length === 0 ? (
|
||||
<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.
|
||||
</td>
|
||||
</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 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.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">
|
||||
g:{artwork.galleryLinks.length} a:{artwork.albumLinks.length} c:
|
||||
{artwork.categoryLinks.length} t:{artwork.tagLinks.length}
|
||||
</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>
|
||||
))
|
||||
)}
|
||||
|
||||
@@ -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 {
|
||||
auth,
|
||||
canDeleteUserAccount,
|
||||
createManagedUserAccount,
|
||||
enforceOwnerInvariant,
|
||||
} from "@/lib/auth/server"
|
||||
import { requirePermissionForRoute } from "@/lib/route-guards"
|
||||
|
||||
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({
|
||||
nextPath: "/users",
|
||||
permission: "users:read",
|
||||
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 (
|
||||
<AdminShell
|
||||
role={role}
|
||||
activePath="/users"
|
||||
badge="Admin App"
|
||||
title="Users"
|
||||
description="Prepare user lifecycle and role management operations."
|
||||
description="Manage internal users, roles, and account status."
|
||||
>
|
||||
<AdminSectionPlaceholder
|
||||
feature="Users Management"
|
||||
summary="This route sets the guardrail and UX entrypoint for role assignment, status, and invitation flows."
|
||||
requiredPermission="users:read (own)"
|
||||
nextSteps={[
|
||||
"Add user list, filter, and detail views.",
|
||||
"Add role and permission editing actions with owner/support safety rules.",
|
||||
"Add disable/ban and invite workflows.",
|
||||
]}
|
||||
/>
|
||||
{notice ? (
|
||||
<section className="rounded-xl border border-emerald-300 bg-emerald-50 px-4 py-3 text-sm text-emerald-800">
|
||||
{notice}
|
||||
</section>
|
||||
) : null}
|
||||
{error ? (
|
||||
<section className="rounded-xl border border-red-300 bg-red-50 px-4 py-3 text-sm text-red-800">
|
||||
{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>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -149,6 +149,52 @@ export function MediaUploadForm() {
|
||||
</label>
|
||||
</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">
|
||||
<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" />
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
/* @vitest-environment jsdom */
|
||||
|
||||
import { render, screen } from "@testing-library/react"
|
||||
import { describe, expect, it, vi } from "vitest"
|
||||
|
||||
import { CreateMenuForm } from "./create-menu-form"
|
||||
|
||||
describe("CreateMenuForm", () => {
|
||||
it("renders defaults for location and visibility", () => {
|
||||
render(<CreateMenuForm action={vi.fn()} />)
|
||||
|
||||
const location = screen.getByLabelText("Location") as HTMLInputElement
|
||||
expect(location.value).toBe("primary")
|
||||
|
||||
const visible = screen.getByLabelText("Visible") as HTMLInputElement
|
||||
expect(visible.checked).toBe(true)
|
||||
|
||||
expect(screen.getByRole("button", { name: "Create menu" })).not.toBeNull()
|
||||
})
|
||||
})
|
||||
41
apps/admin/src/components/navigation/create-menu-form.tsx
Normal file
41
apps/admin/src/components/navigation/create-menu-form.tsx
Normal file
@@ -0,0 +1,41 @@
|
||||
import { Button } from "@cms/ui/button"
|
||||
|
||||
type CreateMenuFormProps = {
|
||||
action: (formData: FormData) => void | Promise<void>
|
||||
}
|
||||
|
||||
export function CreateMenuForm({ action }: CreateMenuFormProps) {
|
||||
return (
|
||||
<form action={action} className="mt-4 space-y-3">
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs text-neutral-600">Name</span>
|
||||
<input
|
||||
name="name"
|
||||
required
|
||||
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"
|
||||
required
|
||||
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="primary"
|
||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
/>
|
||||
</label>
|
||||
<label className="inline-flex items-center gap-2 text-sm text-neutral-700">
|
||||
<input name="isVisible" type="checkbox" value="true" defaultChecked className="size-4" />
|
||||
Visible
|
||||
</label>
|
||||
<Button type="submit">Create menu</Button>
|
||||
</form>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/* @vitest-environment jsdom */
|
||||
|
||||
import { render, screen } from "@testing-library/react"
|
||||
import { describe, expect, it, vi } from "vitest"
|
||||
|
||||
import { CreateNavigationItemForm } from "./create-navigation-item-form"
|
||||
|
||||
describe("CreateNavigationItemForm", () => {
|
||||
it("renders menu/page options and defaults", () => {
|
||||
render(
|
||||
<CreateNavigationItemForm
|
||||
action={vi.fn()}
|
||||
menus={[{ id: "menu-1", name: "Primary", location: "header" }]}
|
||||
pages={[{ id: "page-1", title: "Home", slug: "home" }]}
|
||||
/>,
|
||||
)
|
||||
|
||||
const menu = screen.getByLabelText("Menu") as HTMLSelectElement
|
||||
expect(menu.options.length).toBe(1)
|
||||
expect(menu.value).toBe("menu-1")
|
||||
|
||||
const page = screen.getByLabelText("Linked page") as HTMLSelectElement
|
||||
expect(page.options.length).toBe(2)
|
||||
expect(page.options[0]?.value).toBe("")
|
||||
|
||||
const sortOrder = screen.getByLabelText("Sort order") as HTMLInputElement
|
||||
expect(sortOrder.value).toBe("0")
|
||||
|
||||
const visible = screen.getByLabelText("Visible") as HTMLInputElement
|
||||
expect(visible.checked).toBe(true)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,94 @@
|
||||
import { Button } from "@cms/ui/button"
|
||||
|
||||
type MenuOption = {
|
||||
id: string
|
||||
name: string
|
||||
location: string
|
||||
}
|
||||
|
||||
type PageOption = {
|
||||
id: string
|
||||
title: string
|
||||
slug: string
|
||||
}
|
||||
|
||||
type CreateNavigationItemFormProps = {
|
||||
action: (formData: FormData) => void | Promise<void>
|
||||
menus: MenuOption[]
|
||||
pages: PageOption[]
|
||||
}
|
||||
|
||||
export function CreateNavigationItemForm({ action, menus, pages }: CreateNavigationItemFormProps) {
|
||||
return (
|
||||
<form action={action} className="mt-4 space-y-3">
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs text-neutral-600">Menu</span>
|
||||
<select
|
||||
name="menuId"
|
||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
>
|
||||
{menus.map((menu) => (
|
||||
<option key={menu.id} value={menu.id}>
|
||||
{menu.name} ({menu.location})
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs text-neutral-600">Label</span>
|
||||
<input
|
||||
name="label"
|
||||
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">
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs text-neutral-600">Custom href</span>
|
||||
<input
|
||||
name="href"
|
||||
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">Linked page</span>
|
||||
<select
|
||||
name="pageId"
|
||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
>
|
||||
<option value="">(none)</option>
|
||||
{pages.map((page) => (
|
||||
<option key={page.id} value={page.id}>
|
||||
{page.title} (/{page.slug})
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
<div className="grid gap-3 md:grid-cols-2">
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs text-neutral-600">Parent item id</span>
|
||||
<input
|
||||
name="parentId"
|
||||
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">Sort order</span>
|
||||
<input
|
||||
name="sortOrder"
|
||||
defaultValue="0"
|
||||
type="number"
|
||||
min={0}
|
||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<label className="inline-flex items-center gap-2 text-sm text-neutral-700">
|
||||
<input name="isVisible" type="checkbox" value="true" defaultChecked className="size-4" />
|
||||
Visible
|
||||
</label>
|
||||
<Button type="submit">Create item</Button>
|
||||
</form>
|
||||
)
|
||||
}
|
||||
23
apps/admin/src/components/pages/create-page-form.test.tsx
Normal file
23
apps/admin/src/components/pages/create-page-form.test.tsx
Normal file
@@ -0,0 +1,23 @@
|
||||
/* @vitest-environment jsdom */
|
||||
|
||||
import { render, screen } from "@testing-library/react"
|
||||
import { describe, expect, it, vi } from "vitest"
|
||||
|
||||
import { CreatePageForm } from "./create-page-form"
|
||||
|
||||
describe("CreatePageForm", () => {
|
||||
it("renders required fields and draft default status", () => {
|
||||
render(<CreatePageForm action={vi.fn()} />)
|
||||
|
||||
expect((screen.getByLabelText("Title") as HTMLInputElement).name).toBe("title")
|
||||
expect((screen.getByLabelText("Slug") as HTMLInputElement).name).toBe("slug")
|
||||
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
|
||||
expect(status.value).toBe("draft")
|
||||
|
||||
expect(screen.getByRole("button", { name: "Create page" })).not.toBeNull()
|
||||
})
|
||||
})
|
||||
83
apps/admin/src/components/pages/create-page-form.tsx
Normal file
83
apps/admin/src/components/pages/create-page-form.tsx
Normal file
@@ -0,0 +1,83 @@
|
||||
import { serializePageBlocks } from "@cms/content"
|
||||
import { Button } from "@cms/ui/button"
|
||||
|
||||
import { PageBlockEditor } from "./page-block-editor"
|
||||
|
||||
type CreatePageFormProps = {
|
||||
action: (formData: FormData) => void | Promise<void>
|
||||
}
|
||||
|
||||
export function CreatePageForm({ action }: CreatePageFormProps) {
|
||||
return (
|
||||
<form action={action} className="mt-4 space-y-3">
|
||||
<div className="grid gap-3 md:grid-cols-3">
|
||||
<label className="space-y-1 md:col-span-2">
|
||||
<span className="text-xs text-neutral-600">Title</span>
|
||||
<input
|
||||
name="title"
|
||||
required
|
||||
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">Status</span>
|
||||
<select
|
||||
name="status"
|
||||
defaultValue="draft"
|
||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
>
|
||||
<option value="draft">draft</option>
|
||||
<option value="published">published</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs text-neutral-600">Slug</span>
|
||||
<input
|
||||
name="slug"
|
||||
required
|
||||
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">Summary</span>
|
||||
<input
|
||||
name="summary"
|
||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
/>
|
||||
</label>
|
||||
|
||||
<PageBlockEditor
|
||||
name="content"
|
||||
initialContent={serializePageBlocks([
|
||||
{
|
||||
id: "initial-rich-text",
|
||||
type: "rich_text",
|
||||
body: "",
|
||||
},
|
||||
])}
|
||||
/>
|
||||
|
||||
<div className="grid gap-3 md:grid-cols-2">
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs text-neutral-600">SEO title</span>
|
||||
<input
|
||||
name="seoTitle"
|
||||
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">SEO description</span>
|
||||
<input
|
||||
name="seoDescription"
|
||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<Button type="submit">Create page</Button>
|
||||
</form>
|
||||
)
|
||||
}
|
||||
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>
|
||||
)
|
||||
}
|
||||
@@ -266,11 +266,15 @@ type BootstrapUserConfig = {
|
||||
password: string
|
||||
role: Role
|
||||
isHidden: boolean
|
||||
isSystem?: boolean
|
||||
isProtected?: boolean
|
||||
}
|
||||
|
||||
async function ensureCredentialUser(config: BootstrapUserConfig): Promise<void> {
|
||||
const ctx = await auth.$context
|
||||
const normalizedEmail = config.email.toLowerCase()
|
||||
const isSystem = config.isSystem ?? true
|
||||
const isProtected = config.isProtected ?? true
|
||||
const existing = await ctx.internalAdapter.findUserByEmail(normalizedEmail, {
|
||||
includeAccounts: true,
|
||||
})
|
||||
@@ -282,9 +286,9 @@ async function ensureCredentialUser(config: BootstrapUserConfig): Promise<void>
|
||||
name: config.name,
|
||||
role: config.role,
|
||||
isBanned: false,
|
||||
isSystem: true,
|
||||
isSystem,
|
||||
isHidden: config.isHidden,
|
||||
isProtected: true,
|
||||
isProtected,
|
||||
},
|
||||
})
|
||||
|
||||
@@ -321,9 +325,9 @@ async function ensureCredentialUser(config: BootstrapUserConfig): Promise<void>
|
||||
emailVerified: true,
|
||||
role: config.role,
|
||||
isBanned: false,
|
||||
isSystem: true,
|
||||
isSystem,
|
||||
isHidden: config.isHidden,
|
||||
isProtected: true,
|
||||
isProtected,
|
||||
})
|
||||
|
||||
await ctx.internalAdapter.linkAccount({
|
||||
@@ -371,6 +375,86 @@ 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_USERNAME = "e2e-admin"
|
||||
const DEFAULT_E2E_ADMIN_PASSWORD = "e2e-admin-password"
|
||||
const DEFAULT_E2E_ADMIN_NAME = "E2E Admin"
|
||||
|
||||
export async function ensureE2EAdminBootstrap(): Promise<void> {
|
||||
const email = resolveBootstrapValue("CMS_E2E_ADMIN_EMAIL", DEFAULT_E2E_ADMIN_EMAIL)
|
||||
const username = resolveBootstrapValue("CMS_E2E_ADMIN_USERNAME", DEFAULT_E2E_ADMIN_USERNAME)
|
||||
const password = resolveBootstrapValue("CMS_E2E_ADMIN_PASSWORD", DEFAULT_E2E_ADMIN_PASSWORD)
|
||||
const name = resolveBootstrapValue("CMS_E2E_ADMIN_NAME", DEFAULT_E2E_ADMIN_NAME)
|
||||
|
||||
await ensureCredentialUser({
|
||||
email,
|
||||
username,
|
||||
password,
|
||||
name,
|
||||
role: "admin",
|
||||
isHidden: false,
|
||||
isSystem: true,
|
||||
isProtected: false,
|
||||
})
|
||||
}
|
||||
|
||||
type OwnerInvariantState = {
|
||||
ownerId: string | null
|
||||
ownerCount: number
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
"typecheck": "tsc -p tsconfig.json --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-s3": "3.988.0",
|
||||
"@cms/content": "workspace:*",
|
||||
"@cms/db": "workspace:*",
|
||||
"@cms/i18n": "workspace:*",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getPublishedPageBySlug } from "@cms/db"
|
||||
import { getPublishedPageBySlugForLocale } from "@cms/db"
|
||||
import { notFound } from "next/navigation"
|
||||
|
||||
import { PublicPageView } from "@/components/public-page-view"
|
||||
@@ -6,12 +6,12 @@ import { PublicPageView } from "@/components/public-page-view"
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
type PageProps = {
|
||||
params: Promise<{ slug: string }>
|
||||
params: Promise<{ locale: string; slug: string }>
|
||||
}
|
||||
|
||||
export default async function CmsPageRoute({ params }: PageProps) {
|
||||
const { slug } = await params
|
||||
const page = await getPublishedPageBySlug(slug)
|
||||
const { locale, slug } = await params
|
||||
const page = await getPublishedPageBySlugForLocale(slug, locale)
|
||||
|
||||
if (!page) {
|
||||
notFound()
|
||||
|
||||
217
apps/web/src/app/[locale]/commissions/page.tsx
Normal file
217
apps/web/src/app/[locale]/commissions/page.tsx
Normal file
@@ -0,0 +1,217 @@
|
||||
import { createPublicCommissionRequest } from "@cms/db"
|
||||
import { revalidatePath } from "next/cache"
|
||||
import { redirect } from "next/navigation"
|
||||
import { getTranslations } from "next-intl/server"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
type SearchParamsInput = Record<string, string | string[] | undefined>
|
||||
|
||||
type PublicCommissionRequestPageProps = {
|
||||
params: Promise<{ locale: string }>
|
||||
searchParams: Promise<SearchParamsInput>
|
||||
}
|
||||
|
||||
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 readNullableString(formData: FormData, field: string): string | null {
|
||||
const value = readInputString(formData, field)
|
||||
return value.length > 0 ? value : null
|
||||
}
|
||||
|
||||
function readNullableNumber(formData: FormData, field: string): number | null {
|
||||
const value = readInputString(formData, field)
|
||||
|
||||
if (!value) {
|
||||
return null
|
||||
}
|
||||
|
||||
const parsed = Number.parseFloat(value)
|
||||
return Number.isFinite(parsed) ? parsed : null
|
||||
}
|
||||
|
||||
function buildRedirect(locale: string, 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 serialized = query.toString()
|
||||
return serialized ? `/${locale}/commissions?${serialized}` : `/${locale}/commissions`
|
||||
}
|
||||
|
||||
export default async function PublicCommissionRequestPage({
|
||||
params,
|
||||
searchParams,
|
||||
}: PublicCommissionRequestPageProps) {
|
||||
const { locale } = await params
|
||||
const [resolvedSearchParams, t] = await Promise.all([
|
||||
searchParams,
|
||||
getTranslations("CommissionRequest"),
|
||||
])
|
||||
|
||||
async function submitCommissionRequestAction(formData: FormData) {
|
||||
"use server"
|
||||
|
||||
const budgetMin = readNullableNumber(formData, "budgetMin")
|
||||
const budgetMax = readNullableNumber(formData, "budgetMax")
|
||||
|
||||
if (budgetMin != null && budgetMax != null && budgetMax < budgetMin) {
|
||||
redirect(buildRedirect(locale, { error: "budget_range_invalid" }))
|
||||
}
|
||||
|
||||
try {
|
||||
await createPublicCommissionRequest({
|
||||
customerName: readInputString(formData, "customerName"),
|
||||
customerEmail: readInputString(formData, "customerEmail"),
|
||||
customerPhone: readNullableString(formData, "customerPhone"),
|
||||
customerInstagram: readNullableString(formData, "customerInstagram"),
|
||||
title: readInputString(formData, "title"),
|
||||
description: readNullableString(formData, "description"),
|
||||
budgetMin,
|
||||
budgetMax,
|
||||
})
|
||||
} catch {
|
||||
redirect(buildRedirect(locale, { error: "submission_failed" }))
|
||||
}
|
||||
|
||||
revalidatePath(`/${locale}/commissions`)
|
||||
redirect(buildRedirect(locale, { notice: "submitted" }))
|
||||
}
|
||||
|
||||
const notice = readFirstValue(resolvedSearchParams.notice)
|
||||
const error = readFirstValue(resolvedSearchParams.error)
|
||||
|
||||
return (
|
||||
<section className="mx-auto w-full max-w-3xl space-y-6 px-6 py-16">
|
||||
<header className="space-y-2">
|
||||
<p className="text-sm uppercase tracking-[0.2em] text-neutral-500">{t("badge")}</p>
|
||||
<h1 className="text-4xl font-semibold tracking-tight">{t("title")}</h1>
|
||||
<p className="text-neutral-600">{t("description")}</p>
|
||||
</header>
|
||||
|
||||
{notice === "submitted" ? (
|
||||
<section className="rounded-xl border border-emerald-300 bg-emerald-50 px-4 py-3 text-sm text-emerald-800">
|
||||
{t("success")}
|
||||
</section>
|
||||
) : null}
|
||||
|
||||
{error === "submission_failed" ? (
|
||||
<section className="rounded-xl border border-red-300 bg-red-50 px-4 py-3 text-sm text-red-800">
|
||||
{t("error")}
|
||||
</section>
|
||||
) : null}
|
||||
{error === "budget_range_invalid" ? (
|
||||
<section className="rounded-xl border border-amber-300 bg-amber-50 px-4 py-3 text-sm text-amber-800">
|
||||
{t("budgetRangeError")}
|
||||
</section>
|
||||
) : null}
|
||||
|
||||
<form action={submitCommissionRequestAction} className="space-y-4 rounded-xl border p-6">
|
||||
<div className="grid gap-4 md:grid-cols-2">
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs text-neutral-600">{t("fields.customerName")}</span>
|
||||
<input
|
||||
name="customerName"
|
||||
autoComplete="name"
|
||||
required
|
||||
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">{t("fields.customerEmail")}</span>
|
||||
<input
|
||||
name="customerEmail"
|
||||
type="email"
|
||||
autoComplete="email"
|
||||
required
|
||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-4 md:grid-cols-2">
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs text-neutral-600">{t("fields.customerPhone")}</span>
|
||||
<input
|
||||
name="customerPhone"
|
||||
autoComplete="tel"
|
||||
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">{t("fields.customerInstagram")}</span>
|
||||
<input
|
||||
name="customerInstagram"
|
||||
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">{t("fields.title")}</span>
|
||||
<input
|
||||
name="title"
|
||||
required
|
||||
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">{t("fields.description")}</span>
|
||||
<textarea
|
||||
name="description"
|
||||
rows={6}
|
||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
/>
|
||||
</label>
|
||||
|
||||
<div className="grid gap-4 md:grid-cols-2">
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs text-neutral-600">{t("fields.budgetMin")}</span>
|
||||
<input
|
||||
name="budgetMin"
|
||||
type="number"
|
||||
min="0"
|
||||
step="0.01"
|
||||
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">{t("fields.budgetMax")}</span>
|
||||
<input
|
||||
name="budgetMax"
|
||||
type="number"
|
||||
min="0"
|
||||
step="0.01"
|
||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
className="rounded-md bg-neutral-900 px-4 py-2 text-sm font-medium text-white hover:bg-neutral-700"
|
||||
>
|
||||
{t("submit")}
|
||||
</button>
|
||||
</form>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
@@ -52,7 +52,7 @@ export default async function LocaleLayout({ children, params }: LocaleLayoutPro
|
||||
<NextIntlClientProvider locale={locale}>
|
||||
<Providers>
|
||||
<PublicHeaderBanner banner={banner} />
|
||||
<PublicAnnouncements placement="global_top" />
|
||||
<PublicAnnouncements placement="global_top" locale={locale} />
|
||||
<PublicSiteHeader />
|
||||
<main>{children}</main>
|
||||
<PublicSiteFooter />
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { getPostBySlug } from "@cms/db"
|
||||
import { getPostBySlugForLocale } from "@cms/db"
|
||||
import { notFound } from "next/navigation"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
type PageProps = {
|
||||
params: Promise<{ slug: string }>
|
||||
params: Promise<{ locale: string; slug: string }>
|
||||
}
|
||||
|
||||
export default async function PublicNewsDetailPage({ params }: PageProps) {
|
||||
const { slug } = await params
|
||||
const post = await getPostBySlug(slug)
|
||||
const { locale, slug } = await params
|
||||
const post = await getPostBySlugForLocale(slug, locale)
|
||||
|
||||
if (!post || post.status !== "published") {
|
||||
notFound()
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
import { listPosts } from "@cms/db"
|
||||
import { listPostsForLocale } from "@cms/db"
|
||||
import Link from "next/link"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export default async function PublicNewsIndexPage() {
|
||||
const posts = await listPosts()
|
||||
type PublicNewsIndexPageProps = {
|
||||
params: Promise<{ locale: string }>
|
||||
}
|
||||
|
||||
export default async function PublicNewsIndexPage({ params }: PublicNewsIndexPageProps) {
|
||||
const { locale } = await params
|
||||
const posts = await listPostsForLocale(locale)
|
||||
|
||||
return (
|
||||
<section className="mx-auto w-full max-w-4xl space-y-4 px-6 py-16">
|
||||
|
||||
@@ -1,22 +1,28 @@
|
||||
import { getPublishedPageBySlug, listPosts } from "@cms/db"
|
||||
import { Button } from "@cms/ui/button"
|
||||
import { getPublishedPageBySlugForLocale, listPostsForLocale } from "@cms/db"
|
||||
import { getTranslations } from "next-intl/server"
|
||||
import { PublicAnnouncements } from "@/components/public-announcements"
|
||||
import { PublicPageView } from "@/components/public-page-view"
|
||||
import { Link } from "@/i18n/navigation"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export default async function HomePage() {
|
||||
type HomePageProps = {
|
||||
params: Promise<{ locale: string }>
|
||||
}
|
||||
|
||||
export default async function HomePage({ params }: HomePageProps) {
|
||||
const { locale } = await params
|
||||
|
||||
const [homePage, posts, t] = await Promise.all([
|
||||
getPublishedPageBySlug("home"),
|
||||
listPosts(),
|
||||
getPublishedPageBySlugForLocale("home", locale),
|
||||
listPostsForLocale(locale),
|
||||
getTranslations("Home"),
|
||||
])
|
||||
|
||||
return (
|
||||
<section>
|
||||
{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">
|
||||
<header className="space-y-3">
|
||||
@@ -28,7 +34,20 @@ export default async function HomePage() {
|
||||
<section className="space-y-4 rounded-xl border border-neutral-200 p-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="text-xl font-medium">{t("latestPosts")}</h3>
|
||||
<Button variant="secondary">{t("explore")}</Button>
|
||||
<div className="flex items-center gap-2">
|
||||
<Link
|
||||
href="/news"
|
||||
className="inline-flex h-10 items-center justify-center rounded-md bg-neutral-100 px-4 py-2 text-sm font-medium text-neutral-900 transition-colors hover:bg-neutral-200"
|
||||
>
|
||||
{t("explore")}
|
||||
</Link>
|
||||
<Link
|
||||
href="/commissions"
|
||||
className="inline-flex h-10 items-center justify-center rounded-md bg-neutral-900 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-neutral-800"
|
||||
>
|
||||
{t("requestCommission")}
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ul className="space-y-3">
|
||||
|
||||
136
apps/web/src/app/[locale]/portfolio/[slug]/page.tsx
Normal file
136
apps/web/src/app/[locale]/portfolio/[slug]/page.tsx
Normal file
@@ -0,0 +1,136 @@
|
||||
import { getPublishedArtworkBySlug } from "@cms/db"
|
||||
import Image from "next/image"
|
||||
import { notFound } from "next/navigation"
|
||||
import { getTranslations } from "next-intl/server"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
type PublicArtworkPageProps = {
|
||||
params: Promise<{ slug: string }>
|
||||
}
|
||||
|
||||
function formatLabelList(values: string[]) {
|
||||
if (values.length === 0) {
|
||||
return "-"
|
||||
}
|
||||
|
||||
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) {
|
||||
const [{ slug }, t] = await Promise.all([params, getTranslations("Portfolio")])
|
||||
const artwork = await getPublishedArtworkBySlug(slug)
|
||||
|
||||
if (!artwork) {
|
||||
notFound()
|
||||
}
|
||||
|
||||
const primaryMedia = artwork.renditions[0]?.mediaAsset ?? null
|
||||
|
||||
return (
|
||||
<section className="mx-auto w-full max-w-5xl space-y-6 px-6 py-16">
|
||||
<header className="space-y-2">
|
||||
<p className="text-sm uppercase tracking-[0.2em] text-neutral-500">{t("badge")}</p>
|
||||
<h1 className="text-4xl font-semibold tracking-tight">{artwork.title}</h1>
|
||||
<p className="text-neutral-600">{artwork.description || t("noDescription")}</p>
|
||||
</header>
|
||||
|
||||
<section className="grid gap-4 md:grid-cols-2">
|
||||
{artwork.renditions.length === 0 ? (
|
||||
<article className="rounded-xl border border-neutral-200 p-6 text-sm text-neutral-600">
|
||||
{t("noPreview")}
|
||||
</article>
|
||||
) : (
|
||||
artwork.renditions.map((rendition) => (
|
||||
<article
|
||||
key={rendition.id}
|
||||
className="overflow-hidden rounded-xl border border-neutral-200"
|
||||
>
|
||||
<Image
|
||||
src={`/api/media/file/${rendition.mediaAssetId}`}
|
||||
alt={rendition.mediaAsset.altText || artwork.title}
|
||||
width={1400}
|
||||
height={1000}
|
||||
className="h-72 w-full object-cover"
|
||||
/>
|
||||
<div className="flex items-center justify-between px-4 py-2 text-xs text-neutral-600">
|
||||
<span>{rendition.slot}</span>
|
||||
<span>
|
||||
{rendition.mediaAsset.width ?? "-"} x {rendition.mediaAsset.height ?? "-"}
|
||||
</span>
|
||||
</div>
|
||||
</article>
|
||||
))
|
||||
)}
|
||||
</section>
|
||||
|
||||
<section className="grid gap-4 rounded-xl border border-neutral-200 p-6 md:grid-cols-2">
|
||||
<div className="space-y-2 text-sm">
|
||||
<p>
|
||||
<strong>{t("fields.medium")}:</strong> {artwork.medium || "-"}
|
||||
</p>
|
||||
<p>
|
||||
<strong>{t("fields.dimensions")}:</strong> {artwork.dimensions || "-"}
|
||||
</p>
|
||||
<p>
|
||||
<strong>{t("fields.year")}:</strong> {artwork.year || "-"}
|
||||
</p>
|
||||
<p>
|
||||
<strong>{t("fields.availability")}:</strong> {artwork.availability || "-"}
|
||||
</p>
|
||||
<p>
|
||||
<strong>{t("fields.price")}:</strong>{" "}
|
||||
{artwork.isPriceVisible
|
||||
? formatArtworkPrice(artwork.priceAmountCents, artwork.priceCurrency)
|
||||
: "-"}
|
||||
</p>
|
||||
</div>
|
||||
<div className="space-y-2 text-sm">
|
||||
<p>
|
||||
<strong>{t("fields.galleries")}:</strong>{" "}
|
||||
{formatLabelList(artwork.galleryLinks.map((entry) => entry.gallery.name))}
|
||||
</p>
|
||||
<p>
|
||||
<strong>{t("fields.albums")}:</strong>{" "}
|
||||
{formatLabelList(artwork.albumLinks.map((entry) => entry.album.name))}
|
||||
</p>
|
||||
<p>
|
||||
<strong>{t("fields.categories")}:</strong>{" "}
|
||||
{formatLabelList(artwork.categoryLinks.map((entry) => entry.category.name))}
|
||||
</p>
|
||||
<p>
|
||||
<strong>{t("fields.tags")}:</strong>{" "}
|
||||
{formatLabelList(artwork.tagLinks.map((entry) => entry.tag.name))}
|
||||
</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>
|
||||
</section>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
291
apps/web/src/app/[locale]/portfolio/page.tsx
Normal file
291
apps/web/src/app/[locale]/portfolio/page.tsx
Normal file
@@ -0,0 +1,291 @@
|
||||
import { listPublishedArtworks, listPublishedPortfolioGroups } from "@cms/db"
|
||||
import Image from "next/image"
|
||||
import { getTranslations } from "next-intl/server"
|
||||
|
||||
import { Link } from "@/i18n/navigation"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
type SearchParamsInput = Record<string, string | string[] | undefined>
|
||||
|
||||
type PortfolioPageProps = {
|
||||
searchParams: Promise<SearchParamsInput>
|
||||
}
|
||||
|
||||
function readFirstValue(value: string | string[] | undefined): string | null {
|
||||
if (Array.isArray(value)) {
|
||||
return value[0] ?? null
|
||||
}
|
||||
|
||||
return value ?? null
|
||||
}
|
||||
|
||||
function resolveGroupFilter(searchParams: SearchParamsInput) {
|
||||
const gallery = readFirstValue(searchParams.gallery)
|
||||
if (gallery) {
|
||||
return { groupType: "gallery" as const, groupSlug: gallery }
|
||||
}
|
||||
|
||||
const album = readFirstValue(searchParams.album)
|
||||
if (album) {
|
||||
return { groupType: "album" as const, groupSlug: album }
|
||||
}
|
||||
|
||||
const category = readFirstValue(searchParams.category)
|
||||
if (category) {
|
||||
return { groupType: "category" as const, groupSlug: category }
|
||||
}
|
||||
|
||||
const tag = readFirstValue(searchParams.tag)
|
||||
if (tag) {
|
||||
return { groupType: "tag" as const, groupSlug: tag }
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
function resolveSort(searchParams: SearchParamsInput): "latest" | "title_asc" | "title_desc" {
|
||||
const sort = readFirstValue(searchParams.sort)
|
||||
|
||||
if (sort === "title_asc" || sort === "title_desc") {
|
||||
return sort
|
||||
}
|
||||
|
||||
return "latest"
|
||||
}
|
||||
|
||||
function buildPortfolioQuery(
|
||||
filter: ReturnType<typeof resolveGroupFilter>,
|
||||
sort: ReturnType<typeof resolveSort>,
|
||||
) {
|
||||
const query: Record<string, string> = {}
|
||||
|
||||
if (filter) {
|
||||
query[filter.groupType] = filter.groupSlug
|
||||
}
|
||||
|
||||
if (sort !== "latest") {
|
||||
query.sort = sort
|
||||
}
|
||||
|
||||
return query
|
||||
}
|
||||
|
||||
function findPreviewAsset(
|
||||
renditions: Array<{
|
||||
slot: string
|
||||
mediaAssetId: string
|
||||
mediaAsset: {
|
||||
id: string
|
||||
altText: string | null
|
||||
title: string
|
||||
}
|
||||
}>,
|
||||
) {
|
||||
const byPreference =
|
||||
renditions.find((item) => item.slot === "card") ??
|
||||
renditions.find((item) => item.slot === "thumbnail") ??
|
||||
renditions.find((item) => item.slot === "full") ??
|
||||
renditions[0]
|
||||
|
||||
return byPreference ?? null
|
||||
}
|
||||
|
||||
export default async function PortfolioPage({ searchParams }: PortfolioPageProps) {
|
||||
const [resolvedSearchParams, t] = await Promise.all([searchParams, getTranslations("Portfolio")])
|
||||
const activeFilter = resolveGroupFilter(resolvedSearchParams)
|
||||
const activeSort = resolveSort(resolvedSearchParams)
|
||||
|
||||
const [groups, artworks] = await Promise.all([
|
||||
listPublishedPortfolioGroups(),
|
||||
listPublishedArtworks(
|
||||
activeFilter
|
||||
? {
|
||||
groupType: activeFilter.groupType,
|
||||
groupSlug: activeFilter.groupSlug,
|
||||
sort: activeSort,
|
||||
}
|
||||
: {
|
||||
sort: activeSort,
|
||||
},
|
||||
),
|
||||
])
|
||||
|
||||
return (
|
||||
<section className="mx-auto w-full max-w-6xl space-y-6 px-6 py-16">
|
||||
<header className="space-y-2">
|
||||
<p className="text-sm uppercase tracking-[0.2em] text-neutral-500">{t("badge")}</p>
|
||||
<h1 className="text-4xl font-semibold tracking-tight">{t("title")}</h1>
|
||||
<p className="text-neutral-600">{t("description")}</p>
|
||||
</header>
|
||||
|
||||
<section className="rounded-xl border border-neutral-200 p-4">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<Link
|
||||
href={{
|
||||
pathname: "/portfolio",
|
||||
query: activeSort === "latest" ? undefined : { sort: activeSort },
|
||||
}}
|
||||
className="rounded-md border border-neutral-300 px-3 py-1.5 text-sm text-neutral-700 hover:bg-neutral-100"
|
||||
>
|
||||
{t("filters.clear")}
|
||||
</Link>
|
||||
|
||||
{groups.galleries.map((group) => (
|
||||
<Link
|
||||
key={`gallery-${group.id}`}
|
||||
href={{
|
||||
pathname: "/portfolio",
|
||||
query: {
|
||||
...buildPortfolioQuery(activeFilter, activeSort),
|
||||
gallery: group.slug,
|
||||
album: undefined,
|
||||
category: undefined,
|
||||
tag: undefined,
|
||||
},
|
||||
}}
|
||||
className="rounded-md border border-neutral-300 px-3 py-1.5 text-sm text-neutral-700 hover:bg-neutral-100"
|
||||
>
|
||||
{t("filters.gallery")}: {group.name}
|
||||
</Link>
|
||||
))}
|
||||
|
||||
{groups.albums.map((group) => (
|
||||
<Link
|
||||
key={`album-${group.id}`}
|
||||
href={{
|
||||
pathname: "/portfolio",
|
||||
query: {
|
||||
...buildPortfolioQuery(activeFilter, activeSort),
|
||||
gallery: undefined,
|
||||
album: group.slug,
|
||||
category: undefined,
|
||||
tag: undefined,
|
||||
},
|
||||
}}
|
||||
className="rounded-md border border-neutral-300 px-3 py-1.5 text-sm text-neutral-700 hover:bg-neutral-100"
|
||||
>
|
||||
{t("filters.album")}: {group.name}
|
||||
</Link>
|
||||
))}
|
||||
|
||||
{groups.categories.map((group) => (
|
||||
<Link
|
||||
key={`category-${group.id}`}
|
||||
href={{
|
||||
pathname: "/portfolio",
|
||||
query: {
|
||||
...buildPortfolioQuery(activeFilter, activeSort),
|
||||
gallery: undefined,
|
||||
album: undefined,
|
||||
category: group.slug,
|
||||
tag: undefined,
|
||||
},
|
||||
}}
|
||||
className="rounded-md border border-neutral-300 px-3 py-1.5 text-sm text-neutral-700 hover:bg-neutral-100"
|
||||
>
|
||||
{t("filters.category")}: {group.name}
|
||||
</Link>
|
||||
))}
|
||||
|
||||
{groups.tags.map((group) => (
|
||||
<Link
|
||||
key={`tag-${group.id}`}
|
||||
href={{
|
||||
pathname: "/portfolio",
|
||||
query: {
|
||||
...buildPortfolioQuery(activeFilter, activeSort),
|
||||
gallery: undefined,
|
||||
album: undefined,
|
||||
category: undefined,
|
||||
tag: group.slug,
|
||||
},
|
||||
}}
|
||||
className="rounded-md border border-neutral-300 px-3 py-1.5 text-sm text-neutral-700 hover:bg-neutral-100"
|
||||
>
|
||||
{t("filters.tag")}: {group.name}
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="mt-3 flex flex-wrap items-center gap-2">
|
||||
<span className="text-xs uppercase tracking-wide text-neutral-500">
|
||||
{t("sort.label")}:
|
||||
</span>
|
||||
<Link
|
||||
href={{
|
||||
pathname: "/portfolio",
|
||||
query: buildPortfolioQuery(activeFilter, "latest"),
|
||||
}}
|
||||
className="rounded-md border border-neutral-300 px-3 py-1.5 text-sm text-neutral-700 hover:bg-neutral-100"
|
||||
>
|
||||
{t("sort.latest")}
|
||||
</Link>
|
||||
<Link
|
||||
href={{
|
||||
pathname: "/portfolio",
|
||||
query: buildPortfolioQuery(activeFilter, "title_asc"),
|
||||
}}
|
||||
className="rounded-md border border-neutral-300 px-3 py-1.5 text-sm text-neutral-700 hover:bg-neutral-100"
|
||||
>
|
||||
{t("sort.titleAsc")}
|
||||
</Link>
|
||||
<Link
|
||||
href={{
|
||||
pathname: "/portfolio",
|
||||
query: buildPortfolioQuery(activeFilter, "title_desc"),
|
||||
}}
|
||||
className="rounded-md border border-neutral-300 px-3 py-1.5 text-sm text-neutral-700 hover:bg-neutral-100"
|
||||
>
|
||||
{t("sort.titleDesc")}
|
||||
</Link>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{artworks.length === 0 ? (
|
||||
<section className="rounded-xl border border-neutral-200 p-6 text-sm text-neutral-600">
|
||||
{t("empty")}
|
||||
</section>
|
||||
) : (
|
||||
<section className="grid gap-4 md:grid-cols-2 xl:grid-cols-3">
|
||||
{artworks.map((artwork) => {
|
||||
const preview = findPreviewAsset(artwork.renditions)
|
||||
|
||||
return (
|
||||
<article
|
||||
key={artwork.id}
|
||||
className="overflow-hidden rounded-xl border border-neutral-200"
|
||||
>
|
||||
{preview ? (
|
||||
<Image
|
||||
src={`/api/media/file/${preview.mediaAssetId}`}
|
||||
alt={preview.mediaAsset.altText || artwork.title}
|
||||
width={1200}
|
||||
height={800}
|
||||
className="h-56 w-full object-cover"
|
||||
/>
|
||||
) : (
|
||||
<div className="flex h-56 items-center justify-center bg-neutral-100 text-sm text-neutral-500">
|
||||
{t("noPreview")}
|
||||
</div>
|
||||
)}
|
||||
<div className="space-y-2 p-4">
|
||||
<h2 className="text-lg font-medium">{artwork.title}</h2>
|
||||
<p className="line-clamp-3 text-sm text-neutral-600">
|
||||
{artwork.description || t("noDescription")}
|
||||
</p>
|
||||
<Link
|
||||
href={`/portfolio/${artwork.slug}`}
|
||||
className="text-sm underline underline-offset-2"
|
||||
>
|
||||
{t("viewArtwork")}
|
||||
</Link>
|
||||
</div>
|
||||
</article>
|
||||
)
|
||||
})}
|
||||
</section>
|
||||
)}
|
||||
</section>
|
||||
)
|
||||
}
|
||||
47
apps/web/src/app/api/media/file/[id]/route.ts
Normal file
47
apps/web/src/app/api/media/file/[id]/route.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { getMediaAssetById } from "@cms/db"
|
||||
|
||||
import { readMediaStorageObject } from "@/lib/media/storage-read"
|
||||
|
||||
export const runtime = "nodejs"
|
||||
|
||||
type RouteContext = {
|
||||
params: Promise<{ id: string }>
|
||||
}
|
||||
|
||||
function toBody(data: Uint8Array): BodyInit {
|
||||
const bytes = new Uint8Array(data.byteLength)
|
||||
bytes.set(data)
|
||||
return bytes
|
||||
}
|
||||
|
||||
export async function GET(_request: Request, context: RouteContext): Promise<Response> {
|
||||
const { id } = await context.params
|
||||
const asset = await getMediaAssetById(id)
|
||||
|
||||
if (!asset || !asset.storageKey || !asset.isPublished) {
|
||||
return Response.json(
|
||||
{
|
||||
message: "Media file not found",
|
||||
},
|
||||
{ status: 404 },
|
||||
)
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await readMediaStorageObject(asset.storageKey)
|
||||
return new Response(toBody(data), {
|
||||
status: 200,
|
||||
headers: {
|
||||
"content-type": asset.mimeType || "application/octet-stream",
|
||||
"cache-control": "public, max-age=3600",
|
||||
},
|
||||
})
|
||||
} catch {
|
||||
return Response.json(
|
||||
{
|
||||
message: "Unable to read media file from configured storage backends",
|
||||
},
|
||||
{ status: 404 },
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import Link from "next/link"
|
||||
|
||||
type PublicAnnouncementsProps = {
|
||||
placement: "global_top" | "homepage"
|
||||
locale?: string
|
||||
}
|
||||
|
||||
function AnnouncementCard({ announcement }: { announcement: PublicAnnouncement }) {
|
||||
@@ -22,8 +23,8 @@ function AnnouncementCard({ announcement }: { announcement: PublicAnnouncement }
|
||||
)
|
||||
}
|
||||
|
||||
export async function PublicAnnouncements({ placement }: PublicAnnouncementsProps) {
|
||||
const announcements = await listActiveAnnouncements(placement)
|
||||
export async function PublicAnnouncements({ placement, locale }: PublicAnnouncementsProps) {
|
||||
const announcements = await listActiveAnnouncements(placement, new Date(), locale)
|
||||
|
||||
if (announcements.length === 0) {
|
||||
return null
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import { parsePageBlocks } from "@cms/content"
|
||||
import Image from "next/image"
|
||||
|
||||
type PageEntity = {
|
||||
title: string
|
||||
status: string
|
||||
@@ -9,7 +12,31 @@ type PublicPageViewProps = {
|
||||
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) {
|
||||
const blocks = (() => {
|
||||
try {
|
||||
return parsePageBlocks(page.content)
|
||||
} catch {
|
||||
return [
|
||||
{
|
||||
id: "fallback-rich-text",
|
||||
type: "rich_text" as const,
|
||||
body: page.content,
|
||||
},
|
||||
]
|
||||
}
|
||||
})()
|
||||
|
||||
return (
|
||||
<article className="mx-auto flex w-full max-w-4xl flex-col gap-6 px-6 py-16">
|
||||
<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}
|
||||
</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">
|
||||
{page.content}
|
||||
<section className="space-y-4 rounded-xl border border-neutral-200 bg-white p-6 text-neutral-800">
|
||||
{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>
|
||||
</article>
|
||||
)
|
||||
|
||||
@@ -1,11 +1,39 @@
|
||||
import { listPublicNavigation } from "@cms/db"
|
||||
import { getLocale, getTranslations } from "next-intl/server"
|
||||
|
||||
import { Link } from "@/i18n/navigation"
|
||||
|
||||
import { LanguageSwitcher } from "./language-switcher"
|
||||
|
||||
export async function PublicSiteHeader() {
|
||||
const navItems = await listPublicNavigation("header")
|
||||
const locale = await getLocale()
|
||||
const [navItems, t] = await Promise.all([
|
||||
listPublicNavigation("header", locale),
|
||||
getTranslations("Layout.nav"),
|
||||
])
|
||||
const fallbackNavItems = [
|
||||
{
|
||||
id: "fallback-home",
|
||||
href: "/",
|
||||
label: t("home"),
|
||||
},
|
||||
{
|
||||
id: "fallback-portfolio",
|
||||
href: "/portfolio",
|
||||
label: t("portfolio"),
|
||||
},
|
||||
{
|
||||
id: "fallback-news",
|
||||
href: "/news",
|
||||
label: t("news"),
|
||||
},
|
||||
{
|
||||
id: "fallback-commissions",
|
||||
href: "/commissions",
|
||||
label: t("commissions"),
|
||||
},
|
||||
]
|
||||
const resolvedNavItems = navItems.length > 0 ? navItems : fallbackNavItems
|
||||
|
||||
return (
|
||||
<header className="border-b border-neutral-200 bg-white/80 backdrop-blur">
|
||||
@@ -18,24 +46,15 @@ export async function PublicSiteHeader() {
|
||||
</Link>
|
||||
|
||||
<nav className="flex flex-wrap items-center gap-2">
|
||||
{navItems.length === 0 ? (
|
||||
{resolvedNavItems.map((item) => (
|
||||
<Link
|
||||
href="/"
|
||||
key={item.id}
|
||||
href={item.href}
|
||||
className="rounded-md border border-neutral-300 px-3 py-1.5 text-sm font-medium text-neutral-700 hover:bg-neutral-100"
|
||||
>
|
||||
Home
|
||||
{item.label}
|
||||
</Link>
|
||||
) : (
|
||||
navItems.map((item) => (
|
||||
<Link
|
||||
key={item.id}
|
||||
href={item.href}
|
||||
className="rounded-md border border-neutral-300 px-3 py-1.5 text-sm font-medium text-neutral-700 hover:bg-neutral-100"
|
||||
>
|
||||
{item.label}
|
||||
</Link>
|
||||
))
|
||||
)}
|
||||
))}
|
||||
</nav>
|
||||
|
||||
<LanguageSwitcher />
|
||||
|
||||
114
apps/web/src/lib/media/storage-read.ts
Normal file
114
apps/web/src/lib/media/storage-read.ts
Normal file
@@ -0,0 +1,114 @@
|
||||
import { readFile } from "node:fs/promises"
|
||||
import path from "node:path"
|
||||
import { GetObjectCommand, S3Client } from "@aws-sdk/client-s3"
|
||||
|
||||
export type MediaStorageProvider = "local" | "s3"
|
||||
|
||||
type S3Config = {
|
||||
bucket: string
|
||||
region: string
|
||||
endpoint?: string
|
||||
accessKeyId: string
|
||||
secretAccessKey: string
|
||||
forcePathStyle?: boolean
|
||||
}
|
||||
|
||||
function parseBoolean(value: string | undefined): boolean {
|
||||
return value?.toLowerCase() === "true"
|
||||
}
|
||||
|
||||
export function resolveMediaStorageProvider(raw: string | undefined): MediaStorageProvider {
|
||||
if (raw?.toLowerCase() === "local") {
|
||||
return "local"
|
||||
}
|
||||
|
||||
return "s3"
|
||||
}
|
||||
|
||||
function resolveS3Config(): S3Config {
|
||||
const bucket = process.env.CMS_MEDIA_S3_BUCKET?.trim()
|
||||
const region = process.env.CMS_MEDIA_S3_REGION?.trim()
|
||||
const accessKeyId = process.env.CMS_MEDIA_S3_ACCESS_KEY_ID?.trim()
|
||||
const secretAccessKey = process.env.CMS_MEDIA_S3_SECRET_ACCESS_KEY?.trim()
|
||||
const endpoint = process.env.CMS_MEDIA_S3_ENDPOINT?.trim() || undefined
|
||||
|
||||
if (!bucket || !region || !accessKeyId || !secretAccessKey) {
|
||||
throw new Error(
|
||||
"S3 storage selected but required env vars are missing: CMS_MEDIA_S3_BUCKET, CMS_MEDIA_S3_REGION, CMS_MEDIA_S3_ACCESS_KEY_ID, CMS_MEDIA_S3_SECRET_ACCESS_KEY",
|
||||
)
|
||||
}
|
||||
|
||||
return {
|
||||
bucket,
|
||||
region,
|
||||
endpoint,
|
||||
accessKeyId,
|
||||
secretAccessKey,
|
||||
forcePathStyle: parseBoolean(process.env.CMS_MEDIA_S3_FORCE_PATH_STYLE),
|
||||
}
|
||||
}
|
||||
|
||||
function createS3Client(config: S3Config): S3Client {
|
||||
return new S3Client({
|
||||
region: config.region,
|
||||
endpoint: config.endpoint,
|
||||
forcePathStyle: config.forcePathStyle,
|
||||
credentials: {
|
||||
accessKeyId: config.accessKeyId,
|
||||
secretAccessKey: config.secretAccessKey,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
function resolveLocalMediaBaseDirectory(): string {
|
||||
const configured = process.env.CMS_MEDIA_LOCAL_STORAGE_DIR?.trim()
|
||||
|
||||
if (configured) {
|
||||
return path.resolve(configured)
|
||||
}
|
||||
|
||||
return path.resolve(process.cwd(), ".data", "media")
|
||||
}
|
||||
|
||||
async function readFromLocalStorage(storageKey: string): Promise<Uint8Array> {
|
||||
const baseDirectory = resolveLocalMediaBaseDirectory()
|
||||
const outputPath = path.join(baseDirectory, storageKey)
|
||||
|
||||
return readFile(outputPath)
|
||||
}
|
||||
|
||||
async function readFromS3Storage(storageKey: string): Promise<Uint8Array> {
|
||||
const config = resolveS3Config()
|
||||
const client = createS3Client(config)
|
||||
|
||||
const response = await client.send(
|
||||
new GetObjectCommand({
|
||||
Bucket: config.bucket,
|
||||
Key: storageKey,
|
||||
}),
|
||||
)
|
||||
|
||||
if (!response.Body) {
|
||||
throw new Error("S3 object body is empty")
|
||||
}
|
||||
|
||||
return response.Body.transformToByteArray()
|
||||
}
|
||||
|
||||
export async function readMediaStorageObject(storageKey: string): Promise<Uint8Array> {
|
||||
const preferred = resolveMediaStorageProvider(process.env.CMS_MEDIA_STORAGE_PROVIDER)
|
||||
const reads =
|
||||
preferred === "s3"
|
||||
? [() => readFromS3Storage(storageKey), () => readFromLocalStorage(storageKey)]
|
||||
: [() => readFromLocalStorage(storageKey), () => readFromS3Storage(storageKey)]
|
||||
|
||||
for (const read of reads) {
|
||||
try {
|
||||
return await read()
|
||||
} catch {
|
||||
// Try next backend.
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error("Unable to read media file from configured storage backends")
|
||||
}
|
||||
@@ -5,7 +5,8 @@
|
||||
"description": "Diese Seite liest Beiträge über das gemeinsame Datenbank-Paket.",
|
||||
"latestPosts": "Neueste Beiträge",
|
||||
"explore": "Entdecken",
|
||||
"noExcerpt": "Kein Auszug"
|
||||
"noExcerpt": "Kein Auszug",
|
||||
"requestCommission": "Auftrag anfragen"
|
||||
},
|
||||
"LanguageSwitcher": {
|
||||
"label": "Sprache",
|
||||
@@ -20,6 +21,9 @@
|
||||
"brand": "CMS Web",
|
||||
"nav": {
|
||||
"home": "Start",
|
||||
"portfolio": "Portfolio",
|
||||
"news": "News",
|
||||
"commissions": "Aufträge",
|
||||
"about": "Über uns",
|
||||
"contact": "Kontakt"
|
||||
},
|
||||
@@ -41,5 +45,62 @@
|
||||
"badge": "Kontakt",
|
||||
"title": "Kontakt",
|
||||
"description": "Kontakt- und Auftragsabläufe werden in den nächsten MVP-Schritten eingeführt."
|
||||
},
|
||||
"CommissionRequest": {
|
||||
"badge": "Aufträge",
|
||||
"title": "Auftragsanfrage",
|
||||
"description": "Teile deine Idee und Projektdetails. Wir prüfen die Anfrage und melden uns zeitnah.",
|
||||
"success": "Deine Auftragsanfrage wurde übermittelt.",
|
||||
"error": "Übermittlung fehlgeschlagen. Bitte prüfe die Eingaben und versuche es erneut.",
|
||||
"budgetRangeError": "Das maximale Budget muss größer oder gleich dem minimalen Budget sein.",
|
||||
"submit": "Anfrage senden",
|
||||
"fields": {
|
||||
"customerName": "Name",
|
||||
"customerEmail": "E-Mail",
|
||||
"customerPhone": "Telefon",
|
||||
"customerInstagram": "Instagram",
|
||||
"title": "Projekttitel",
|
||||
"description": "Projektdetails",
|
||||
"budgetMin": "Budget min.",
|
||||
"budgetMax": "Budget max."
|
||||
}
|
||||
},
|
||||
"Portfolio": {
|
||||
"badge": "Portfolio",
|
||||
"title": "Kunstwerk-Portfolio",
|
||||
"description": "Durchsuche veröffentlichte Kunstwerke aus Galerien, Alben und Kategorien.",
|
||||
"empty": "Keine Kunstwerke für diesen Filter gefunden.",
|
||||
"noPreview": "Keine Vorschau verfügbar",
|
||||
"noDescription": "Keine Beschreibung",
|
||||
"viewArtwork": "Kunstwerk ansehen",
|
||||
"filters": {
|
||||
"clear": "Filter zurücksetzen",
|
||||
"gallery": "Galerie",
|
||||
"album": "Album",
|
||||
"category": "Kategorie",
|
||||
"tag": "Tag"
|
||||
},
|
||||
"sort": {
|
||||
"label": "Sortierung",
|
||||
"latest": "Neueste",
|
||||
"titleAsc": "Titel A-Z",
|
||||
"titleDesc": "Titel Z-A"
|
||||
},
|
||||
"fields": {
|
||||
"medium": "Medium",
|
||||
"dimensions": "Abmessungen",
|
||||
"year": "Jahr",
|
||||
"availability": "Verfügbarkeit",
|
||||
"price": "Preis",
|
||||
"galleries": "Galerien",
|
||||
"albums": "Alben",
|
||||
"categories": "Kategorien",
|
||||
"tags": "Tags",
|
||||
"licenseType": "Lizenztyp",
|
||||
"licenseUrl": "Lizenz-URL",
|
||||
"usageContext": "Nutzungskontext",
|
||||
"location": "Ort",
|
||||
"capturedAt": "Aufgenommen am"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
"description": "This page reads posts through the shared database package.",
|
||||
"latestPosts": "Latest posts",
|
||||
"explore": "Explore",
|
||||
"noExcerpt": "No excerpt"
|
||||
"noExcerpt": "No excerpt",
|
||||
"requestCommission": "Request commission"
|
||||
},
|
||||
"LanguageSwitcher": {
|
||||
"label": "Language",
|
||||
@@ -20,6 +21,9 @@
|
||||
"brand": "CMS Web",
|
||||
"nav": {
|
||||
"home": "Home",
|
||||
"portfolio": "Portfolio",
|
||||
"news": "News",
|
||||
"commissions": "Commissions",
|
||||
"about": "About",
|
||||
"contact": "Contact"
|
||||
},
|
||||
@@ -41,5 +45,62 @@
|
||||
"badge": "Contact",
|
||||
"title": "Contact",
|
||||
"description": "Contact and commission flows will be introduced in upcoming MVP steps."
|
||||
},
|
||||
"CommissionRequest": {
|
||||
"badge": "Commissions",
|
||||
"title": "Commission request",
|
||||
"description": "Share your idea and project details. We will review and reply as soon as possible.",
|
||||
"success": "Your commission request was submitted.",
|
||||
"error": "Submission failed. Please review your data and try again.",
|
||||
"budgetRangeError": "Budget max must be greater than or equal to budget min.",
|
||||
"submit": "Submit request",
|
||||
"fields": {
|
||||
"customerName": "Name",
|
||||
"customerEmail": "Email",
|
||||
"customerPhone": "Phone",
|
||||
"customerInstagram": "Instagram",
|
||||
"title": "Project title",
|
||||
"description": "Project details",
|
||||
"budgetMin": "Budget min",
|
||||
"budgetMax": "Budget max"
|
||||
}
|
||||
},
|
||||
"Portfolio": {
|
||||
"badge": "Portfolio",
|
||||
"title": "Artwork portfolio",
|
||||
"description": "Browse published artworks from galleries, albums, and categories.",
|
||||
"empty": "No artworks found for this filter.",
|
||||
"noPreview": "No preview available",
|
||||
"noDescription": "No description",
|
||||
"viewArtwork": "View artwork",
|
||||
"filters": {
|
||||
"clear": "Clear filters",
|
||||
"gallery": "Gallery",
|
||||
"album": "Album",
|
||||
"category": "Category",
|
||||
"tag": "Tag"
|
||||
},
|
||||
"sort": {
|
||||
"label": "Sort",
|
||||
"latest": "Latest",
|
||||
"titleAsc": "Title A-Z",
|
||||
"titleDesc": "Title Z-A"
|
||||
},
|
||||
"fields": {
|
||||
"medium": "Medium",
|
||||
"dimensions": "Dimensions",
|
||||
"year": "Year",
|
||||
"availability": "Availability",
|
||||
"price": "Price",
|
||||
"galleries": "Galleries",
|
||||
"albums": "Albums",
|
||||
"categories": "Categories",
|
||||
"tags": "Tags",
|
||||
"licenseType": "License type",
|
||||
"licenseUrl": "License URL",
|
||||
"usageContext": "Usage context",
|
||||
"location": "Location",
|
||||
"capturedAt": "Captured at"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
"description": "Esta página lee publicaciones a través del paquete compartido de base de datos.",
|
||||
"latestPosts": "Últimas publicaciones",
|
||||
"explore": "Explorar",
|
||||
"noExcerpt": "Sin extracto"
|
||||
"noExcerpt": "Sin extracto",
|
||||
"requestCommission": "Solicitar comisión"
|
||||
},
|
||||
"LanguageSwitcher": {
|
||||
"label": "Idioma",
|
||||
@@ -20,6 +21,9 @@
|
||||
"brand": "CMS Web",
|
||||
"nav": {
|
||||
"home": "Inicio",
|
||||
"portfolio": "Portafolio",
|
||||
"news": "Noticias",
|
||||
"commissions": "Comisiones",
|
||||
"about": "Acerca de",
|
||||
"contact": "Contacto"
|
||||
},
|
||||
@@ -41,5 +45,62 @@
|
||||
"badge": "Contacto",
|
||||
"title": "Contacto",
|
||||
"description": "Los flujos de contacto y comisiones se incorporarán en los siguientes pasos del MVP."
|
||||
},
|
||||
"CommissionRequest": {
|
||||
"badge": "Comisiones",
|
||||
"title": "Solicitud de comisión",
|
||||
"description": "Comparte tu idea y detalles del proyecto. Revisaremos la solicitud y responderemos pronto.",
|
||||
"success": "Tu solicitud de comisión fue enviada.",
|
||||
"error": "No se pudo enviar la solicitud. Revisa los datos e inténtalo de nuevo.",
|
||||
"budgetRangeError": "El presupuesto máximo debe ser mayor o igual al mínimo.",
|
||||
"submit": "Enviar solicitud",
|
||||
"fields": {
|
||||
"customerName": "Nombre",
|
||||
"customerEmail": "Correo electrónico",
|
||||
"customerPhone": "Teléfono",
|
||||
"customerInstagram": "Instagram",
|
||||
"title": "Título del proyecto",
|
||||
"description": "Detalles del proyecto",
|
||||
"budgetMin": "Presupuesto mínimo",
|
||||
"budgetMax": "Presupuesto máximo"
|
||||
}
|
||||
},
|
||||
"Portfolio": {
|
||||
"badge": "Portafolio",
|
||||
"title": "Portafolio de obras",
|
||||
"description": "Explora obras publicadas de galerías, álbumes y categorías.",
|
||||
"empty": "No se encontraron obras para este filtro.",
|
||||
"noPreview": "Sin vista previa",
|
||||
"noDescription": "Sin descripción",
|
||||
"viewArtwork": "Ver obra",
|
||||
"filters": {
|
||||
"clear": "Limpiar filtros",
|
||||
"gallery": "Galería",
|
||||
"album": "Álbum",
|
||||
"category": "Categoría",
|
||||
"tag": "Etiqueta"
|
||||
},
|
||||
"sort": {
|
||||
"label": "Orden",
|
||||
"latest": "Más recientes",
|
||||
"titleAsc": "Título A-Z",
|
||||
"titleDesc": "Título Z-A"
|
||||
},
|
||||
"fields": {
|
||||
"medium": "Técnica",
|
||||
"dimensions": "Dimensiones",
|
||||
"year": "Año",
|
||||
"availability": "Disponibilidad",
|
||||
"price": "Precio",
|
||||
"galleries": "Galerías",
|
||||
"albums": "Álbumes",
|
||||
"categories": "Categorías",
|
||||
"tags": "Etiquetas",
|
||||
"licenseType": "Tipo de licencia",
|
||||
"licenseUrl": "URL de licencia",
|
||||
"usageContext": "Contexto de uso",
|
||||
"location": "Ubicación",
|
||||
"capturedAt": "Capturado el"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
"description": "Cette page lit les publications via le package base de données partagé.",
|
||||
"latestPosts": "Dernières publications",
|
||||
"explore": "Explorer",
|
||||
"noExcerpt": "Aucun extrait"
|
||||
"noExcerpt": "Aucun extrait",
|
||||
"requestCommission": "Demander une commission"
|
||||
},
|
||||
"LanguageSwitcher": {
|
||||
"label": "Langue",
|
||||
@@ -20,6 +21,9 @@
|
||||
"brand": "CMS Web",
|
||||
"nav": {
|
||||
"home": "Accueil",
|
||||
"portfolio": "Portfolio",
|
||||
"news": "Actualités",
|
||||
"commissions": "Commissions",
|
||||
"about": "À propos",
|
||||
"contact": "Contact"
|
||||
},
|
||||
@@ -41,5 +45,62 @@
|
||||
"badge": "Contact",
|
||||
"title": "Contact",
|
||||
"description": "Les flux de contact et de commission seront introduits dans les prochaines étapes MVP."
|
||||
},
|
||||
"CommissionRequest": {
|
||||
"badge": "Commissions",
|
||||
"title": "Demande de commission",
|
||||
"description": "Partagez votre idée et les détails du projet. Nous examinerons la demande et répondrons rapidement.",
|
||||
"success": "Votre demande de commission a été envoyée.",
|
||||
"error": "Échec de l'envoi. Vérifiez les données et réessayez.",
|
||||
"budgetRangeError": "Le budget max doit être supérieur ou égal au budget min.",
|
||||
"submit": "Envoyer la demande",
|
||||
"fields": {
|
||||
"customerName": "Nom",
|
||||
"customerEmail": "E-mail",
|
||||
"customerPhone": "Téléphone",
|
||||
"customerInstagram": "Instagram",
|
||||
"title": "Titre du projet",
|
||||
"description": "Détails du projet",
|
||||
"budgetMin": "Budget min",
|
||||
"budgetMax": "Budget max"
|
||||
}
|
||||
},
|
||||
"Portfolio": {
|
||||
"badge": "Portfolio",
|
||||
"title": "Portfolio d'oeuvres",
|
||||
"description": "Parcourez les oeuvres publiées par galeries, albums et catégories.",
|
||||
"empty": "Aucune oeuvre trouvée pour ce filtre.",
|
||||
"noPreview": "Aperçu indisponible",
|
||||
"noDescription": "Aucune description",
|
||||
"viewArtwork": "Voir l'oeuvre",
|
||||
"filters": {
|
||||
"clear": "Réinitialiser les filtres",
|
||||
"gallery": "Galerie",
|
||||
"album": "Album",
|
||||
"category": "Catégorie",
|
||||
"tag": "Tag"
|
||||
},
|
||||
"sort": {
|
||||
"label": "Tri",
|
||||
"latest": "Plus récents",
|
||||
"titleAsc": "Titre A-Z",
|
||||
"titleDesc": "Titre Z-A"
|
||||
},
|
||||
"fields": {
|
||||
"medium": "Médium",
|
||||
"dimensions": "Dimensions",
|
||||
"year": "Année",
|
||||
"availability": "Disponibilité",
|
||||
"price": "Prix",
|
||||
"galleries": "Galeries",
|
||||
"albums": "Albums",
|
||||
"categories": "Catégories",
|
||||
"tags": "Tags",
|
||||
"licenseType": "Type de licence",
|
||||
"licenseUrl": "URL de licence",
|
||||
"usageContext": "Contexte d'utilisation",
|
||||
"location": "Lieu",
|
||||
"capturedAt": "Capturé le"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
3
bun.lock
3
bun.lock
@@ -28,7 +28,7 @@
|
||||
"name": "@cms/admin",
|
||||
"version": "0.0.1",
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-s3": "^3.988.0",
|
||||
"@aws-sdk/client-s3": "3.988.0",
|
||||
"@cms/content": "workspace:*",
|
||||
"@cms/db": "workspace:*",
|
||||
"@cms/i18n": "workspace:*",
|
||||
@@ -58,6 +58,7 @@
|
||||
"name": "@cms/web",
|
||||
"version": "0.0.1",
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-s3": "3.988.0",
|
||||
"@cms/content": "workspace:*",
|
||||
"@cms/db": "workspace:*",
|
||||
"@cms/i18n": "workspace:*",
|
||||
|
||||
30
conventional-changelog.config.cjs
Normal file
30
conventional-changelog.config.cjs
Normal file
@@ -0,0 +1,30 @@
|
||||
module.exports = {
|
||||
preset: "conventionalcommits",
|
||||
writerOpts: {
|
||||
transform: (commit) => {
|
||||
const typeMap = {
|
||||
feat: "Features",
|
||||
fix: "Bug Fixes",
|
||||
perf: "Performance",
|
||||
refactor: "Refactors",
|
||||
docs: "Documentation",
|
||||
test: "Tests",
|
||||
build: "Build System",
|
||||
ci: "CI",
|
||||
chore: "Chores",
|
||||
revert: "Reverts",
|
||||
}
|
||||
|
||||
const mappedType = typeMap[commit.type]
|
||||
|
||||
if (!mappedType) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
return {
|
||||
...commit,
|
||||
type: mappedType,
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -25,6 +25,10 @@ export default defineConfig({
|
||||
{ text: "i18n Baseline", link: "/product-engineering/i18n-baseline" },
|
||||
{ text: "i18n Conventions", link: "/product-engineering/i18n-conventions" },
|
||||
{ text: "RBAC And Permissions", link: "/product-engineering/rbac-permission-model" },
|
||||
{ text: "Code Architecture Map", link: "/product-engineering/code-architecture-map" },
|
||||
{ text: "Critical Invariants", link: "/product-engineering/critical-invariants" },
|
||||
{ text: "Request Lifecycle Flows", link: "/product-engineering/request-lifecycle-flows" },
|
||||
{ text: "Code Handover Playbook", link: "/product-engineering/code-handover-playbook" },
|
||||
{ text: "Domain Glossary", link: "/product-engineering/domain-glossary" },
|
||||
{ text: "Environment Runbook", link: "/product-engineering/environment-runbook" },
|
||||
{ text: "Delivery Pipeline", link: "/product-engineering/delivery-pipeline" },
|
||||
|
||||
53
docs/product-engineering/code-architecture-map.md
Normal file
53
docs/product-engineering/code-architecture-map.md
Normal file
@@ -0,0 +1,53 @@
|
||||
# Code Architecture Map
|
||||
|
||||
This page is the fast handover map for engineers taking over the codebase.
|
||||
|
||||
## Repository Structure
|
||||
|
||||
- `apps/admin`:
|
||||
Next.js admin panel. Owns auth UI, CMS management screens, and protected workflows.
|
||||
- `apps/web`:
|
||||
Next.js public site. Renders CMS-managed content and public-facing routes.
|
||||
- `packages/db`:
|
||||
Prisma schema, generated client usage, and data access services.
|
||||
- `packages/content`:
|
||||
Domain-level Zod schemas and shared contracts.
|
||||
- `packages/crud`:
|
||||
Shared CRUD service pattern (validation, not-found behavior, audit hook contracts).
|
||||
- `packages/ui`:
|
||||
Shared UI primitives used by admin/public apps.
|
||||
- `packages/i18n`:
|
||||
Shared locale helpers.
|
||||
|
||||
## Runtime Boundaries
|
||||
|
||||
- Admin app:
|
||||
writes content and settings, enforces RBAC, runs Better Auth route handlers.
|
||||
- Public app:
|
||||
reads published content and settings; no public auth coupling.
|
||||
- DB package:
|
||||
only data access and business-persistence rules.
|
||||
- Content package:
|
||||
only validation and domain typing; no DB or framework runtime coupling.
|
||||
|
||||
## Core Feature Modules
|
||||
|
||||
- Auth and user guards:
|
||||
`apps/admin/src/lib/auth/server.ts`, `apps/admin/src/app/api/auth/[...all]/route.ts`
|
||||
- Access and route permissions:
|
||||
`apps/admin/src/lib/access.ts`, `apps/admin/src/lib/route-guards.ts`
|
||||
- Media domain + storage:
|
||||
`packages/db/src/media-foundation.ts`, `apps/admin/src/lib/media/storage.ts`
|
||||
- Pages and navigation:
|
||||
`packages/db/src/pages-navigation.ts`, `apps/admin/src/app/pages/*`, `apps/admin/src/app/navigation/*`
|
||||
- Commissions and customers:
|
||||
`packages/db/src/commissions.ts`, `apps/admin/src/app/commissions/page.tsx`
|
||||
- Announcements and news:
|
||||
`packages/db/src/announcements.ts`, `apps/admin/src/app/announcements/page.tsx`, `apps/admin/src/app/news/page.tsx`
|
||||
|
||||
## Extension Rules
|
||||
|
||||
- Add/adjust schema first in `packages/content`.
|
||||
- Implement persistence in `packages/db`.
|
||||
- Wire usage in app route/actions after schema/service are in place.
|
||||
- Add tests at service and app-boundary levels before marking TODO items done.
|
||||
62
docs/product-engineering/code-handover-playbook.md
Normal file
62
docs/product-engineering/code-handover-playbook.md
Normal file
@@ -0,0 +1,62 @@
|
||||
# Code Handover Playbook
|
||||
|
||||
This is the minimum runbook for a new engineer to continue delivery safely.
|
||||
|
||||
## Local Setup
|
||||
|
||||
1. Install Bun matching repo policy.
|
||||
2. Copy `.env.example` to `.env` and fill required values.
|
||||
3. Generate Prisma client:
|
||||
`bun run db:generate`
|
||||
4. Apply migrations:
|
||||
`bun run db:migrate:deploy` (or local named migration flow)
|
||||
5. Seed data:
|
||||
`bun run db:seed`
|
||||
6. Start apps:
|
||||
`bun run dev`
|
||||
|
||||
## Daily Development Loop
|
||||
|
||||
1. Create branch by task type:
|
||||
`todo/*`, `refactor/*`, `code/*`.
|
||||
2. Implement smallest vertical slice for one TODO item.
|
||||
3. Run quality gates:
|
||||
`bun run check`
|
||||
`bun run typecheck`
|
||||
`bun run test`
|
||||
4. Update `TODO.md` status and discovery log.
|
||||
5. Commit with Conventional Commit message and GPG signing.
|
||||
|
||||
## Database Workflow
|
||||
|
||||
- Schema source is:
|
||||
`packages/db/prisma/schema.prisma`
|
||||
- Use named dev migrations for schema changes.
|
||||
- Avoid manual SQL unless migration tooling is blocked.
|
||||
- Always regenerate client after schema change.
|
||||
|
||||
## Testing Strategy
|
||||
|
||||
- Unit/service tests:
|
||||
`packages/*` and logic helpers.
|
||||
- App-boundary integration tests:
|
||||
auth flow and route-level behavior.
|
||||
- E2E tests:
|
||||
full admin/public happy paths through Playwright.
|
||||
|
||||
## Common Failure Recovery
|
||||
|
||||
- `DATABASE_URL not set`:
|
||||
ensure root `.env` is loaded for Bun/Prisma scripts.
|
||||
- Prisma client import errors:
|
||||
run `bun run db:generate`.
|
||||
- Migration drift:
|
||||
run deploy/reset flow in dev and reseed.
|
||||
- Playwright host deps missing:
|
||||
install browser dependencies on host before running e2e.
|
||||
|
||||
## Ownership Expectations
|
||||
|
||||
- Keep invariants explicit and tested before changing auth/media pipelines.
|
||||
- Treat `TODO.md` as delivery source of truth.
|
||||
- If changing branch/release workflow, update docs in same branch.
|
||||
57
docs/product-engineering/critical-invariants.md
Normal file
57
docs/product-engineering/critical-invariants.md
Normal file
@@ -0,0 +1,57 @@
|
||||
# Critical Invariants
|
||||
|
||||
These rules must stay true across refactors and feature work.
|
||||
|
||||
## Auth and User Invariants
|
||||
|
||||
- Exactly one owner user must exist.
|
||||
- The canonical owner must remain protected and not banned.
|
||||
- Support user is system-owned and protected.
|
||||
- Protected users cannot be deleted through auth endpoints.
|
||||
- First owner bootstrap closes open owner-registration window.
|
||||
|
||||
Primary implementation:
|
||||
- `apps/admin/src/lib/auth/server.ts`
|
||||
- `apps/admin/src/app/api/auth/[...all]/route.ts`
|
||||
|
||||
Primary tests:
|
||||
- `apps/admin/src/lib/auth/server.test.ts`
|
||||
- `apps/admin/src/app/register/page.test.tsx`
|
||||
- `apps/admin/src/app/welcome/page.test.tsx`
|
||||
- `apps/admin/src/app/login/page.test.tsx`
|
||||
|
||||
## Registration Policy Invariants
|
||||
|
||||
- If no owner exists:
|
||||
`welcome` flow is open for first owner bootstrap.
|
||||
- If owner exists:
|
||||
self-registration depends on persisted policy in `system_setting`.
|
||||
- Register route must never silently create users when policy is disabled.
|
||||
|
||||
Primary implementation:
|
||||
- `packages/db/src/settings.ts`
|
||||
- `apps/admin/src/app/settings/page.tsx`
|
||||
- `apps/admin/src/app/register/page.tsx`
|
||||
|
||||
## Media Storage Contract
|
||||
|
||||
- Storage provider is selected by `CMS_MEDIA_STORAGE_PROVIDER`.
|
||||
- S3 is primary; local is explicit fallback.
|
||||
- Each media asset stores a stable `storageKey`.
|
||||
- Deleting a media asset must also attempt storage object deletion.
|
||||
|
||||
Primary implementation:
|
||||
- `apps/admin/src/lib/media/storage.ts`
|
||||
- `apps/admin/src/lib/media/storage-key.ts`
|
||||
- `apps/admin/src/app/media/[id]/page.tsx`
|
||||
|
||||
## Public Rendering Contract
|
||||
|
||||
- Public pages must render only published CMS pages.
|
||||
- Public navigation must be built from managed menu items.
|
||||
- Header banner and announcements must be optional and fail-safe.
|
||||
|
||||
Primary implementation:
|
||||
- `apps/web/src/app/[locale]/layout.tsx`
|
||||
- `apps/web/src/app/[locale]/page.tsx`
|
||||
- `apps/web/src/app/[locale]/[slug]/page.tsx`
|
||||
@@ -11,6 +11,10 @@ This section covers platform and implementation documentation for engineers and
|
||||
- [i18n Conventions](/product-engineering/i18n-conventions)
|
||||
- [CRUD Examples](/product-engineering/crud-examples)
|
||||
- [Package Catalog And Decision Notes](/product-engineering/package-catalog)
|
||||
- [Code Architecture Map](/product-engineering/code-architecture-map)
|
||||
- [Critical Invariants](/product-engineering/critical-invariants)
|
||||
- [Request Lifecycle Flows](/product-engineering/request-lifecycle-flows)
|
||||
- [Code Handover Playbook](/product-engineering/code-handover-playbook)
|
||||
- [User Personas And Use-Case Topics](/product-engineering/user-personas-and-use-cases)
|
||||
- [CMS Feature Topics (Domain-Centric)](/product-engineering/cms-feature-topics)
|
||||
- [Domain Glossary](/product-engineering/domain-glossary)
|
||||
|
||||
87
docs/product-engineering/request-lifecycle-flows.md
Normal file
87
docs/product-engineering/request-lifecycle-flows.md
Normal file
@@ -0,0 +1,87 @@
|
||||
# Request Lifecycle Flows
|
||||
|
||||
## 1. Auth Sign-In (Admin)
|
||||
|
||||
1. Browser posts to `/api/auth/sign-in/email`.
|
||||
2. Route resolves `identifier` (email or username) to canonical email.
|
||||
3. Better Auth credential sign-in executes.
|
||||
4. Session cookie is set and user is redirected.
|
||||
|
||||
Key files:
|
||||
- `apps/admin/src/app/login/login-form.tsx`
|
||||
- `apps/admin/src/app/api/auth/[...all]/route.ts`
|
||||
- `apps/admin/src/lib/auth/server.ts`
|
||||
|
||||
## 2. Initial Owner Registration
|
||||
|
||||
1. If no owner exists, `/welcome` renders owner sign-up mode.
|
||||
2. Sign-up request goes through auth route handler.
|
||||
3. New user is promoted to owner in transactional guard.
|
||||
4. Owner invariant is re-validated to enforce single owner.
|
||||
|
||||
Key files:
|
||||
- `apps/admin/src/app/welcome/page.tsx`
|
||||
- `apps/admin/src/app/api/auth/[...all]/route.ts`
|
||||
- `apps/admin/src/lib/auth/server.ts`
|
||||
|
||||
## 3. Media Upload
|
||||
|
||||
1. Admin form posts multipart data to `/api/media/upload`.
|
||||
2. Metadata is validated and file is stored through selected provider.
|
||||
3. Media asset record is persisted with storage metadata.
|
||||
4. UI redirects back to media list with flash status query.
|
||||
|
||||
Key files:
|
||||
- `apps/admin/src/components/media/media-upload-form.tsx`
|
||||
- `apps/admin/src/app/api/media/upload/route.ts`
|
||||
- `apps/admin/src/lib/media/storage.ts`
|
||||
- `packages/db/src/media-foundation.ts`
|
||||
|
||||
## 4. Page Publish
|
||||
|
||||
1. Admin submit on `/pages` calls server action.
|
||||
2. Page schema validates payload and persists.
|
||||
3. `published` status sets publication fields.
|
||||
4. Public app resolves slug and renders page if published.
|
||||
|
||||
Key files:
|
||||
- `apps/admin/src/app/pages/page.tsx`
|
||||
- `packages/db/src/pages-navigation.ts`
|
||||
- `apps/web/src/app/[locale]/[slug]/page.tsx`
|
||||
|
||||
## 5. Commission Status Transition
|
||||
|
||||
1. Admin updates status from commission card form.
|
||||
2. Server action validates transition payload.
|
||||
3. DB update persists new status.
|
||||
4. Kanban view re-renders with updated column placement.
|
||||
|
||||
Key files:
|
||||
- `apps/admin/src/app/commissions/page.tsx`
|
||||
- `packages/db/src/commissions.ts`
|
||||
|
||||
## 6. Public Commission Request Submission
|
||||
|
||||
1. Visitor opens `/{locale}/commissions` and submits request form.
|
||||
2. Server action validates input through shared schema.
|
||||
3. Existing customer is reused by email (and marked recurring) or a new customer is created.
|
||||
4. A new commission is created in `new` status and linked to the resolved customer.
|
||||
|
||||
Key files:
|
||||
- `apps/web/src/app/[locale]/commissions/page.tsx`
|
||||
- `packages/content/src/commissions.ts`
|
||||
- `packages/db/src/commissions.ts`
|
||||
|
||||
## 7. Public Portfolio Rendering
|
||||
|
||||
1. Visitor opens `/{locale}/portfolio` with optional group filter query.
|
||||
2. Public app loads published portfolio groups and filtered published artworks.
|
||||
3. Artwork cards render preferred rendition preview (`card` > `thumbnail` > `full`).
|
||||
4. Image bytes are streamed through web media endpoint using configured storage provider fallback.
|
||||
|
||||
Key files:
|
||||
- `apps/web/src/app/[locale]/portfolio/page.tsx`
|
||||
- `apps/web/src/app/[locale]/portfolio/[slug]/page.tsx`
|
||||
- `apps/web/src/app/api/media/file/[id]/route.ts`
|
||||
- `apps/web/src/lib/media/storage-read.ts`
|
||||
- `packages/db/src/media-foundation.ts`
|
||||
@@ -23,12 +23,18 @@ Follow `BRANCHING.md`:
|
||||
## Changelog
|
||||
|
||||
- Conventional commits required (see `CONTRIBUTING.md`)
|
||||
- Generate changelog with:
|
||||
- Generate changelog with release-focused sections and `Unreleased`:
|
||||
|
||||
```bash
|
||||
bun run changelog:release
|
||||
```
|
||||
|
||||
- For exhaustive output across all allowed commit types:
|
||||
|
||||
```bash
|
||||
bun run changelog:full:preview
|
||||
```
|
||||
|
||||
## Governance
|
||||
|
||||
- Branch and PR governance checks run in `.gitea/workflows/ci.yml`.
|
||||
|
||||
84
e2e/public-rendering.pw.ts
Normal file
84
e2e/public-rendering.pw.ts
Normal file
@@ -0,0 +1,84 @@
|
||||
import { expect, test } from "@playwright/test"
|
||||
|
||||
const E2E_ADMIN_EMAIL = process.env.CMS_E2E_ADMIN_EMAIL ?? "e2e-admin@cms.local"
|
||||
const E2E_ADMIN_PASSWORD = process.env.CMS_E2E_ADMIN_PASSWORD ?? "e2e-admin-password"
|
||||
|
||||
async function ensureE2EAdminSession(page: import("@playwright/test").Page) {
|
||||
const commissionsHeading = page.getByRole("heading", { name: /commissions/i })
|
||||
|
||||
await page.goto("http://127.0.0.1:3001/commissions")
|
||||
if (await commissionsHeading.isVisible({ timeout: 2000 }).catch(() => false)) {
|
||||
return
|
||||
}
|
||||
|
||||
await page.goto("http://127.0.0.1:3001/login")
|
||||
await page.locator("#email").fill(E2E_ADMIN_EMAIL)
|
||||
await page.locator("#password").fill(E2E_ADMIN_PASSWORD)
|
||||
await page.getByRole("button", { name: /sign in/i }).click()
|
||||
await page.goto("http://127.0.0.1:3001/commissions")
|
||||
await expect(commissionsHeading).toBeVisible()
|
||||
}
|
||||
|
||||
test.describe("public rendering integration", () => {
|
||||
test("header exposes portfolio/news/commissions navigation", async ({ page }, testInfo) => {
|
||||
test.skip(testInfo.project.name !== "web-chromium")
|
||||
|
||||
await page.goto("/")
|
||||
|
||||
const header = page.locator("header").first()
|
||||
await expect(header.getByRole("link", { name: /portfolio/i })).toBeVisible()
|
||||
await expect(header.getByRole("link", { name: /news|actualités|noticias/i })).toBeVisible()
|
||||
await expect(header.getByRole("link", { name: /commissions|auftrag/i })).toBeVisible()
|
||||
})
|
||||
|
||||
test("portfolio routes render list and seeded artwork detail", async ({ page }, testInfo) => {
|
||||
test.skip(testInfo.project.name !== "web-chromium")
|
||||
|
||||
await page.goto("/portfolio")
|
||||
await expect(page.getByRole("heading", { name: /portfolio|portafolio/i })).toBeVisible()
|
||||
|
||||
await page.goto("/portfolio/seed-artwork-welcome")
|
||||
await expect(page.getByRole("heading", { name: /seed artwork/i })).toBeVisible()
|
||||
})
|
||||
|
||||
test("commission form rejects invalid budget ranges", async ({ page }, testInfo) => {
|
||||
test.skip(testInfo.project.name !== "web-chromium")
|
||||
|
||||
await page.goto("http://127.0.0.1:3000/commissions")
|
||||
await page.locator('input[name="customerName"]').fill("E2E Client")
|
||||
await page.locator('input[name="customerEmail"]').fill(`e2e-${Date.now()}@example.com`)
|
||||
await page.locator('input[name="title"]').fill("E2E Budget Validation")
|
||||
await page.locator('input[name="budgetMin"]').fill("1000")
|
||||
await page.locator('input[name="budgetMax"]').fill("500")
|
||||
await page.getByRole("button", { name: /submit|senden|envoyer/i }).click()
|
||||
|
||||
await expect(page).toHaveURL(/\/commissions\?error=budget_range_invalid/)
|
||||
})
|
||||
|
||||
test("public commission submission is visible in admin board", async ({ page }, testInfo) => {
|
||||
test.skip(testInfo.project.name !== "admin-chromium")
|
||||
|
||||
const customerName = `E2E Public Customer ${Date.now()}`
|
||||
const commissionTitle = `E2E Public Commission ${Date.now()}`
|
||||
const customerEmail = `public-commission-${Date.now()}@example.com`
|
||||
|
||||
await page.goto("http://127.0.0.1:3000/commissions")
|
||||
await page.locator('input[name="customerName"]').fill(customerName)
|
||||
await page.locator('input[name="customerEmail"]').fill(customerEmail)
|
||||
await page.locator('input[name="title"]').fill(commissionTitle)
|
||||
await page
|
||||
.locator('textarea[name="description"]')
|
||||
.fill("E2E public request -> admin visibility")
|
||||
await page.locator('input[name="budgetMin"]').fill("250")
|
||||
await page.locator('input[name="budgetMax"]').fill("500")
|
||||
await page.getByRole("button", { name: /submit|senden|envoyer/i }).click()
|
||||
|
||||
await expect(page).toHaveURL(/\/commissions\?notice=submitted/)
|
||||
await expect(page.getByText(/submitted|übermittelt|enviada|envoyée/i)).toBeVisible()
|
||||
|
||||
await ensureE2EAdminSession(page)
|
||||
await page.goto("http://127.0.0.1:3001/commissions")
|
||||
await expect(page.getByText(new RegExp(commissionTitle, "i"))).toBeVisible()
|
||||
await expect(page.getByText(new RegExp(customerName, "i"))).toBeVisible()
|
||||
})
|
||||
})
|
||||
20
package.json
20
package.json
@@ -15,16 +15,18 @@
|
||||
"docs:build": "vitepress build docs",
|
||||
"docs:preview": "vitepress preview docs --port 4173",
|
||||
"build": "turbo build",
|
||||
"test": "vitest run",
|
||||
"test:watch": "vitest",
|
||||
"test:coverage": "vitest run --coverage",
|
||||
"test:e2e:prepare": "bun run db:generate && bun run db:migrate:deploy && bun run db:seed",
|
||||
"test:e2e": "bun run test:e2e:prepare && playwright test",
|
||||
"test:e2e:headed": "bun run test:e2e:prepare && playwright test --headed",
|
||||
"test:e2e:ui": "bun run test:e2e:prepare && playwright test --ui",
|
||||
"test": "echo \"Testing is temporarily disabled. See TODO.md MVP 3: Testing and Quality.\"",
|
||||
"test:watch": "echo \"Testing is temporarily disabled. See TODO.md MVP 3: Testing and Quality.\"",
|
||||
"test:coverage": "echo \"Testing is temporarily disabled. See TODO.md MVP 3: Testing and Quality.\"",
|
||||
"test:e2e:prepare": "echo \"E2E preparation is temporarily disabled. See TODO.md MVP 3: Testing and Quality.\"",
|
||||
"test:e2e": "echo \"E2E testing is temporarily disabled. See TODO.md MVP 3: Testing and Quality.\"",
|
||||
"test:e2e:headed": "echo \"E2E testing is temporarily disabled. See TODO.md MVP 3: Testing and Quality.\"",
|
||||
"test:e2e:ui": "echo \"E2E testing is temporarily disabled. See TODO.md MVP 3: Testing and Quality.\"",
|
||||
"commitlint": "commitlint --last",
|
||||
"changelog:preview": "conventional-changelog -p conventionalcommits -r 0",
|
||||
"changelog:release": "conventional-changelog -p conventionalcommits -i CHANGELOG.md -s",
|
||||
"changelog:preview": "conventional-changelog -p conventionalcommits -r 0 -u",
|
||||
"changelog:release": "conventional-changelog -p conventionalcommits -i CHANGELOG.md -s -u",
|
||||
"changelog:full:preview": "conventional-changelog -n ./conventional-changelog.config.cjs -r 0 -u",
|
||||
"changelog:full:release": "conventional-changelog -n ./conventional-changelog.config.cjs -i CHANGELOG.md -s -u",
|
||||
"lint": "turbo lint",
|
||||
"typecheck": "turbo typecheck",
|
||||
"format": "biome format --write .",
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import { z } from "zod"
|
||||
|
||||
export const announcementPlacementSchema = z.enum(["global_top", "homepage"])
|
||||
export const announcementLocaleSchema = z.enum(["de", "en", "es", "fr"])
|
||||
|
||||
export const createAnnouncementInputSchema = z.object({
|
||||
title: z.string().min(1).max(180),
|
||||
message: z.string().min(1).max(500),
|
||||
placement: announcementPlacementSchema.default("global_top"),
|
||||
targetLocales: z.array(announcementLocaleSchema).default([]),
|
||||
priority: z.number().int().min(0).default(100),
|
||||
ctaLabel: z.string().max(120).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(),
|
||||
message: z.string().min(1).max(500).optional(),
|
||||
placement: announcementPlacementSchema.optional(),
|
||||
targetLocales: z.array(announcementLocaleSchema).optional(),
|
||||
priority: z.number().int().min(0).optional(),
|
||||
ctaLabel: z.string().max(120).nullable().optional(),
|
||||
ctaHref: z.string().max(500).nullable().optional(),
|
||||
|
||||
@@ -23,12 +23,46 @@ export const createCommissionInputSchema = z.object({
|
||||
description: z.string().max(4000).nullable().optional(),
|
||||
status: commissionStatusSchema.default("new"),
|
||||
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(),
|
||||
budgetMax: z.number().nonnegative().nullable().optional(),
|
||||
dueAt: z.date().nullable().optional(),
|
||||
})
|
||||
|
||||
export const createPublicCommissionRequestInputSchema = z
|
||||
.object({
|
||||
customerName: z.string().min(1).max(180),
|
||||
customerEmail: z.string().email().max(320),
|
||||
customerPhone: z.string().max(80).nullable().optional(),
|
||||
customerInstagram: z.string().max(120).nullable().optional(),
|
||||
title: z.string().min(1).max(180),
|
||||
description: z.string().max(4000).nullable().optional(),
|
||||
budgetMin: z.number().nonnegative().nullable().optional(),
|
||||
budgetMax: z.number().nonnegative().nullable().optional(),
|
||||
})
|
||||
.refine(
|
||||
(value) =>
|
||||
value.budgetMin == null || value.budgetMax == null || value.budgetMax >= value.budgetMin,
|
||||
{
|
||||
message: "budgetMax must be greater than or equal to budgetMin.",
|
||||
path: ["budgetMax"],
|
||||
},
|
||||
)
|
||||
|
||||
export const updateCommissionStatusInputSchema = z.object({
|
||||
id: z.string().uuid(),
|
||||
status: commissionStatusSchema,
|
||||
@@ -37,4 +71,8 @@ export const updateCommissionStatusInputSchema = z.object({
|
||||
export type CommissionStatus = z.infer<typeof commissionStatusSchema>
|
||||
export type CreateCustomerInput = z.infer<typeof createCustomerInputSchema>
|
||||
export type CreateCommissionInput = z.infer<typeof createCommissionInputSchema>
|
||||
export type UpdateCommissionInput = z.infer<typeof updateCommissionInputSchema>
|
||||
export type CreatePublicCommissionRequestInput = z.infer<
|
||||
typeof createPublicCommissionRequestInputSchema
|
||||
>
|
||||
export type UpdateCommissionStatusInput = z.infer<typeof updateCommissionStatusInputSchema>
|
||||
|
||||
@@ -6,6 +6,8 @@ import {
|
||||
createCustomerInputSchema,
|
||||
createNavigationMenuInputSchema,
|
||||
createPageInputSchema,
|
||||
parsePageBlocks,
|
||||
serializePageBlocks,
|
||||
updateCommissionStatusInputSchema,
|
||||
updateNavigationItemInputSchema,
|
||||
} from "./index"
|
||||
@@ -64,4 +66,23 @@ describe("domain schemas", () => {
|
||||
expect(menu.success).toBe(true)
|
||||
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({
|
||||
type: "artwork",
|
||||
title: "Artwork",
|
||||
licenseType: "CC BY",
|
||||
usageContext: "homepage hero",
|
||||
capturedAt: new Date("2026-01-02T10:30:00.000Z"),
|
||||
tags: ["tag-a"],
|
||||
})
|
||||
|
||||
expect(parsed.type).toBe("artwork")
|
||||
expect(parsed.licenseType).toBe("CC BY")
|
||||
expect(parsed.tags).toEqual(["tag-a"])
|
||||
})
|
||||
|
||||
|
||||
@@ -9,7 +9,57 @@ export const mediaAssetTypeSchema = z.enum([
|
||||
"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({
|
||||
id: z.string().uuid().optional(),
|
||||
@@ -20,6 +70,11 @@ export const createMediaAssetInputSchema = z.object({
|
||||
source: z.string().max(500).optional(),
|
||||
copyright: z.string().max(500).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([]),
|
||||
storageKey: z.string().max(500).optional(),
|
||||
mimeType: z.string().max(180).optional(),
|
||||
@@ -38,6 +93,11 @@ export const updateMediaAssetInputSchema = z.object({
|
||||
source: z.string().max(500).nullable().optional(),
|
||||
copyright: z.string().max(500).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(),
|
||||
mimeType: z.string().max(180).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(),
|
||||
framing: 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({
|
||||
@@ -65,6 +144,21 @@ export const createGroupingInputSchema = z.object({
|
||||
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({
|
||||
artworkId: z.string().uuid(),
|
||||
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 UpdateMediaAssetInput = z.infer<typeof updateMediaAssetInputSchema>
|
||||
export type CreateArtworkInput = z.infer<typeof createArtworkInputSchema>
|
||||
export type UpdateArtworkInput = z.infer<typeof updateArtworkInputSchema>
|
||||
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 AttachArtworkRenditionInput = z.infer<typeof attachArtworkRenditionInputSchema>
|
||||
|
||||
@@ -1,6 +1,99 @@
|
||||
import { z } from "zod"
|
||||
|
||||
export const pageStatusSchema = z.enum(["draft", "published"])
|
||||
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({
|
||||
title: z.string().min(1).max(180),
|
||||
@@ -23,6 +116,16 @@ export const updatePageInputSchema = z.object({
|
||||
seoDescription: z.string().max(320).nullable().optional(),
|
||||
})
|
||||
|
||||
export const upsertPageTranslationInputSchema = z.object({
|
||||
pageId: z.string().uuid(),
|
||||
locale: pageLocaleSchema,
|
||||
title: z.string().min(1).max(180),
|
||||
summary: z.string().max(500).nullable().optional(),
|
||||
content: z.string().min(1),
|
||||
seoTitle: z.string().max(180).nullable().optional(),
|
||||
seoDescription: z.string().max(320).nullable().optional(),
|
||||
})
|
||||
|
||||
export const createNavigationMenuInputSchema = z.object({
|
||||
name: z.string().min(1).max(180),
|
||||
slug: z.string().min(1).max(180),
|
||||
@@ -30,6 +133,14 @@ export const createNavigationMenuInputSchema = z.object({
|
||||
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({
|
||||
menuId: z.string().uuid(),
|
||||
label: z.string().min(1).max(180),
|
||||
@@ -52,6 +163,10 @@ export const updateNavigationItemInputSchema = z.object({
|
||||
|
||||
export type CreatePageInput = z.infer<typeof createPageInputSchema>
|
||||
export type UpdatePageInput = z.infer<typeof updatePageInputSchema>
|
||||
export type UpsertPageTranslationInput = z.infer<typeof upsertPageTranslationInputSchema>
|
||||
export type CreateNavigationMenuInput = z.infer<typeof createNavigationMenuInputSchema>
|
||||
export type UpdateNavigationMenuInput = z.infer<typeof updateNavigationMenuInputSchema>
|
||||
export type CreateNavigationItemInput = z.infer<typeof createNavigationItemInputSchema>
|
||||
export type UpdateNavigationItemInput = z.infer<typeof updateNavigationItemInputSchema>
|
||||
export type PageBlock = z.infer<typeof pageBlockSchema>
|
||||
export type PageBlocks = z.infer<typeof pageBlocksSchema>
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "PageTranslation" (
|
||||
"id" TEXT NOT NULL,
|
||||
"pageId" TEXT NOT NULL,
|
||||
"locale" TEXT NOT NULL,
|
||||
"title" TEXT NOT NULL,
|
||||
"summary" TEXT,
|
||||
"content" TEXT NOT NULL,
|
||||
"seoTitle" TEXT,
|
||||
"seoDescription" TEXT,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "PageTranslation_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "PageTranslation_locale_idx" ON "PageTranslation"("locale");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "PageTranslation_pageId_locale_key" ON "PageTranslation"("pageId", "locale");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "PageTranslation" ADD CONSTRAINT "PageTranslation_pageId_fkey" FOREIGN KEY ("pageId") REFERENCES "Page"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -0,0 +1,43 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "PostTranslation" (
|
||||
"id" TEXT NOT NULL,
|
||||
"postId" TEXT NOT NULL,
|
||||
"locale" TEXT NOT NULL,
|
||||
"title" TEXT NOT NULL,
|
||||
"excerpt" TEXT,
|
||||
"body" TEXT NOT NULL,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "PostTranslation_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "NavigationItemTranslation" (
|
||||
"id" TEXT NOT NULL,
|
||||
"navigationItemId" TEXT NOT NULL,
|
||||
"locale" TEXT NOT NULL,
|
||||
"label" TEXT NOT NULL,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "NavigationItemTranslation_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "PostTranslation_locale_idx" ON "PostTranslation"("locale");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "PostTranslation_postId_locale_key" ON "PostTranslation"("postId", "locale");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "NavigationItemTranslation_locale_idx" ON "NavigationItemTranslation"("locale");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "NavigationItemTranslation_navigationItemId_locale_key" ON "NavigationItemTranslation"("navigationItemId", "locale");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "PostTranslation" ADD CONSTRAINT "PostTranslation_postId_fkey" FOREIGN KEY ("postId") REFERENCES "Post"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "NavigationItemTranslation" ADD CONSTRAINT "NavigationItemTranslation_navigationItemId_fkey" FOREIGN KEY ("navigationItemId") REFERENCES "NavigationItem"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -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[];
|
||||
@@ -16,6 +16,22 @@ model Post {
|
||||
status String
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
translations PostTranslation[]
|
||||
}
|
||||
|
||||
model PostTranslation {
|
||||
id String @id @default(uuid())
|
||||
postId String
|
||||
locale String
|
||||
title String
|
||||
excerpt String?
|
||||
body String
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
post Post @relation(fields: [postId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@unique([postId, locale])
|
||||
@@index([locale])
|
||||
}
|
||||
|
||||
model User {
|
||||
@@ -107,6 +123,11 @@ model MediaAsset {
|
||||
source String?
|
||||
copyright String?
|
||||
author String?
|
||||
licenseType String?
|
||||
licenseUrl String?
|
||||
usageContext String?
|
||||
location String?
|
||||
capturedAt DateTime?
|
||||
tags String[]
|
||||
storageKey String? @unique
|
||||
mimeType String?
|
||||
@@ -132,6 +153,9 @@ model Artwork {
|
||||
year Int?
|
||||
framing String?
|
||||
availability String?
|
||||
priceAmountCents Int?
|
||||
priceCurrency String?
|
||||
isPriceVisible Boolean @default(false)
|
||||
isPublished Boolean @default(false)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
@@ -201,6 +225,9 @@ model Tag {
|
||||
id String @id @default(uuid())
|
||||
name String
|
||||
slug String @unique
|
||||
description String?
|
||||
sortOrder Int @default(0)
|
||||
isVisible Boolean @default(true)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
artworkLinks ArtworkTag[]
|
||||
@@ -267,10 +294,28 @@ model Page {
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
navItems NavigationItem[]
|
||||
translations PageTranslation[]
|
||||
|
||||
@@index([status])
|
||||
}
|
||||
|
||||
model PageTranslation {
|
||||
id String @id @default(uuid())
|
||||
pageId String
|
||||
locale String
|
||||
title String
|
||||
summary String?
|
||||
content String
|
||||
seoTitle String?
|
||||
seoDescription String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
page Page @relation(fields: [pageId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@unique([pageId, locale])
|
||||
@@index([locale])
|
||||
}
|
||||
|
||||
model NavigationMenu {
|
||||
id String @id @default(uuid())
|
||||
name String
|
||||
@@ -297,6 +342,7 @@ model NavigationItem {
|
||||
page Page? @relation(fields: [pageId], references: [id], onDelete: SetNull)
|
||||
parent NavigationItem? @relation("NavigationItemParent", fields: [parentId], references: [id], onDelete: Cascade)
|
||||
children NavigationItem[] @relation("NavigationItemParent")
|
||||
translations NavigationItemTranslation[]
|
||||
|
||||
@@index([menuId])
|
||||
@@index([pageId])
|
||||
@@ -304,6 +350,19 @@ model NavigationItem {
|
||||
@@unique([menuId, parentId, sortOrder, label])
|
||||
}
|
||||
|
||||
model NavigationItemTranslation {
|
||||
id String @id @default(uuid())
|
||||
navigationItemId String
|
||||
locale String
|
||||
label String
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
navigationItem NavigationItem @relation(fields: [navigationItemId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@unique([navigationItemId, locale])
|
||||
@@index([locale])
|
||||
}
|
||||
|
||||
model Customer {
|
||||
id String @id @default(uuid())
|
||||
name String
|
||||
@@ -327,6 +386,7 @@ model Commission {
|
||||
status String
|
||||
customerId String?
|
||||
assignedUserId String?
|
||||
linkedArtworkIds String[] @default([])
|
||||
budgetMin Float?
|
||||
budgetMax Float?
|
||||
dueAt DateTime?
|
||||
@@ -345,6 +405,7 @@ model Announcement {
|
||||
title String
|
||||
message String
|
||||
placement String
|
||||
targetLocales String[] @default([])
|
||||
priority Int @default(100)
|
||||
ctaLabel String?
|
||||
ctaHref String?
|
||||
|
||||
@@ -159,6 +159,67 @@ async function main() {
|
||||
})
|
||||
}
|
||||
|
||||
const defaultHeaderItems = [
|
||||
{
|
||||
label: "Portfolio",
|
||||
href: "/portfolio",
|
||||
sortOrder: 1,
|
||||
pageId: null,
|
||||
},
|
||||
{
|
||||
label: "News",
|
||||
href: "/news",
|
||||
sortOrder: 2,
|
||||
pageId: null,
|
||||
},
|
||||
{
|
||||
label: "Commissions",
|
||||
href: "/commissions",
|
||||
sortOrder: 3,
|
||||
pageId: null,
|
||||
},
|
||||
] as const
|
||||
|
||||
for (const item of defaultHeaderItems) {
|
||||
const existingItem = await db.navigationItem.findFirst({
|
||||
where: {
|
||||
menuId: primaryMenu.id,
|
||||
parentId: null,
|
||||
href: item.href,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
})
|
||||
|
||||
if (existingItem) {
|
||||
await db.navigationItem.update({
|
||||
where: {
|
||||
id: existingItem.id,
|
||||
},
|
||||
data: {
|
||||
label: item.label,
|
||||
sortOrder: item.sortOrder,
|
||||
isVisible: true,
|
||||
pageId: item.pageId,
|
||||
},
|
||||
})
|
||||
continue
|
||||
}
|
||||
|
||||
await db.navigationItem.create({
|
||||
data: {
|
||||
menuId: primaryMenu.id,
|
||||
label: item.label,
|
||||
href: item.href,
|
||||
pageId: item.pageId,
|
||||
parentId: null,
|
||||
sortOrder: item.sortOrder,
|
||||
isVisible: true,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
const existingCustomer = await db.customer.findFirst({
|
||||
where: {
|
||||
email: "collector@example.com",
|
||||
|
||||
@@ -41,13 +41,18 @@ describe("announcements service", () => {
|
||||
it("queries only visible announcements in the given placement", async () => {
|
||||
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.mock.calls[0]?.[0]).toMatchObject({
|
||||
where: {
|
||||
placement: "homepage",
|
||||
isVisible: true,
|
||||
AND: [
|
||||
{
|
||||
OR: [{ targetLocales: { isEmpty: true } }, { targetLocales: { has: "en" } }],
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
@@ -13,6 +13,7 @@ export type PublicAnnouncement = {
|
||||
ctaLabel: string | null
|
||||
ctaHref: string | null
|
||||
placement: string
|
||||
targetLocales: string[]
|
||||
priority: number
|
||||
}
|
||||
|
||||
@@ -50,13 +51,26 @@ export async function deleteAnnouncement(id: string) {
|
||||
export async function listActiveAnnouncements(
|
||||
placement: AnnouncementPlacement,
|
||||
now = new Date(),
|
||||
locale?: string,
|
||||
): Promise<PublicAnnouncement[]> {
|
||||
const localeFilter =
|
||||
locale && locale.length > 0
|
||||
? {
|
||||
AND: [
|
||||
{
|
||||
OR: [{ targetLocales: { isEmpty: true } }, { targetLocales: { has: locale } }],
|
||||
},
|
||||
],
|
||||
}
|
||||
: undefined
|
||||
|
||||
const announcements = await db.announcement.findMany({
|
||||
where: {
|
||||
placement,
|
||||
isVisible: true,
|
||||
OR: [{ startsAt: null }, { startsAt: { lte: now } }],
|
||||
AND: [{ OR: [{ endsAt: null }, { endsAt: { gte: now } }] }],
|
||||
...(localeFilter ?? {}),
|
||||
},
|
||||
orderBy: [{ priority: "asc" }, { createdAt: "desc" }],
|
||||
select: {
|
||||
@@ -66,6 +80,7 @@ export async function listActiveAnnouncements(
|
||||
ctaLabel: true,
|
||||
ctaHref: true,
|
||||
placement: true,
|
||||
targetLocales: true,
|
||||
priority: true,
|
||||
},
|
||||
})
|
||||
|
||||
@@ -2,9 +2,12 @@ import { beforeEach, describe, expect, it, vi } from "vitest"
|
||||
|
||||
const { mockDb } = vi.hoisted(() => ({
|
||||
mockDb: {
|
||||
$transaction: vi.fn(),
|
||||
customer: {
|
||||
create: vi.fn(),
|
||||
findFirst: vi.fn(),
|
||||
findMany: vi.fn(),
|
||||
update: vi.fn(),
|
||||
},
|
||||
commission: {
|
||||
create: vi.fn(),
|
||||
@@ -18,17 +21,29 @@ vi.mock("./client", () => ({
|
||||
db: mockDb,
|
||||
}))
|
||||
|
||||
import { createCommission, createCustomer, updateCommissionStatus } from "./commissions"
|
||||
import {
|
||||
createCommission,
|
||||
createCustomer,
|
||||
createPublicCommissionRequest,
|
||||
updateCommissionStatus,
|
||||
} from "./commissions"
|
||||
|
||||
describe("commissions service", () => {
|
||||
beforeEach(() => {
|
||||
for (const value of Object.values(mockDb)) {
|
||||
if (typeof value === "function") {
|
||||
value.mockReset()
|
||||
continue
|
||||
}
|
||||
|
||||
for (const fn of Object.values(value)) {
|
||||
if (typeof fn === "function") {
|
||||
fn.mockReset()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mockDb.$transaction.mockImplementation(async (callback) => callback(mockDb))
|
||||
})
|
||||
|
||||
it("creates customer and commission payloads", async () => {
|
||||
@@ -51,6 +66,37 @@ describe("commissions service", () => {
|
||||
expect(mockDb.commission.create).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it("creates a public commission request with customer upsert behavior", async () => {
|
||||
mockDb.customer.findFirst.mockResolvedValue({
|
||||
id: "customer-existing",
|
||||
phone: null,
|
||||
instagram: null,
|
||||
})
|
||||
mockDb.customer.update.mockResolvedValue({
|
||||
id: "customer-existing",
|
||||
})
|
||||
mockDb.commission.create.mockResolvedValue({
|
||||
id: "commission-2",
|
||||
})
|
||||
|
||||
await createPublicCommissionRequest({
|
||||
customerName: "Grace Hopper",
|
||||
customerEmail: "GRACE@EXAMPLE.COM",
|
||||
customerPhone: "12345",
|
||||
title: "Landscape commission",
|
||||
description: "Oil painting request",
|
||||
budgetMin: 500,
|
||||
budgetMax: 900,
|
||||
})
|
||||
|
||||
expect(mockDb.customer.findFirst).toHaveBeenCalledWith({
|
||||
where: { email: "grace@example.com" },
|
||||
orderBy: { updatedAt: "desc" },
|
||||
})
|
||||
expect(mockDb.customer.update).toHaveBeenCalledTimes(1)
|
||||
expect(mockDb.commission.create).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it("updates commission status", async () => {
|
||||
mockDb.commission.update.mockResolvedValue({ id: "commission-1", status: "done" })
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ import {
|
||||
commissionStatusSchema,
|
||||
createCommissionInputSchema,
|
||||
createCustomerInputSchema,
|
||||
createPublicCommissionRequestInputSchema,
|
||||
updateCommissionInputSchema,
|
||||
updateCommissionStatusInputSchema,
|
||||
} from "@cms/content"
|
||||
|
||||
@@ -56,6 +58,73 @@ 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) {
|
||||
const payload = createPublicCommissionRequestInputSchema.parse(input)
|
||||
const normalizedEmail = payload.customerEmail.trim().toLowerCase()
|
||||
|
||||
return db.$transaction(async (tx) => {
|
||||
const existingCustomer = await tx.customer.findFirst({
|
||||
where: {
|
||||
email: normalizedEmail,
|
||||
},
|
||||
orderBy: {
|
||||
updatedAt: "desc",
|
||||
},
|
||||
})
|
||||
|
||||
const customer = existingCustomer
|
||||
? await tx.customer.update({
|
||||
where: { id: existingCustomer.id },
|
||||
data: {
|
||||
name: payload.customerName,
|
||||
phone: payload.customerPhone ?? existingCustomer.phone,
|
||||
instagram: payload.customerInstagram ?? existingCustomer.instagram,
|
||||
isRecurring: true,
|
||||
},
|
||||
})
|
||||
: await tx.customer.create({
|
||||
data: {
|
||||
name: payload.customerName,
|
||||
email: normalizedEmail,
|
||||
phone: payload.customerPhone,
|
||||
instagram: payload.customerInstagram,
|
||||
isRecurring: false,
|
||||
},
|
||||
})
|
||||
|
||||
return tx.commission.create({
|
||||
data: {
|
||||
title: payload.title,
|
||||
description: payload.description,
|
||||
status: "new",
|
||||
customerId: customer.id,
|
||||
budgetMin: payload.budgetMin,
|
||||
budgetMax: payload.budgetMax,
|
||||
},
|
||||
include: {
|
||||
customer: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
email: true,
|
||||
isRecurring: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export async function updateCommissionStatus(input: unknown) {
|
||||
const payload = updateCommissionStatusInputSchema.parse(input)
|
||||
|
||||
|
||||
@@ -11,8 +11,10 @@ export {
|
||||
commissionKanbanOrder,
|
||||
createCommission,
|
||||
createCustomer,
|
||||
createPublicCommissionRequest,
|
||||
listCommissions,
|
||||
listCustomers,
|
||||
updateCommission,
|
||||
updateCommissionStatus,
|
||||
} from "./commissions"
|
||||
export {
|
||||
@@ -23,13 +25,20 @@ export {
|
||||
createGallery,
|
||||
createMediaAsset,
|
||||
createTag,
|
||||
deleteArtworkRendition,
|
||||
deleteGrouping,
|
||||
deleteMediaAsset,
|
||||
getMediaAssetById,
|
||||
getMediaFoundationSummary,
|
||||
getPublishedArtworkBySlug,
|
||||
linkArtworkToGrouping,
|
||||
listArtworks,
|
||||
listMediaAssets,
|
||||
listMediaFoundationGroups,
|
||||
listPublishedArtworks,
|
||||
listPublishedPortfolioGroups,
|
||||
updateArtwork,
|
||||
updateGrouping,
|
||||
updateMediaAsset,
|
||||
} from "./media-foundation"
|
||||
export type { PublicNavigationItem } from "./pages-navigation"
|
||||
@@ -38,24 +47,34 @@ export {
|
||||
createNavigationMenu,
|
||||
createPage,
|
||||
deleteNavigationItem,
|
||||
deleteNavigationMenu,
|
||||
deletePage,
|
||||
getPageById,
|
||||
getPublishedPageBySlug,
|
||||
getPublishedPageBySlugForLocale,
|
||||
listNavigationMenus,
|
||||
listPages,
|
||||
listPageTranslations,
|
||||
listPublicNavigation,
|
||||
listPublishedPageSlugs,
|
||||
updateNavigationItem,
|
||||
updateNavigationMenu,
|
||||
updatePage,
|
||||
upsertNavigationItemTranslation,
|
||||
upsertPageTranslation,
|
||||
} from "./pages-navigation"
|
||||
export {
|
||||
createPost,
|
||||
deletePost,
|
||||
getPostById,
|
||||
getPostBySlug,
|
||||
getPostBySlugForLocale,
|
||||
listPosts,
|
||||
listPostsForLocale,
|
||||
listPostsWithTranslations,
|
||||
registerPostCrudAuditHook,
|
||||
updatePost,
|
||||
upsertPostTranslation,
|
||||
} from "./posts"
|
||||
export type { PublicHeaderBanner, PublicHeaderBannerConfig } from "./settings"
|
||||
export {
|
||||
|
||||
@@ -8,11 +8,11 @@ const { mockDb } = vi.hoisted(() => ({
|
||||
artworkTag: { upsert: vi.fn() },
|
||||
artworkRendition: { upsert: vi.fn() },
|
||||
mediaAsset: { create: vi.fn(), findUnique: vi.fn(), update: vi.fn(), delete: vi.fn() },
|
||||
artwork: { create: vi.fn() },
|
||||
gallery: { create: vi.fn() },
|
||||
album: { create: vi.fn() },
|
||||
category: { create: vi.fn() },
|
||||
tag: { create: vi.fn() },
|
||||
artwork: { create: vi.fn(), findMany: vi.fn(), findFirst: vi.fn() },
|
||||
gallery: { create: vi.fn(), findMany: vi.fn() },
|
||||
album: { create: vi.fn(), findMany: vi.fn() },
|
||||
category: { create: vi.fn(), findMany: vi.fn() },
|
||||
tag: { create: vi.fn(), findMany: vi.fn() },
|
||||
},
|
||||
}))
|
||||
|
||||
@@ -26,7 +26,10 @@ import {
|
||||
createMediaAsset,
|
||||
deleteMediaAsset,
|
||||
getMediaAssetById,
|
||||
getPublishedArtworkBySlug,
|
||||
linkArtworkToGrouping,
|
||||
listPublishedArtworks,
|
||||
listPublishedPortfolioGroups,
|
||||
updateMediaAsset,
|
||||
} from "./media-foundation"
|
||||
|
||||
@@ -42,6 +45,12 @@ describe("media foundation service", () => {
|
||||
if ("findUnique" in value) {
|
||||
value.findUnique.mockReset()
|
||||
}
|
||||
if ("findMany" in value) {
|
||||
value.findMany.mockReset()
|
||||
}
|
||||
if ("findFirst" in value) {
|
||||
value.findFirst.mockReset()
|
||||
}
|
||||
if ("update" in value) {
|
||||
value.update.mockReset()
|
||||
}
|
||||
@@ -120,4 +129,58 @@ describe("media foundation service", () => {
|
||||
expect(mockDb.mediaAsset.update).toHaveBeenCalledTimes(1)
|
||||
expect(mockDb.mediaAsset.delete).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it("lists published artworks with group filters", async () => {
|
||||
mockDb.artwork.findMany.mockResolvedValue([])
|
||||
|
||||
await listPublishedArtworks({
|
||||
groupType: "gallery",
|
||||
groupSlug: "showcase",
|
||||
})
|
||||
|
||||
expect(mockDb.artwork.findMany).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
where: expect.objectContaining({
|
||||
isPublished: true,
|
||||
galleryLinks: {
|
||||
some: {
|
||||
gallery: {
|
||||
slug: "showcase",
|
||||
isVisible: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
it("lists published portfolio groups", async () => {
|
||||
mockDb.gallery.findMany.mockResolvedValue([])
|
||||
mockDb.album.findMany.mockResolvedValue([])
|
||||
mockDb.category.findMany.mockResolvedValue([])
|
||||
mockDb.tag.findMany.mockResolvedValue([])
|
||||
|
||||
await listPublishedPortfolioGroups()
|
||||
|
||||
expect(mockDb.gallery.findMany).toHaveBeenCalledTimes(1)
|
||||
expect(mockDb.album.findMany).toHaveBeenCalledTimes(1)
|
||||
expect(mockDb.category.findMany).toHaveBeenCalledTimes(1)
|
||||
expect(mockDb.tag.findMany).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it("loads a published artwork by slug", async () => {
|
||||
mockDb.artwork.findFirst.mockResolvedValue(null)
|
||||
|
||||
await getPublishedArtworkBySlug("artwork-slug")
|
||||
|
||||
expect(mockDb.artwork.findFirst).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
where: {
|
||||
slug: "artwork-slug",
|
||||
isPublished: true,
|
||||
},
|
||||
}),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -3,12 +3,26 @@ import {
|
||||
createArtworkInputSchema,
|
||||
createGroupingInputSchema,
|
||||
createMediaAssetInputSchema,
|
||||
deleteGroupingInputSchema,
|
||||
linkArtworkGroupingInputSchema,
|
||||
updateArtworkInputSchema,
|
||||
updateGroupingInputSchema,
|
||||
updateMediaAssetInputSchema,
|
||||
} from "@cms/content"
|
||||
import type { Prisma } from "@prisma/client"
|
||||
|
||||
import { db } from "./client"
|
||||
|
||||
type PublicArtworkGroupType = "gallery" | "album" | "category" | "tag"
|
||||
type PublicArtworkSort = "latest" | "title_asc" | "title_desc"
|
||||
|
||||
type ListPublishedArtworksInput = {
|
||||
groupType?: PublicArtworkGroupType
|
||||
groupSlug?: string
|
||||
limit?: number
|
||||
sort?: PublicArtworkSort
|
||||
}
|
||||
|
||||
export async function listMediaAssets(limit = 24) {
|
||||
return db.mediaAsset.findMany({
|
||||
orderBy: { updatedAt: "desc" },
|
||||
@@ -22,10 +36,14 @@ export async function listArtworks(limit = 24) {
|
||||
take: limit,
|
||||
include: {
|
||||
renditions: {
|
||||
orderBy: [{ isPrimary: "desc" }, { updatedAt: "desc" }],
|
||||
select: {
|
||||
id: true,
|
||||
slot: true,
|
||||
mediaAssetId: true,
|
||||
width: true,
|
||||
height: true,
|
||||
isPrimary: true,
|
||||
},
|
||||
},
|
||||
galleryLinks: {
|
||||
@@ -88,7 +106,7 @@ export async function listMediaFoundationGroups() {
|
||||
orderBy: [{ sortOrder: "asc" }, { name: "asc" }],
|
||||
}),
|
||||
db.tag.findMany({
|
||||
orderBy: { name: "asc" },
|
||||
orderBy: [{ sortOrder: "asc" }, { name: "asc" }],
|
||||
}),
|
||||
])
|
||||
|
||||
@@ -138,6 +156,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) {
|
||||
const payload = createGroupingInputSchema.parse(input)
|
||||
|
||||
@@ -163,18 +191,76 @@ export async function createCategory(input: unknown) {
|
||||
}
|
||||
|
||||
export async function createTag(input: unknown) {
|
||||
const payload = createGroupingInputSchema
|
||||
.pick({
|
||||
name: true,
|
||||
slug: true,
|
||||
})
|
||||
.parse(input)
|
||||
const payload = createGroupingInputSchema.parse(input)
|
||||
|
||||
return db.tag.create({
|
||||
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) {
|
||||
const payload = linkArtworkGroupingInputSchema.parse(input)
|
||||
|
||||
@@ -261,6 +347,12 @@ export async function attachArtworkRendition(input: unknown) {
|
||||
})
|
||||
}
|
||||
|
||||
export async function deleteArtworkRendition(id: string) {
|
||||
return db.artworkRendition.delete({
|
||||
where: { id },
|
||||
})
|
||||
}
|
||||
|
||||
export async function getMediaFoundationSummary() {
|
||||
const [mediaAssets, artworks, galleries, albums, categories, tags] = await Promise.all([
|
||||
db.mediaAsset.count(),
|
||||
@@ -280,3 +372,268 @@ export async function getMediaFoundationSummary() {
|
||||
tags,
|
||||
}
|
||||
}
|
||||
|
||||
export async function listPublishedPortfolioGroups() {
|
||||
const [galleries, albums, categories, tags] = await Promise.all([
|
||||
db.gallery.findMany({
|
||||
where: {
|
||||
isVisible: true,
|
||||
},
|
||||
orderBy: [{ sortOrder: "asc" }, { name: "asc" }],
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
slug: true,
|
||||
},
|
||||
}),
|
||||
db.album.findMany({
|
||||
where: {
|
||||
isVisible: true,
|
||||
},
|
||||
orderBy: [{ sortOrder: "asc" }, { name: "asc" }],
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
slug: true,
|
||||
},
|
||||
}),
|
||||
db.category.findMany({
|
||||
where: {
|
||||
isVisible: true,
|
||||
},
|
||||
orderBy: [{ sortOrder: "asc" }, { name: "asc" }],
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
slug: true,
|
||||
},
|
||||
}),
|
||||
db.tag.findMany({
|
||||
where: {
|
||||
isVisible: true,
|
||||
},
|
||||
orderBy: [{ sortOrder: "asc" }, { name: "asc" }],
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
slug: true,
|
||||
},
|
||||
}),
|
||||
])
|
||||
|
||||
return {
|
||||
galleries,
|
||||
albums,
|
||||
categories,
|
||||
tags,
|
||||
}
|
||||
}
|
||||
|
||||
export async function listPublishedArtworks(input: ListPublishedArtworksInput = {}) {
|
||||
const take = input.limit ?? 36
|
||||
const where: Record<string, unknown> = {
|
||||
isPublished: true,
|
||||
}
|
||||
const orderBy: Prisma.ArtworkOrderByWithRelationInput[] =
|
||||
input.sort === "title_asc"
|
||||
? [{ title: "asc" }, { updatedAt: "desc" }]
|
||||
: input.sort === "title_desc"
|
||||
? [{ title: "desc" }, { updatedAt: "desc" }]
|
||||
: [{ updatedAt: "desc" }]
|
||||
|
||||
if (input.groupType && input.groupSlug) {
|
||||
if (input.groupType === "gallery") {
|
||||
where.galleryLinks = {
|
||||
some: {
|
||||
gallery: {
|
||||
slug: input.groupSlug,
|
||||
isVisible: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
} else if (input.groupType === "album") {
|
||||
where.albumLinks = {
|
||||
some: {
|
||||
album: {
|
||||
slug: input.groupSlug,
|
||||
isVisible: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
} else if (input.groupType === "category") {
|
||||
where.categoryLinks = {
|
||||
some: {
|
||||
category: {
|
||||
slug: input.groupSlug,
|
||||
isVisible: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
} else if (input.groupType === "tag") {
|
||||
where.tagLinks = {
|
||||
some: {
|
||||
tag: {
|
||||
slug: input.groupSlug,
|
||||
isVisible: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return db.artwork.findMany({
|
||||
where,
|
||||
orderBy,
|
||||
take,
|
||||
include: {
|
||||
renditions: {
|
||||
where: {
|
||||
mediaAsset: {
|
||||
isPublished: true,
|
||||
},
|
||||
},
|
||||
orderBy: [{ isPrimary: "desc" }, { updatedAt: "desc" }],
|
||||
include: {
|
||||
mediaAsset: {
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
altText: true,
|
||||
mimeType: true,
|
||||
width: true,
|
||||
height: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
galleryLinks: {
|
||||
include: {
|
||||
gallery: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
slug: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
albumLinks: {
|
||||
include: {
|
||||
album: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
slug: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
categoryLinks: {
|
||||
include: {
|
||||
category: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
slug: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
tagLinks: {
|
||||
include: {
|
||||
tag: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
slug: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export async function getPublishedArtworkBySlug(slug: string) {
|
||||
return db.artwork.findFirst({
|
||||
where: {
|
||||
slug,
|
||||
isPublished: true,
|
||||
},
|
||||
include: {
|
||||
renditions: {
|
||||
where: {
|
||||
mediaAsset: {
|
||||
isPublished: true,
|
||||
},
|
||||
},
|
||||
orderBy: [{ isPrimary: "desc" }, { updatedAt: "desc" }],
|
||||
include: {
|
||||
mediaAsset: {
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
altText: true,
|
||||
mimeType: true,
|
||||
width: true,
|
||||
height: true,
|
||||
source: true,
|
||||
author: true,
|
||||
copyright: true,
|
||||
licenseType: true,
|
||||
licenseUrl: true,
|
||||
usageContext: true,
|
||||
location: true,
|
||||
capturedAt: true,
|
||||
tags: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
galleryLinks: {
|
||||
include: {
|
||||
gallery: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
slug: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
albumLinks: {
|
||||
include: {
|
||||
album: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
slug: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
categoryLinks: {
|
||||
include: {
|
||||
category: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
slug: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
tagLinks: {
|
||||
include: {
|
||||
tag: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
slug: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -7,6 +7,11 @@ const { mockDb } = vi.hoisted(() => ({
|
||||
update: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
findUnique: vi.fn(),
|
||||
findFirst: vi.fn(),
|
||||
findMany: vi.fn(),
|
||||
},
|
||||
pageTranslation: {
|
||||
upsert: vi.fn(),
|
||||
findMany: vi.fn(),
|
||||
},
|
||||
navigationMenu: {
|
||||
@@ -19,6 +24,9 @@ const { mockDb } = vi.hoisted(() => ({
|
||||
update: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
},
|
||||
navigationItemTranslation: {
|
||||
upsert: vi.fn(),
|
||||
},
|
||||
},
|
||||
}))
|
||||
|
||||
@@ -30,8 +38,11 @@ import {
|
||||
createNavigationItem,
|
||||
createNavigationMenu,
|
||||
createPage,
|
||||
getPublishedPageBySlugForLocale,
|
||||
listPublicNavigation,
|
||||
updatePage,
|
||||
upsertNavigationItemTranslation,
|
||||
upsertPageTranslation,
|
||||
} from "./pages-navigation"
|
||||
|
||||
describe("pages-navigation service", () => {
|
||||
@@ -105,19 +116,89 @@ describe("pages-navigation service", () => {
|
||||
slug: "home",
|
||||
status: "published",
|
||||
},
|
||||
translations: [{ locale: "de", label: "Startseite" }],
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
const navigation = await listPublicNavigation("header")
|
||||
const navigation = await listPublicNavigation("header", "de")
|
||||
|
||||
expect(navigation).toEqual([
|
||||
{
|
||||
id: "item-1",
|
||||
label: "Home",
|
||||
label: "Startseite",
|
||||
href: "/",
|
||||
children: [],
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
it("validates locale when upserting navigation item translation", async () => {
|
||||
await expect(() =>
|
||||
upsertNavigationItemTranslation({
|
||||
navigationItemId: "550e8400-e29b-41d4-a716-446655440001",
|
||||
locale: "it",
|
||||
label: "Home",
|
||||
}),
|
||||
).rejects.toThrow()
|
||||
})
|
||||
|
||||
it("validates locale when upserting page translation", async () => {
|
||||
await expect(() =>
|
||||
upsertPageTranslation({
|
||||
pageId: "550e8400-e29b-41d4-a716-446655440000",
|
||||
locale: "it",
|
||||
title: "Titolo",
|
||||
content: "Contenuto",
|
||||
}),
|
||||
).rejects.toThrow()
|
||||
})
|
||||
|
||||
it("upserts page translation and reads localized page with fallback", async () => {
|
||||
mockDb.pageTranslation.upsert.mockResolvedValue({ id: "pt-1" })
|
||||
mockDb.page.findFirst
|
||||
.mockResolvedValueOnce({
|
||||
id: "page-1",
|
||||
title: "About",
|
||||
summary: "Base summary",
|
||||
content: "Base content",
|
||||
seoTitle: "Base SEO",
|
||||
seoDescription: "Base description",
|
||||
translations: [
|
||||
{
|
||||
locale: "de",
|
||||
title: "Uber Uns",
|
||||
summary: "Zusammenfassung",
|
||||
content: "Inhalt",
|
||||
seoTitle: "SEO DE",
|
||||
seoDescription: "Beschreibung",
|
||||
},
|
||||
],
|
||||
})
|
||||
.mockResolvedValueOnce({
|
||||
id: "page-1",
|
||||
title: "About",
|
||||
summary: "Base summary",
|
||||
content: "Base content",
|
||||
seoTitle: "Base SEO",
|
||||
seoDescription: "Base description",
|
||||
translations: [],
|
||||
})
|
||||
|
||||
await upsertPageTranslation({
|
||||
pageId: "550e8400-e29b-41d4-a716-446655440000",
|
||||
locale: "de",
|
||||
title: "Uber Uns",
|
||||
content: "Inhalt",
|
||||
})
|
||||
|
||||
const translated = await getPublishedPageBySlugForLocale("about", "de")
|
||||
const fallback = await getPublishedPageBySlugForLocale("about", "fr")
|
||||
|
||||
expect(mockDb.pageTranslation.upsert).toHaveBeenCalledTimes(1)
|
||||
expect(translated?.title).toBe("Uber Uns")
|
||||
expect(translated?.content).toBe("Inhalt")
|
||||
expect(fallback?.title).toBe("About")
|
||||
expect(fallback?.content).toBe("Base content")
|
||||
})
|
||||
})
|
||||
|
||||
@@ -3,8 +3,11 @@ import {
|
||||
createNavigationMenuInputSchema,
|
||||
createPageInputSchema,
|
||||
updateNavigationItemInputSchema,
|
||||
updateNavigationMenuInputSchema,
|
||||
updatePageInputSchema,
|
||||
upsertPageTranslationInputSchema,
|
||||
} from "@cms/content"
|
||||
import { z } from "zod"
|
||||
|
||||
import { db } from "./client"
|
||||
|
||||
@@ -15,6 +18,13 @@ export type PublicNavigationItem = {
|
||||
children: PublicNavigationItem[]
|
||||
}
|
||||
|
||||
const supportedLocaleSchema = z.enum(["de", "en", "es", "fr"])
|
||||
const upsertNavigationItemTranslationInputSchema = z.object({
|
||||
navigationItemId: z.string().uuid(),
|
||||
locale: supportedLocaleSchema,
|
||||
label: z.string().min(1).max(180),
|
||||
})
|
||||
|
||||
function resolvePublishedAt(status: string): Date | null {
|
||||
return status === "published" ? new Date() : null
|
||||
}
|
||||
@@ -54,6 +64,38 @@ export async function getPublishedPageBySlug(slug: string) {
|
||||
})
|
||||
}
|
||||
|
||||
export async function getPublishedPageBySlugForLocale(slug: string, locale: string) {
|
||||
const page = await db.page.findFirst({
|
||||
where: {
|
||||
slug,
|
||||
status: "published",
|
||||
},
|
||||
include: {
|
||||
translations: {
|
||||
where: {
|
||||
locale,
|
||||
},
|
||||
take: 1,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
if (!page) {
|
||||
return null
|
||||
}
|
||||
|
||||
const translation = page.translations[0]
|
||||
|
||||
return {
|
||||
...page,
|
||||
title: translation?.title ?? page.title,
|
||||
summary: translation?.summary ?? page.summary,
|
||||
content: translation?.content ?? page.content,
|
||||
seoTitle: translation?.seoTitle ?? page.seoTitle,
|
||||
seoDescription: translation?.seoDescription ?? page.seoDescription,
|
||||
}
|
||||
}
|
||||
|
||||
export async function createPage(input: unknown) {
|
||||
const payload = createPageInputSchema.parse(input)
|
||||
|
||||
@@ -85,6 +127,33 @@ export async function deletePage(id: string) {
|
||||
})
|
||||
}
|
||||
|
||||
export async function upsertPageTranslation(input: unknown) {
|
||||
const payload = upsertPageTranslationInputSchema.parse(input)
|
||||
const { pageId, locale, ...data } = payload
|
||||
|
||||
return db.pageTranslation.upsert({
|
||||
where: {
|
||||
pageId_locale: {
|
||||
pageId,
|
||||
locale,
|
||||
},
|
||||
},
|
||||
create: {
|
||||
pageId,
|
||||
locale,
|
||||
...data,
|
||||
},
|
||||
update: data,
|
||||
})
|
||||
}
|
||||
|
||||
export async function listPageTranslations(pageId: string) {
|
||||
return db.pageTranslation.findMany({
|
||||
where: { pageId },
|
||||
orderBy: [{ locale: "asc" }],
|
||||
})
|
||||
}
|
||||
|
||||
export async function listNavigationMenus() {
|
||||
return db.navigationMenu.findMany({
|
||||
orderBy: [{ location: "asc" }, { name: "asc" }],
|
||||
@@ -99,6 +168,9 @@ export async function listNavigationMenus() {
|
||||
slug: true,
|
||||
},
|
||||
},
|
||||
translations: {
|
||||
orderBy: [{ locale: "asc" }],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -123,7 +195,12 @@ function resolveNavigationHref(item: {
|
||||
return null
|
||||
}
|
||||
|
||||
export async function listPublicNavigation(location = "header"): Promise<PublicNavigationItem[]> {
|
||||
export async function listPublicNavigation(
|
||||
location = "header",
|
||||
locale?: string,
|
||||
): Promise<PublicNavigationItem[]> {
|
||||
const normalizedLocale = locale ? supportedLocaleSchema.safeParse(locale).data : undefined
|
||||
|
||||
const menu = await db.navigationMenu.findFirst({
|
||||
where: {
|
||||
location,
|
||||
@@ -143,6 +220,12 @@ export async function listPublicNavigation(location = "header"): Promise<PublicN
|
||||
status: true,
|
||||
},
|
||||
},
|
||||
translations: normalizedLocale
|
||||
? {
|
||||
where: { locale: normalizedLocale },
|
||||
take: 1,
|
||||
}
|
||||
: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -172,7 +255,7 @@ export async function listPublicNavigation(location = "header"): Promise<PublicN
|
||||
|
||||
itemMap.set(item.id, {
|
||||
id: item.id,
|
||||
label: item.label,
|
||||
label: item.translations?.[0]?.label ?? item.label,
|
||||
href,
|
||||
parentId: item.parentId,
|
||||
children: [],
|
||||
@@ -215,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) {
|
||||
const payload = createNavigationItemInputSchema.parse(input)
|
||||
|
||||
@@ -238,3 +337,20 @@ export async function deleteNavigationItem(id: string) {
|
||||
where: { id },
|
||||
})
|
||||
}
|
||||
|
||||
export async function upsertNavigationItemTranslation(input: unknown) {
|
||||
const payload = upsertNavigationItemTranslationInputSchema.parse(input)
|
||||
|
||||
return db.navigationItemTranslation.upsert({
|
||||
where: {
|
||||
navigationItemId_locale: {
|
||||
navigationItemId: payload.navigationItemId,
|
||||
locale: payload.locale,
|
||||
},
|
||||
},
|
||||
create: payload,
|
||||
update: {
|
||||
label: payload.label,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -9,6 +9,9 @@ const { mockDb } = vi.hoisted(() => ({
|
||||
update: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
},
|
||||
postTranslation: {
|
||||
upsert: vi.fn(),
|
||||
},
|
||||
},
|
||||
}))
|
||||
|
||||
@@ -16,7 +19,15 @@ vi.mock("./client", () => ({
|
||||
db: mockDb,
|
||||
}))
|
||||
|
||||
import { createPost, getPostBySlug, listPosts, updatePost } from "./posts"
|
||||
import {
|
||||
createPost,
|
||||
getPostBySlug,
|
||||
getPostBySlugForLocale,
|
||||
listPosts,
|
||||
listPostsForLocale,
|
||||
updatePost,
|
||||
upsertPostTranslation,
|
||||
} from "./posts"
|
||||
|
||||
describe("posts service", () => {
|
||||
beforeEach(() => {
|
||||
@@ -25,6 +36,7 @@ describe("posts service", () => {
|
||||
fn.mockReset()
|
||||
}
|
||||
}
|
||||
mockDb.postTranslation.upsert.mockReset()
|
||||
})
|
||||
|
||||
it("lists posts ordered by update date desc", async () => {
|
||||
@@ -72,4 +84,63 @@ describe("posts service", () => {
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it("upserts post translation and reads localized/fallback post views", async () => {
|
||||
mockDb.postTranslation.upsert.mockResolvedValue({ id: "pt-1" })
|
||||
mockDb.post.findUnique
|
||||
.mockResolvedValueOnce({
|
||||
id: "post-1",
|
||||
slug: "hello",
|
||||
title: "Base title",
|
||||
excerpt: "Base excerpt",
|
||||
body: "Base body",
|
||||
translations: [{ locale: "de", title: "Titel", excerpt: "Auszug", body: "Text" }],
|
||||
})
|
||||
.mockResolvedValueOnce({
|
||||
id: "post-1",
|
||||
slug: "hello",
|
||||
title: "Base title",
|
||||
excerpt: "Base excerpt",
|
||||
body: "Base body",
|
||||
translations: [],
|
||||
})
|
||||
mockDb.post.findMany.mockResolvedValue([
|
||||
{
|
||||
id: "post-1",
|
||||
slug: "hello",
|
||||
title: "Base title",
|
||||
excerpt: "Base excerpt",
|
||||
body: "Base body",
|
||||
status: "published",
|
||||
translations: [{ locale: "de", title: "Titel", excerpt: "Auszug", body: "Text" }],
|
||||
},
|
||||
])
|
||||
|
||||
await upsertPostTranslation({
|
||||
postId: "550e8400-e29b-41d4-a716-446655440000",
|
||||
locale: "de",
|
||||
title: "Titel",
|
||||
body: "Text",
|
||||
})
|
||||
|
||||
const localized = await getPostBySlugForLocale("hello", "de")
|
||||
const fallback = await getPostBySlugForLocale("hello", "fr")
|
||||
const localizedList = await listPostsForLocale("de")
|
||||
|
||||
expect(mockDb.postTranslation.upsert).toHaveBeenCalledTimes(1)
|
||||
expect(localized?.title).toBe("Titel")
|
||||
expect(fallback?.title).toBe("Base title")
|
||||
expect(localizedList[0]?.title).toBe("Titel")
|
||||
})
|
||||
|
||||
it("validates locale for post translations", async () => {
|
||||
await expect(() =>
|
||||
upsertPostTranslation({
|
||||
postId: "550e8400-e29b-41d4-a716-446655440000",
|
||||
locale: "it",
|
||||
title: "Titolo",
|
||||
body: "Testo",
|
||||
}),
|
||||
).rejects.toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
updatePostInputSchema,
|
||||
} from "@cms/content"
|
||||
import { type CrudAuditHook, type CrudMutationContext, createCrudService } from "@cms/crud"
|
||||
import { z } from "zod"
|
||||
import type { Post } from "../prisma/generated/client/client"
|
||||
|
||||
import { db } from "./client"
|
||||
@@ -35,6 +36,15 @@ const postRepository = {
|
||||
}),
|
||||
}
|
||||
|
||||
const supportedLocaleSchema = z.enum(["de", "en", "es", "fr"])
|
||||
const upsertPostTranslationInputSchema = z.object({
|
||||
postId: z.string().uuid(),
|
||||
locale: supportedLocaleSchema,
|
||||
title: z.string().min(3).max(180),
|
||||
excerpt: z.string().max(320).nullable().optional(),
|
||||
body: z.string().min(1),
|
||||
})
|
||||
|
||||
const postAuditHooks: Array<CrudAuditHook<Post>> = []
|
||||
|
||||
const postCrudService = createCrudService({
|
||||
@@ -73,6 +83,100 @@ export async function getPostBySlug(slug: string) {
|
||||
})
|
||||
}
|
||||
|
||||
export async function getPostBySlugForLocale(slug: string, locale: string) {
|
||||
const normalizedLocale = supportedLocaleSchema.safeParse(locale).data
|
||||
const post = await db.post.findUnique({
|
||||
where: { slug },
|
||||
include: {
|
||||
translations: normalizedLocale
|
||||
? {
|
||||
where: {
|
||||
locale: normalizedLocale,
|
||||
},
|
||||
take: 1,
|
||||
}
|
||||
: false,
|
||||
},
|
||||
})
|
||||
|
||||
if (!post) {
|
||||
return null
|
||||
}
|
||||
|
||||
const translation = post.translations?.[0]
|
||||
|
||||
return {
|
||||
...post,
|
||||
title: translation?.title ?? post.title,
|
||||
excerpt: translation?.excerpt ?? post.excerpt,
|
||||
body: translation?.body ?? post.body,
|
||||
}
|
||||
}
|
||||
|
||||
export async function listPostsForLocale(locale: string) {
|
||||
const normalizedLocale = supportedLocaleSchema.safeParse(locale).data
|
||||
const posts = await db.post.findMany({
|
||||
where: {
|
||||
status: "published",
|
||||
},
|
||||
orderBy: {
|
||||
updatedAt: "desc",
|
||||
},
|
||||
include: {
|
||||
translations: normalizedLocale
|
||||
? {
|
||||
where: { locale: normalizedLocale },
|
||||
take: 1,
|
||||
}
|
||||
: false,
|
||||
},
|
||||
})
|
||||
|
||||
return posts.map((post) => {
|
||||
const translation = post.translations?.[0]
|
||||
|
||||
return {
|
||||
...post,
|
||||
title: translation?.title ?? post.title,
|
||||
excerpt: translation?.excerpt ?? post.excerpt,
|
||||
body: translation?.body ?? post.body,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export async function listPostsWithTranslations() {
|
||||
return db.post.findMany({
|
||||
orderBy: {
|
||||
updatedAt: "desc",
|
||||
},
|
||||
include: {
|
||||
translations: {
|
||||
orderBy: [{ locale: "asc" }],
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export async function upsertPostTranslation(input: unknown) {
|
||||
const payload = upsertPostTranslationInputSchema.parse(input)
|
||||
const { postId, locale, ...data } = payload
|
||||
|
||||
return db.postTranslation.upsert({
|
||||
where: {
|
||||
postId_locale: {
|
||||
postId,
|
||||
locale,
|
||||
},
|
||||
},
|
||||
create: {
|
||||
postId,
|
||||
locale,
|
||||
...data,
|
||||
},
|
||||
update: data,
|
||||
})
|
||||
}
|
||||
|
||||
export async function createPost(input: unknown, context?: CrudMutationContext) {
|
||||
return postCrudService.create(input, context)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user