Compare commits
3 Commits
todo/mvp1-
...
todo/mvp1-
| Author | SHA1 | Date | |
|---|---|---|---|
|
994b33e081
|
|||
|
f65a9ea03f
|
|||
|
281b1d7a1b
|
25
TODO.md
25
TODO.md
@@ -122,13 +122,13 @@ This file is the single source of truth for roadmap and delivery progress.
|
|||||||
media model, artwork entity, grouping primitives (gallery/album/category/tag), rendition slots
|
media model, artwork entity, grouping primitives (gallery/album/category/tag), rendition slots
|
||||||
- [~] [P1] `todo/mvp1-media-upload-pipeline`:
|
- [~] [P1] `todo/mvp1-media-upload-pipeline`:
|
||||||
S3/local upload adapter, media processing presets, metadata input flows, admin media CRUD UI
|
S3/local upload adapter, media processing presets, metadata input flows, admin media CRUD UI
|
||||||
- [ ] [P1] `todo/mvp1-pages-navigation-builder`:
|
- [~] [P1] `todo/mvp1-pages-navigation-builder`:
|
||||||
page CRUD, navigation tree, reusable page blocks (forms/price cards/gallery embeds)
|
page CRUD, navigation tree, reusable page blocks (forms/price cards/gallery embeds)
|
||||||
- [ ] [P1] `todo/mvp1-commissions-customers`:
|
- [~] [P1] `todo/mvp1-commissions-customers`:
|
||||||
commission request intake + admin CRUD + kanban + customer entity/linking
|
commission request intake + admin CRUD + kanban + customer entity/linking
|
||||||
- [ ] [P1] `todo/mvp1-announcements-news`:
|
- [ ] [P1] `todo/mvp1-announcements-news`:
|
||||||
announcement management/rendering + news/blog CRUD and public rendering
|
announcement management/rendering + news/blog CRUD and public rendering
|
||||||
- [ ] [P1] `todo/mvp1-public-rendering-integration`:
|
- [~] [P1] `todo/mvp1-public-rendering-integration`:
|
||||||
public rendering for pages/navigation/media/portfolio/announcements and commissioning entrypoints
|
public rendering for pages/navigation/media/portfolio/announcements and commissioning entrypoints
|
||||||
- [ ] [P1] `todo/mvp1-e2e-happy-paths`:
|
- [ ] [P1] `todo/mvp1-e2e-happy-paths`:
|
||||||
end-to-end scenarios for page publish, media flow, announcement display, commission flow
|
end-to-end scenarios for page publish, media flow, announcement display, commission flow
|
||||||
@@ -144,9 +144,9 @@ This file is the single source of truth for roadmap and delivery progress.
|
|||||||
|
|
||||||
### Admin App (Primary Focus)
|
### Admin App (Primary Focus)
|
||||||
|
|
||||||
- [ ] [P1] Page management (create/edit/publish/unpublish/schedule)
|
- [~] [P1] Page management (create/edit/publish/unpublish/schedule)
|
||||||
- [ ] [P1] Page builder with reusable content blocks (hero, rich text, gallery, CTA, forms, price cards)
|
- [ ] [P1] Page builder with reusable content blocks (hero, rich text, gallery, CTA, forms, price cards)
|
||||||
- [ ] [P1] Navigation management (menus, nested items, order, visibility)
|
- [~] [P1] Navigation management (menus, nested items, order, visibility)
|
||||||
- [~] [P1] Media library (upload, browse, replace, delete) with media-type classification (artwork, banner, promo, generic, video/gif)
|
- [~] [P1] Media library (upload, browse, replace, delete) with media-type classification (artwork, banner, promo, generic, video/gif)
|
||||||
- [ ] [P1] Media enrichment metadata (alt text, copyright, author, source, tags, licensing, usage context)
|
- [ ] [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] Portfolio grouping primitives (galleries, albums, categories, tags) with ordering/visibility controls
|
||||||
@@ -156,18 +156,18 @@ This file is the single source of truth for roadmap and delivery progress.
|
|||||||
- [ ] [P1] Users management (invite, roles, status)
|
- [ ] [P1] Users management (invite, roles, status)
|
||||||
- [ ] [P1] Disable/ban user function and enforcement in auth/session checks
|
- [ ] [P1] Disable/ban user function and enforcement in auth/session checks
|
||||||
- [~] [P1] Owner/support protection rules in user management actions (cannot delete/demote)
|
- [~] [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] Commissions management (request intake, owner, due date, notes, linked customer, linked artworks)
|
||||||
- [ ] [P1] Customer records (contact profile, notes, consent flags, recurrence marker)
|
- [~] [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] Customer-to-commission linkage and reuse workflow (no re-entry for recurring customers)
|
||||||
- [ ] [P1] Kanban workflow for commissions (new, scoped, in-progress, review, done)
|
- [~] [P1] Kanban workflow for commissions (new, scoped, in-progress, review, done)
|
||||||
- [ ] [P1] Header banner management (message, CTA, active window)
|
- [ ] [P1] Header banner management (message, CTA, active window)
|
||||||
- [ ] [P1] Announcements management (prominent site notices with schedule, priority, and audience targeting)
|
- [ ] [P1] Announcements management (prominent site notices with schedule, priority, and audience targeting)
|
||||||
- [ ] [P2] News/blog editorial workflow (draft/review/publish, authoring metadata)
|
- [ ] [P2] News/blog editorial workflow (draft/review/publish, authoring metadata)
|
||||||
|
|
||||||
### Public App
|
### Public App
|
||||||
|
|
||||||
- [ ] [P1] Dynamic page rendering from CMS page entities
|
- [~] [P1] Dynamic page rendering from CMS page entities
|
||||||
- [ ] [P1] Navigation rendering from managed menu structure
|
- [~] [P1] Navigation rendering from managed menu structure
|
||||||
- [ ] [P1] Media entity rendering with enrichment data
|
- [ ] [P1] Media entity rendering with enrichment data
|
||||||
- [ ] [P1] Portfolio views (gallery/album/category/tag) for artworks with filter and sort controls
|
- [ ] [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] Rendition-aware media delivery (thumbnail/card/full) per template slot
|
||||||
@@ -274,6 +274,9 @@ This file is the single source of truth for roadmap and delivery progress.
|
|||||||
- [2026-02-12] Upload storage is now provider-based (`local` + `s3`) via `CMS_MEDIA_STORAGE_PROVIDER`; admin-side GUI toggle remains a later MVP item.
|
- [2026-02-12] Upload storage is now provider-based (`local` + `s3`) via `CMS_MEDIA_STORAGE_PROVIDER`; admin-side GUI toggle remains a later MVP item.
|
||||||
- [2026-02-12] Media storage keys now use asset-centric layout (`tenant/<id>/asset/<assetId>/<fileRole>/<assetId>__<variant>.<ext>`) with DB-managed media taxonomy.
|
- [2026-02-12] Media storage keys now use asset-centric layout (`tenant/<id>/asset/<assetId>/<fileRole>/<assetId>__<variant>.<ext>`) with DB-managed media taxonomy.
|
||||||
- [2026-02-12] Admin media CRUD now includes list-to-detail flow (`/media/:id`) with metadata edit and delete actions.
|
- [2026-02-12] Admin media CRUD now includes list-to-detail flow (`/media/:id`) with metadata edit and delete actions.
|
||||||
|
- [2026-02-12] 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.
|
||||||
|
|
||||||
## How We Use This File
|
## How We Use This File
|
||||||
|
|
||||||
|
|||||||
@@ -1,34 +1,454 @@
|
|||||||
import { AdminSectionPlaceholder } from "@/components/admin-section-placeholder"
|
import {
|
||||||
|
commissionKanbanOrder,
|
||||||
|
createCommission,
|
||||||
|
createCustomer,
|
||||||
|
listCommissions,
|
||||||
|
listCustomers,
|
||||||
|
updateCommissionStatus,
|
||||||
|
} 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 { AdminShell } from "@/components/admin-shell"
|
||||||
import { requirePermissionForRoute } from "@/lib/route-guards"
|
import { requirePermissionForRoute } from "@/lib/route-guards"
|
||||||
|
|
||||||
export const dynamic = "force-dynamic"
|
export const dynamic = "force-dynamic"
|
||||||
|
|
||||||
export default async function CommissionsManagementPage() {
|
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 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)
|
||||||
|
|
||||||
|
if (!Number.isFinite(parsed)) {
|
||||||
|
return 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 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 ? `/commissions?${value}` : "/commissions")
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createCustomerAction(formData: FormData) {
|
||||||
|
"use server"
|
||||||
|
|
||||||
|
await requirePermissionForRoute({
|
||||||
|
nextPath: "/commissions",
|
||||||
|
permission: "commissions:write",
|
||||||
|
scope: "own",
|
||||||
|
})
|
||||||
|
|
||||||
|
try {
|
||||||
|
await createCustomer({
|
||||||
|
name: readInputString(formData, "name"),
|
||||||
|
email: readNullableString(formData, "email"),
|
||||||
|
phone: readNullableString(formData, "phone"),
|
||||||
|
instagram: readNullableString(formData, "instagram"),
|
||||||
|
notes: readNullableString(formData, "notes"),
|
||||||
|
isRecurring: readInputString(formData, "isRecurring") === "true",
|
||||||
|
})
|
||||||
|
} catch {
|
||||||
|
redirectWithState({ error: "Failed to create customer." })
|
||||||
|
}
|
||||||
|
|
||||||
|
revalidatePath("/commissions")
|
||||||
|
redirectWithState({ notice: "Customer created." })
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createCommissionAction(formData: FormData) {
|
||||||
|
"use server"
|
||||||
|
|
||||||
|
await requirePermissionForRoute({
|
||||||
|
nextPath: "/commissions",
|
||||||
|
permission: "commissions:write",
|
||||||
|
scope: "own",
|
||||||
|
})
|
||||||
|
|
||||||
|
try {
|
||||||
|
await createCommission({
|
||||||
|
title: readInputString(formData, "title"),
|
||||||
|
description: readNullableString(formData, "description"),
|
||||||
|
status: readInputString(formData, "status"),
|
||||||
|
customerId: readNullableString(formData, "customerId"),
|
||||||
|
assignedUserId: readNullableString(formData, "assignedUserId"),
|
||||||
|
budgetMin: readNullableNumber(formData, "budgetMin"),
|
||||||
|
budgetMax: readNullableNumber(formData, "budgetMax"),
|
||||||
|
dueAt: readNullableDate(formData, "dueAt"),
|
||||||
|
})
|
||||||
|
} catch {
|
||||||
|
redirectWithState({ error: "Failed to create commission." })
|
||||||
|
}
|
||||||
|
|
||||||
|
revalidatePath("/commissions")
|
||||||
|
redirectWithState({ notice: "Commission created." })
|
||||||
|
}
|
||||||
|
|
||||||
|
async function updateCommissionStatusAction(formData: FormData) {
|
||||||
|
"use server"
|
||||||
|
|
||||||
|
await requirePermissionForRoute({
|
||||||
|
nextPath: "/commissions",
|
||||||
|
permission: "commissions:transition",
|
||||||
|
scope: "own",
|
||||||
|
})
|
||||||
|
|
||||||
|
try {
|
||||||
|
await updateCommissionStatus({
|
||||||
|
id: readInputString(formData, "id"),
|
||||||
|
status: readInputString(formData, "status"),
|
||||||
|
})
|
||||||
|
} catch {
|
||||||
|
redirectWithState({ error: "Failed to transition commission." })
|
||||||
|
}
|
||||||
|
|
||||||
|
revalidatePath("/commissions")
|
||||||
|
redirectWithState({ notice: "Commission status updated." })
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatDate(value: Date | null) {
|
||||||
|
if (!value) {
|
||||||
|
return "-"
|
||||||
|
}
|
||||||
|
|
||||||
|
return value.toLocaleDateString("en-US")
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function CommissionsManagementPage({
|
||||||
|
searchParams,
|
||||||
|
}: {
|
||||||
|
searchParams: Promise<SearchParamsInput>
|
||||||
|
}) {
|
||||||
const role = await requirePermissionForRoute({
|
const role = await requirePermissionForRoute({
|
||||||
nextPath: "/commissions",
|
nextPath: "/commissions",
|
||||||
permission: "commissions:read",
|
permission: "commissions:read",
|
||||||
scope: "own",
|
scope: "own",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const [resolvedSearchParams, customers, commissions] = await Promise.all([
|
||||||
|
searchParams,
|
||||||
|
listCustomers(200),
|
||||||
|
listCommissions(300),
|
||||||
|
])
|
||||||
|
|
||||||
|
const notice = readFirstValue(resolvedSearchParams.notice)
|
||||||
|
const error = readFirstValue(resolvedSearchParams.error)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AdminShell
|
<AdminShell
|
||||||
role={role}
|
role={role}
|
||||||
activePath="/commissions"
|
activePath="/commissions"
|
||||||
badge="Admin App"
|
badge="Admin App"
|
||||||
title="Commissions"
|
title="Commissions"
|
||||||
description="Prepare commissions intake and kanban workflow tooling."
|
description="Manage customers and commission requests with kanban-style status transitions."
|
||||||
>
|
>
|
||||||
<AdminSectionPlaceholder
|
{notice ? (
|
||||||
feature="Commissions Workflow"
|
<section className="rounded-xl border border-emerald-300 bg-emerald-50 px-4 py-3 text-sm text-emerald-800">
|
||||||
summary="This route is reserved for request intake, ownership assignment, and kanban transitions."
|
{notice}
|
||||||
requiredPermission="commissions:read (own)"
|
</section>
|
||||||
nextSteps={[
|
) : null}
|
||||||
"Add commissions board with status columns.",
|
|
||||||
"Add assignment, due-date, and notes editing.",
|
{error ? (
|
||||||
"Add transition rules and audit history.",
|
<section className="rounded-xl border border-red-300 bg-red-50 px-4 py-3 text-sm text-red-800">
|
||||||
]}
|
{error}
|
||||||
/>
|
</section>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
<section className="grid gap-4 xl:grid-cols-2">
|
||||||
|
<article className="rounded-xl border border-neutral-200 p-6">
|
||||||
|
<h2 className="text-xl font-medium">Create Customer</h2>
|
||||||
|
<form action={createCustomerAction} 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>
|
||||||
|
<div className="grid gap-3 md:grid-cols-2">
|
||||||
|
<label className="space-y-1">
|
||||||
|
<span className="text-xs text-neutral-600">Email</span>
|
||||||
|
<input
|
||||||
|
name="email"
|
||||||
|
type="email"
|
||||||
|
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">Phone</span>
|
||||||
|
<input
|
||||||
|
name="phone"
|
||||||
|
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">Instagram</span>
|
||||||
|
<input
|
||||||
|
name="instagram"
|
||||||
|
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">Notes</span>
|
||||||
|
<textarea
|
||||||
|
name="notes"
|
||||||
|
rows={3}
|
||||||
|
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="isRecurring" type="checkbox" value="true" className="size-4" />
|
||||||
|
Recurring customer
|
||||||
|
</label>
|
||||||
|
<Button type="submit">Create customer</Button>
|
||||||
|
</form>
|
||||||
|
</article>
|
||||||
|
|
||||||
|
<article className="rounded-xl border border-neutral-200 p-6">
|
||||||
|
<h2 className="text-xl font-medium">Create Commission</h2>
|
||||||
|
<form action={createCommissionAction} className="mt-4 space-y-3">
|
||||||
|
<label className="space-y-1">
|
||||||
|
<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">Description</span>
|
||||||
|
<textarea
|
||||||
|
name="description"
|
||||||
|
rows={3}
|
||||||
|
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">Status</span>
|
||||||
|
<select
|
||||||
|
name="status"
|
||||||
|
defaultValue="new"
|
||||||
|
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||||
|
>
|
||||||
|
{commissionKanbanOrder.map((status) => (
|
||||||
|
<option key={status} value={status}>
|
||||||
|
{status}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
<label className="space-y-1">
|
||||||
|
<span className="text-xs text-neutral-600">Customer</span>
|
||||||
|
<select
|
||||||
|
name="customerId"
|
||||||
|
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||||
|
>
|
||||||
|
<option value="">(none)</option>
|
||||||
|
{customers.map((customer) => (
|
||||||
|
<option key={customer.id} value={customer.id}>
|
||||||
|
{customer.name}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
</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
|
||||||
|
name="assignedUserId"
|
||||||
|
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">Budget min</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">Budget max</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>
|
||||||
|
<label className="space-y-1">
|
||||||
|
<span className="text-xs text-neutral-600">Due date</span>
|
||||||
|
<input
|
||||||
|
name="dueAt"
|
||||||
|
type="date"
|
||||||
|
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<Button type="submit">Create commission</Button>
|
||||||
|
</form>
|
||||||
|
</article>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section className="space-y-4">
|
||||||
|
<h2 className="text-xl font-medium">Kanban Board</h2>
|
||||||
|
<div className="grid gap-3 xl:grid-cols-6">
|
||||||
|
{commissionKanbanOrder.map((status) => {
|
||||||
|
const items = commissions.filter((commission) => commission.status === status)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<article
|
||||||
|
key={status}
|
||||||
|
className="rounded-xl border border-neutral-200 bg-neutral-50 p-3"
|
||||||
|
>
|
||||||
|
<header className="mb-3 flex items-center justify-between">
|
||||||
|
<h3 className="text-sm font-semibold uppercase tracking-wide text-neutral-700">
|
||||||
|
{status}
|
||||||
|
</h3>
|
||||||
|
<span className="text-xs text-neutral-500">{items.length}</span>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div className="space-y-2">
|
||||||
|
{items.length === 0 ? (
|
||||||
|
<p className="text-xs text-neutral-500">No commissions</p>
|
||||||
|
) : (
|
||||||
|
items.map((commission) => (
|
||||||
|
<form
|
||||||
|
key={commission.id}
|
||||||
|
action={updateCommissionStatusAction}
|
||||||
|
className="rounded border border-neutral-200 bg-white p-2"
|
||||||
|
>
|
||||||
|
<input type="hidden" name="id" value={commission.id} />
|
||||||
|
<div className="space-y-1">
|
||||||
|
<p className="text-sm font-medium">{commission.title}</p>
|
||||||
|
<p className="text-xs text-neutral-600">
|
||||||
|
{commission.customer?.name ?? "No customer"}
|
||||||
|
</p>
|
||||||
|
<p className="text-xs text-neutral-500">
|
||||||
|
Due: {formatDate(commission.dueAt)}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="mt-2 flex items-center gap-2">
|
||||||
|
<select
|
||||||
|
name="status"
|
||||||
|
defaultValue={commission.status}
|
||||||
|
className="w-full rounded border border-neutral-300 px-2 py-1 text-xs"
|
||||||
|
>
|
||||||
|
{commissionKanbanOrder.map((value) => (
|
||||||
|
<option key={value} value={value}>
|
||||||
|
{value}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
className="rounded border border-neutral-300 px-2 py-1 text-xs"
|
||||||
|
>
|
||||||
|
Move
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section className="rounded-xl border border-neutral-200 p-6">
|
||||||
|
<h2 className="text-xl font-medium">Customers</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">Name</th>
|
||||||
|
<th className="py-2 pr-4">Email</th>
|
||||||
|
<th className="py-2 pr-4">Phone</th>
|
||||||
|
<th className="py-2 pr-4">Recurring</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{customers.length === 0 ? (
|
||||||
|
<tr>
|
||||||
|
<td className="py-3 text-neutral-500" colSpan={4}>
|
||||||
|
No customers yet.
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
) : (
|
||||||
|
customers.map((customer) => (
|
||||||
|
<tr key={customer.id} className="border-t border-neutral-200">
|
||||||
|
<td className="py-3 pr-4">{customer.name}</td>
|
||||||
|
<td className="py-3 pr-4 text-neutral-600">{customer.email ?? "-"}</td>
|
||||||
|
<td className="py-3 pr-4 text-neutral-600">{customer.phone ?? "-"}</td>
|
||||||
|
<td className="py-3 pr-4">{customer.isRecurring ? "yes" : "no"}</td>
|
||||||
|
</tr>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
</AdminShell>
|
</AdminShell>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
446
apps/admin/src/app/navigation/page.tsx
Normal file
446
apps/admin/src/app/navigation/page.tsx
Normal file
@@ -0,0 +1,446 @@
|
|||||||
|
import {
|
||||||
|
createNavigationItem,
|
||||||
|
createNavigationMenu,
|
||||||
|
deleteNavigationItem,
|
||||||
|
listNavigationMenus,
|
||||||
|
listPages,
|
||||||
|
updateNavigationItem,
|
||||||
|
} 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 { requirePermissionForRoute } from "@/lib/route-guards"
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic"
|
||||||
|
|
||||||
|
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 readNullableString(formData: FormData, field: string): string | null {
|
||||||
|
const value = readInputString(formData, field)
|
||||||
|
return value.length > 0 ? value : null
|
||||||
|
}
|
||||||
|
|
||||||
|
function readInt(formData: FormData, field: string, fallback = 0): number {
|
||||||
|
const value = readInputString(formData, field)
|
||||||
|
|
||||||
|
if (!value) {
|
||||||
|
return fallback
|
||||||
|
}
|
||||||
|
|
||||||
|
const parsed = Number.parseInt(value, 10)
|
||||||
|
|
||||||
|
if (!Number.isFinite(parsed)) {
|
||||||
|
return fallback
|
||||||
|
}
|
||||||
|
|
||||||
|
return parsed
|
||||||
|
}
|
||||||
|
|
||||||
|
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 ? `/navigation?${value}` : "/navigation")
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createMenuAction(formData: FormData) {
|
||||||
|
"use server"
|
||||||
|
|
||||||
|
await requirePermissionForRoute({
|
||||||
|
nextPath: "/navigation",
|
||||||
|
permission: "navigation:write",
|
||||||
|
scope: "team",
|
||||||
|
})
|
||||||
|
|
||||||
|
try {
|
||||||
|
await createNavigationMenu({
|
||||||
|
name: readInputString(formData, "name"),
|
||||||
|
slug: readInputString(formData, "slug"),
|
||||||
|
location: readInputString(formData, "location"),
|
||||||
|
isVisible: readInputString(formData, "isVisible") === "true",
|
||||||
|
})
|
||||||
|
} catch {
|
||||||
|
redirectWithState({ error: "Failed to create navigation menu." })
|
||||||
|
}
|
||||||
|
|
||||||
|
revalidatePath("/navigation")
|
||||||
|
redirectWithState({ notice: "Navigation menu created." })
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createItemAction(formData: FormData) {
|
||||||
|
"use server"
|
||||||
|
|
||||||
|
await requirePermissionForRoute({
|
||||||
|
nextPath: "/navigation",
|
||||||
|
permission: "navigation:write",
|
||||||
|
scope: "team",
|
||||||
|
})
|
||||||
|
|
||||||
|
try {
|
||||||
|
await createNavigationItem({
|
||||||
|
menuId: readInputString(formData, "menuId"),
|
||||||
|
label: readInputString(formData, "label"),
|
||||||
|
href: readNullableString(formData, "href"),
|
||||||
|
pageId: readNullableString(formData, "pageId"),
|
||||||
|
parentId: readNullableString(formData, "parentId"),
|
||||||
|
sortOrder: readInt(formData, "sortOrder", 0),
|
||||||
|
isVisible: readInputString(formData, "isVisible") === "true",
|
||||||
|
})
|
||||||
|
} catch {
|
||||||
|
redirectWithState({ error: "Failed to create navigation item." })
|
||||||
|
}
|
||||||
|
|
||||||
|
revalidatePath("/navigation")
|
||||||
|
redirectWithState({ notice: "Navigation item created." })
|
||||||
|
}
|
||||||
|
|
||||||
|
async function updateItemAction(formData: FormData) {
|
||||||
|
"use server"
|
||||||
|
|
||||||
|
await requirePermissionForRoute({
|
||||||
|
nextPath: "/navigation",
|
||||||
|
permission: "navigation:write",
|
||||||
|
scope: "team",
|
||||||
|
})
|
||||||
|
|
||||||
|
try {
|
||||||
|
await updateNavigationItem({
|
||||||
|
id: readInputString(formData, "id"),
|
||||||
|
label: readInputString(formData, "label"),
|
||||||
|
href: readNullableString(formData, "href"),
|
||||||
|
pageId: readNullableString(formData, "pageId"),
|
||||||
|
parentId: readNullableString(formData, "parentId"),
|
||||||
|
sortOrder: readInt(formData, "sortOrder", 0),
|
||||||
|
isVisible: readInputString(formData, "isVisible") === "true",
|
||||||
|
})
|
||||||
|
} catch {
|
||||||
|
redirectWithState({ error: "Failed to update navigation item." })
|
||||||
|
}
|
||||||
|
|
||||||
|
revalidatePath("/navigation")
|
||||||
|
redirectWithState({ notice: "Navigation item updated." })
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteItemAction(formData: FormData) {
|
||||||
|
"use server"
|
||||||
|
|
||||||
|
await requirePermissionForRoute({
|
||||||
|
nextPath: "/navigation",
|
||||||
|
permission: "navigation:write",
|
||||||
|
scope: "team",
|
||||||
|
})
|
||||||
|
|
||||||
|
try {
|
||||||
|
await deleteNavigationItem(readInputString(formData, "id"))
|
||||||
|
} catch {
|
||||||
|
redirectWithState({ error: "Failed to delete navigation item." })
|
||||||
|
}
|
||||||
|
|
||||||
|
revalidatePath("/navigation")
|
||||||
|
redirectWithState({ notice: "Navigation item deleted." })
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function NavigationManagementPage({
|
||||||
|
searchParams,
|
||||||
|
}: {
|
||||||
|
searchParams: Promise<SearchParamsInput>
|
||||||
|
}) {
|
||||||
|
const role = await requirePermissionForRoute({
|
||||||
|
nextPath: "/navigation",
|
||||||
|
permission: "navigation:read",
|
||||||
|
scope: "team",
|
||||||
|
})
|
||||||
|
|
||||||
|
const [resolvedSearchParams, menus, pages] = await Promise.all([
|
||||||
|
searchParams,
|
||||||
|
listNavigationMenus(),
|
||||||
|
listPages(200),
|
||||||
|
])
|
||||||
|
|
||||||
|
const notice = readFirstValue(resolvedSearchParams.notice)
|
||||||
|
const error = readFirstValue(resolvedSearchParams.error)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AdminShell
|
||||||
|
role={role}
|
||||||
|
activePath="/navigation"
|
||||||
|
badge="Admin App"
|
||||||
|
title="Navigation"
|
||||||
|
description="Manage menus and navigation entries linked to pages or custom routes."
|
||||||
|
>
|
||||||
|
{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}
|
||||||
|
|
||||||
|
<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>
|
||||||
|
</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>
|
||||||
|
</article>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section className="space-y-4">
|
||||||
|
{menus.length === 0 ? (
|
||||||
|
<article className="rounded-xl border border-neutral-200 p-6 text-sm text-neutral-600">
|
||||||
|
No navigation menus yet.
|
||||||
|
</article>
|
||||||
|
) : (
|
||||||
|
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>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</section>
|
||||||
|
</AdminShell>
|
||||||
|
)
|
||||||
|
}
|
||||||
242
apps/admin/src/app/pages/[id]/page.tsx
Normal file
242
apps/admin/src/app/pages/[id]/page.tsx
Normal file
@@ -0,0 +1,242 @@
|
|||||||
|
import { deletePage, getPageById, updatePage } 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 { requirePermissionForRoute } from "@/lib/route-guards"
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic"
|
||||||
|
|
||||||
|
type SearchParamsInput = Record<string, string | string[] | undefined>
|
||||||
|
|
||||||
|
type PageProps = {
|
||||||
|
params: Promise<{ id: 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 redirectWithState(pageId: 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 value = query.toString()
|
||||||
|
redirect(value ? `/pages/${pageId}?${value}` : `/pages/${pageId}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function PageEditorPage({ params, searchParams }: PageProps) {
|
||||||
|
const role = await requirePermissionForRoute({
|
||||||
|
nextPath: "/pages",
|
||||||
|
permission: "pages:read",
|
||||||
|
scope: "team",
|
||||||
|
})
|
||||||
|
const resolvedParams = await params
|
||||||
|
const pageId = resolvedParams.id
|
||||||
|
|
||||||
|
const [resolvedSearchParams, pageRecord] = await Promise.all([searchParams, getPageById(pageId)])
|
||||||
|
|
||||||
|
if (!pageRecord) {
|
||||||
|
redirect("/pages?error=Page+not+found")
|
||||||
|
}
|
||||||
|
|
||||||
|
const page = pageRecord
|
||||||
|
const notice = readFirstValue(resolvedSearchParams.notice)
|
||||||
|
const error = readFirstValue(resolvedSearchParams.error)
|
||||||
|
|
||||||
|
async function updatePageAction(formData: FormData) {
|
||||||
|
"use server"
|
||||||
|
|
||||||
|
await requirePermissionForRoute({
|
||||||
|
nextPath: "/pages",
|
||||||
|
permission: "pages:write",
|
||||||
|
scope: "team",
|
||||||
|
})
|
||||||
|
|
||||||
|
try {
|
||||||
|
await updatePage({
|
||||||
|
id: pageId,
|
||||||
|
title: readInputString(formData, "title"),
|
||||||
|
slug: readInputString(formData, "slug"),
|
||||||
|
status: readInputString(formData, "status"),
|
||||||
|
summary: readNullableString(formData, "summary"),
|
||||||
|
content: readInputString(formData, "content"),
|
||||||
|
seoTitle: readNullableString(formData, "seoTitle"),
|
||||||
|
seoDescription: readNullableString(formData, "seoDescription"),
|
||||||
|
})
|
||||||
|
} catch {
|
||||||
|
redirectWithState(pageId, {
|
||||||
|
error: "Failed to update page. Validate values and try again.",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
redirectWithState(pageId, {
|
||||||
|
notice: "Page updated.",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deletePageAction() {
|
||||||
|
"use server"
|
||||||
|
|
||||||
|
await requirePermissionForRoute({
|
||||||
|
nextPath: "/pages",
|
||||||
|
permission: "pages:write",
|
||||||
|
scope: "team",
|
||||||
|
})
|
||||||
|
|
||||||
|
try {
|
||||||
|
await deletePage(pageId)
|
||||||
|
} catch {
|
||||||
|
redirectWithState(pageId, {
|
||||||
|
error: "Failed to delete page. Remove linked navigation references first.",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
redirect("/pages?notice=Page+deleted")
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AdminShell
|
||||||
|
role={role}
|
||||||
|
activePath="/pages"
|
||||||
|
badge="Admin App"
|
||||||
|
title="Page Editor"
|
||||||
|
description="Edit page metadata, content, and publication status."
|
||||||
|
>
|
||||||
|
{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}
|
||||||
|
|
||||||
|
<section className="rounded-xl border border-neutral-200 p-6">
|
||||||
|
<div className="flex flex-wrap items-center justify-between gap-3">
|
||||||
|
<div>
|
||||||
|
<h2 className="text-xl font-medium">{page.title}</h2>
|
||||||
|
<p className="mt-1 text-xs text-neutral-600">ID: {page.id}</p>
|
||||||
|
</div>
|
||||||
|
<Link href="/pages" className="text-sm text-neutral-700 underline underline-offset-2">
|
||||||
|
Back to pages
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form action={updatePageAction} className="mt-6 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"
|
||||||
|
defaultValue={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">Status</span>
|
||||||
|
<select
|
||||||
|
name="status"
|
||||||
|
defaultValue={page.status}
|
||||||
|
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"
|
||||||
|
defaultValue={page.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"
|
||||||
|
defaultValue={page.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={10}
|
||||||
|
defaultValue={page.content}
|
||||||
|
required
|
||||||
|
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<div className="grid gap-3 md:grid-cols-2">
|
||||||
|
<label className="space-y-1">
|
||||||
|
<span className="text-xs text-neutral-600">SEO title</span>
|
||||||
|
<input
|
||||||
|
name="seoTitle"
|
||||||
|
defaultValue={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={page.seoDescription ?? ""}
|
||||||
|
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Button type="submit">Save page</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">
|
||||||
|
Deleting this page is permanent and may break linked navigation items.
|
||||||
|
</p>
|
||||||
|
<form action={deletePageAction} className="mt-4">
|
||||||
|
<Button type="submit" variant="secondary" className="border border-red-300 text-red-800">
|
||||||
|
Delete page
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
</AdminShell>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,15 +1,92 @@
|
|||||||
import { AdminSectionPlaceholder } from "@/components/admin-section-placeholder"
|
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 { AdminShell } from "@/components/admin-shell"
|
||||||
import { requirePermissionForRoute } from "@/lib/route-guards"
|
import { requirePermissionForRoute } from "@/lib/route-guards"
|
||||||
|
|
||||||
export const dynamic = "force-dynamic"
|
export const dynamic = "force-dynamic"
|
||||||
|
|
||||||
export default async function PagesManagementPage() {
|
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 readNullableString(formData: FormData, field: string): string | null {
|
||||||
|
const value = readInputString(formData, field)
|
||||||
|
return value.length > 0 ? value : null
|
||||||
|
}
|
||||||
|
|
||||||
|
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 ? `/pages?${value}` : "/pages")
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createPageAction(formData: FormData) {
|
||||||
|
"use server"
|
||||||
|
|
||||||
|
await requirePermissionForRoute({
|
||||||
|
nextPath: "/pages",
|
||||||
|
permission: "pages:write",
|
||||||
|
scope: "team",
|
||||||
|
})
|
||||||
|
|
||||||
|
try {
|
||||||
|
await createPage({
|
||||||
|
title: readInputString(formData, "title"),
|
||||||
|
slug: readInputString(formData, "slug"),
|
||||||
|
status: readInputString(formData, "status"),
|
||||||
|
summary: readNullableString(formData, "summary"),
|
||||||
|
content: readInputString(formData, "content"),
|
||||||
|
seoTitle: readNullableString(formData, "seoTitle"),
|
||||||
|
seoDescription: readNullableString(formData, "seoDescription"),
|
||||||
|
})
|
||||||
|
} catch {
|
||||||
|
redirectWithState({
|
||||||
|
error: "Failed to create page. Validate slug/title/content and try again.",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
revalidatePath("/pages")
|
||||||
|
revalidatePath("/navigation")
|
||||||
|
redirectWithState({ notice: "Page created." })
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function PagesManagementPage({
|
||||||
|
searchParams,
|
||||||
|
}: {
|
||||||
|
searchParams: Promise<SearchParamsInput>
|
||||||
|
}) {
|
||||||
const role = await requirePermissionForRoute({
|
const role = await requirePermissionForRoute({
|
||||||
nextPath: "/pages",
|
nextPath: "/pages",
|
||||||
permission: "pages:read",
|
permission: "pages:read",
|
||||||
scope: "team",
|
scope: "team",
|
||||||
})
|
})
|
||||||
|
const [resolvedSearchParams, pages] = await Promise.all([searchParams, listPages(100)])
|
||||||
|
const notice = readFirstValue(resolvedSearchParams.notice)
|
||||||
|
const error = readFirstValue(resolvedSearchParams.error)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AdminShell
|
<AdminShell
|
||||||
@@ -17,18 +94,137 @@ export default async function PagesManagementPage() {
|
|||||||
activePath="/pages"
|
activePath="/pages"
|
||||||
badge="Admin App"
|
badge="Admin App"
|
||||||
title="Pages"
|
title="Pages"
|
||||||
description="Manage page entities and publication workflows."
|
description="Create, update, and manage published page entities."
|
||||||
>
|
>
|
||||||
<AdminSectionPlaceholder
|
{notice ? (
|
||||||
feature="Page Management"
|
<section className="rounded-xl border border-emerald-300 bg-emerald-50 px-4 py-3 text-sm text-emerald-800">
|
||||||
summary="This MVP0 scaffold defines information architecture and access boundaries for future page CRUD."
|
{notice}
|
||||||
requiredPermission="pages:read (team)"
|
</section>
|
||||||
nextSteps={[
|
) : null}
|
||||||
"Add page entity list and search.",
|
|
||||||
"Add create/edit draft flows with validation.",
|
{error ? (
|
||||||
"Add publish/unpublish scheduling controls.",
|
<section className="rounded-xl border border-red-300 bg-red-50 px-4 py-3 text-sm text-red-800">
|
||||||
]}
|
{error}
|
||||||
/>
|
</section>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
<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>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section className="rounded-xl border border-neutral-200 p-6">
|
||||||
|
<h2 className="text-xl font-medium">Pages</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">Title</th>
|
||||||
|
<th className="py-2 pr-4">Slug</th>
|
||||||
|
<th className="py-2 pr-4">Status</th>
|
||||||
|
<th className="py-2 pr-4">Updated</th>
|
||||||
|
<th className="py-2 pr-4">Action</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{pages.length === 0 ? (
|
||||||
|
<tr>
|
||||||
|
<td className="py-3 text-neutral-500" colSpan={5}>
|
||||||
|
No pages yet.
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
) : (
|
||||||
|
pages.map((page) => (
|
||||||
|
<tr key={page.id} className="border-t border-neutral-200">
|
||||||
|
<td className="py-3 pr-4">{page.title}</td>
|
||||||
|
<td className="py-3 pr-4 text-neutral-600">/{page.slug}</td>
|
||||||
|
<td className="py-3 pr-4">{page.status}</td>
|
||||||
|
<td className="py-3 pr-4 text-neutral-600">
|
||||||
|
{page.updatedAt.toLocaleDateString("en-US")}
|
||||||
|
</td>
|
||||||
|
<td className="py-3 pr-4">
|
||||||
|
<Link
|
||||||
|
href={`/pages/${page.id}`}
|
||||||
|
className="text-xs font-medium text-neutral-700 underline underline-offset-2"
|
||||||
|
>
|
||||||
|
Open
|
||||||
|
</Link>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
</AdminShell>
|
</AdminShell>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ type NavItem = {
|
|||||||
const navItems: NavItem[] = [
|
const navItems: NavItem[] = [
|
||||||
{ href: "/", label: "Dashboard", permission: "dashboard:read", scope: "global" },
|
{ href: "/", label: "Dashboard", permission: "dashboard:read", scope: "global" },
|
||||||
{ href: "/pages", label: "Pages", permission: "pages:read", scope: "team" },
|
{ href: "/pages", label: "Pages", permission: "pages:read", scope: "team" },
|
||||||
|
{ href: "/navigation", label: "Navigation", permission: "navigation:read", scope: "team" },
|
||||||
{ href: "/media", label: "Media", permission: "media:read", scope: "team" },
|
{ href: "/media", label: "Media", permission: "media:read", scope: "team" },
|
||||||
{ href: "/portfolio", label: "Portfolio", permission: "media:read", scope: "team" },
|
{ href: "/portfolio", label: "Portfolio", permission: "media:read", scope: "team" },
|
||||||
{ href: "/users", label: "Users", permission: "users:read", scope: "own" },
|
{ href: "/users", label: "Users", permission: "users:read", scope: "own" },
|
||||||
|
|||||||
@@ -27,6 +27,10 @@ describe("admin route access rules", () => {
|
|||||||
permission: "pages:read",
|
permission: "pages:read",
|
||||||
scope: "team",
|
scope: "team",
|
||||||
})
|
})
|
||||||
|
expect(getRequiredPermission("/navigation")).toEqual({
|
||||||
|
permission: "navigation:read",
|
||||||
|
scope: "team",
|
||||||
|
})
|
||||||
expect(getRequiredPermission("/media")).toEqual({
|
expect(getRequiredPermission("/media")).toEqual({
|
||||||
permission: "media:read",
|
permission: "media:read",
|
||||||
scope: "team",
|
scope: "team",
|
||||||
|
|||||||
@@ -50,6 +50,13 @@ const guardRules: GuardRule[] = [
|
|||||||
scope: "team",
|
scope: "team",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
route: /^\/navigation(?:\/|$)/,
|
||||||
|
requirement: {
|
||||||
|
permission: "navigation:read",
|
||||||
|
scope: "team",
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
route: /^\/media(?:\/|$)/,
|
route: /^\/media(?:\/|$)/,
|
||||||
requirement: {
|
requirement: {
|
||||||
|
|||||||
21
apps/web/src/app/[locale]/[slug]/page.tsx
Normal file
21
apps/web/src/app/[locale]/[slug]/page.tsx
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { getPublishedPageBySlug } from "@cms/db"
|
||||||
|
import { notFound } from "next/navigation"
|
||||||
|
|
||||||
|
import { PublicPageView } from "@/components/public-page-view"
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic"
|
||||||
|
|
||||||
|
type PageProps = {
|
||||||
|
params: Promise<{ slug: string }>
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function CmsPageRoute({ params }: PageProps) {
|
||||||
|
const { slug } = await params
|
||||||
|
const page = await getPublishedPageBySlug(slug)
|
||||||
|
|
||||||
|
if (!page) {
|
||||||
|
notFound()
|
||||||
|
}
|
||||||
|
|
||||||
|
return <PublicPageView page={page} />
|
||||||
|
}
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
import { getTranslations } from "next-intl/server"
|
|
||||||
|
|
||||||
export default async function AboutPage() {
|
|
||||||
const t = await getTranslations("About")
|
|
||||||
|
|
||||||
return (
|
|
||||||
<section className="mx-auto w-full max-w-6xl space-y-4 px-6 py-16">
|
|
||||||
<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="max-w-3xl text-neutral-600">{t("description")}</p>
|
|
||||||
</section>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
import { getTranslations } from "next-intl/server"
|
|
||||||
|
|
||||||
export default async function ContactPage() {
|
|
||||||
const t = await getTranslations("Contact")
|
|
||||||
|
|
||||||
return (
|
|
||||||
<section className="mx-auto w-full max-w-6xl space-y-4 px-6 py-16">
|
|
||||||
<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="max-w-3xl text-neutral-600">{t("description")}</p>
|
|
||||||
</section>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,35 +1,45 @@
|
|||||||
import { listPosts } from "@cms/db"
|
import { getPublishedPageBySlug, listPosts } from "@cms/db"
|
||||||
import { Button } from "@cms/ui/button"
|
import { Button } from "@cms/ui/button"
|
||||||
import { getTranslations } from "next-intl/server"
|
import { getTranslations } from "next-intl/server"
|
||||||
|
|
||||||
|
import { PublicPageView } from "@/components/public-page-view"
|
||||||
|
|
||||||
export const dynamic = "force-dynamic"
|
export const dynamic = "force-dynamic"
|
||||||
|
|
||||||
export default async function HomePage() {
|
export default async function HomePage() {
|
||||||
const [posts, t] = await Promise.all([listPosts(), getTranslations("Home")])
|
const [homePage, posts, t] = await Promise.all([
|
||||||
|
getPublishedPageBySlug("home"),
|
||||||
|
listPosts(),
|
||||||
|
getTranslations("Home"),
|
||||||
|
])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className="mx-auto flex w-full max-w-6xl flex-col gap-6 px-6 py-16">
|
<section>
|
||||||
<header className="space-y-3">
|
{homePage ? <PublicPageView page={homePage} /> : null}
|
||||||
<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="space-y-4 rounded-xl border border-neutral-200 p-6">
|
<section className="mx-auto flex w-full max-w-6xl flex-col gap-6 px-6 py-6 pb-16">
|
||||||
<div className="flex items-center justify-between">
|
<header className="space-y-3">
|
||||||
<h2 className="text-xl font-medium">{t("latestPosts")}</h2>
|
<p className="text-sm uppercase tracking-[0.2em] text-neutral-500">{t("badge")}</p>
|
||||||
<Button variant="secondary">{t("explore")}</Button>
|
<h2 className="text-3xl font-semibold tracking-tight">{t("latestPosts")}</h2>
|
||||||
</div>
|
<p className="text-neutral-600">{t("description")}</p>
|
||||||
|
</header>
|
||||||
|
|
||||||
<ul className="space-y-3">
|
<section className="space-y-4 rounded-xl border border-neutral-200 p-6">
|
||||||
{posts.map((post) => (
|
<div className="flex items-center justify-between">
|
||||||
<li key={post.id} className="rounded-lg border border-neutral-200 p-4">
|
<h3 className="text-xl font-medium">{t("latestPosts")}</h3>
|
||||||
<p className="text-xs uppercase tracking-wide text-neutral-500">{post.status}</p>
|
<Button variant="secondary">{t("explore")}</Button>
|
||||||
<h3 className="mt-1 text-lg font-medium">{post.title}</h3>
|
</div>
|
||||||
<p className="mt-2 text-sm text-neutral-600">{post.excerpt ?? t("noExcerpt")}</p>
|
|
||||||
</li>
|
<ul className="space-y-3">
|
||||||
))}
|
{posts.map((post) => (
|
||||||
</ul>
|
<li key={post.id} className="rounded-lg border border-neutral-200 p-4">
|
||||||
|
<p className="text-xs uppercase tracking-wide text-neutral-500">{post.status}</p>
|
||||||
|
<h4 className="mt-1 text-lg font-medium">{post.title}</h4>
|
||||||
|
<p className="mt-2 text-sm text-neutral-600">{post.excerpt ?? t("noExcerpt")}</p>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
</section>
|
</section>
|
||||||
</section>
|
</section>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
|
import { listPublishedPageSlugs } from "@cms/db"
|
||||||
import type { MetadataRoute } from "next"
|
import type { MetadataRoute } from "next"
|
||||||
|
|
||||||
const baseUrl = process.env.CMS_WEB_ORIGIN ?? "http://localhost:3000"
|
const baseUrl = process.env.CMS_WEB_ORIGIN ?? "http://localhost:3000"
|
||||||
|
|
||||||
const publicRoutes = ["/", "/about", "/contact"]
|
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
||||||
|
const pages = await listPublishedPageSlugs()
|
||||||
|
|
||||||
export default function sitemap(): MetadataRoute.Sitemap {
|
return pages.map((page) => ({
|
||||||
const now = new Date()
|
url: page.slug === "home" ? `${baseUrl}/` : `${baseUrl}/${page.slug}`,
|
||||||
|
lastModified: page.updatedAt,
|
||||||
return publicRoutes.map((route) => ({
|
|
||||||
url: `${baseUrl}${route}`,
|
|
||||||
lastModified: now,
|
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|||||||
26
apps/web/src/components/public-page-view.tsx
Normal file
26
apps/web/src/components/public-page-view.tsx
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
type PageEntity = {
|
||||||
|
title: string
|
||||||
|
status: string
|
||||||
|
summary: string | null
|
||||||
|
content: string
|
||||||
|
}
|
||||||
|
|
||||||
|
type PublicPageViewProps = {
|
||||||
|
page: PageEntity
|
||||||
|
}
|
||||||
|
|
||||||
|
export function PublicPageView({ page }: PublicPageViewProps) {
|
||||||
|
return (
|
||||||
|
<article className="mx-auto flex w-full max-w-4xl flex-col gap-6 px-6 py-16">
|
||||||
|
<header className="space-y-3">
|
||||||
|
<p className="text-sm uppercase tracking-[0.2em] text-neutral-500">{page.status}</p>
|
||||||
|
<h1 className="text-4xl font-semibold tracking-tight">{page.title}</h1>
|
||||||
|
{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>
|
||||||
|
</article>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,19 +1,11 @@
|
|||||||
"use client"
|
import { listPublicNavigation } from "@cms/db"
|
||||||
|
|
||||||
import { useTranslations } from "next-intl"
|
|
||||||
|
|
||||||
import { Link } from "@/i18n/navigation"
|
import { Link } from "@/i18n/navigation"
|
||||||
|
|
||||||
import { LanguageSwitcher } from "./language-switcher"
|
import { LanguageSwitcher } from "./language-switcher"
|
||||||
|
|
||||||
export function PublicSiteHeader() {
|
export async function PublicSiteHeader() {
|
||||||
const t = useTranslations("Layout")
|
const navItems = await listPublicNavigation("header")
|
||||||
|
|
||||||
const navItems = [
|
|
||||||
{ href: "/", label: t("nav.home") },
|
|
||||||
{ href: "/about", label: t("nav.about") },
|
|
||||||
{ href: "/contact", label: t("nav.contact") },
|
|
||||||
]
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<header className="border-b border-neutral-200 bg-white/80 backdrop-blur">
|
<header className="border-b border-neutral-200 bg-white/80 backdrop-blur">
|
||||||
@@ -22,19 +14,28 @@ export function PublicSiteHeader() {
|
|||||||
href="/"
|
href="/"
|
||||||
className="text-sm font-semibold uppercase tracking-[0.2em] text-neutral-700"
|
className="text-sm font-semibold uppercase tracking-[0.2em] text-neutral-700"
|
||||||
>
|
>
|
||||||
{t("brand")}
|
CMS Web
|
||||||
</Link>
|
</Link>
|
||||||
|
|
||||||
<nav className="flex flex-wrap items-center gap-2">
|
<nav className="flex flex-wrap items-center gap-2">
|
||||||
{navItems.map((item) => (
|
{navItems.length === 0 ? (
|
||||||
<Link
|
<Link
|
||||||
key={item.href}
|
href="/"
|
||||||
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"
|
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}
|
Home
|
||||||
</Link>
|
</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>
|
</nav>
|
||||||
|
|
||||||
<LanguageSwitcher />
|
<LanguageSwitcher />
|
||||||
|
|||||||
40
packages/content/src/commissions.ts
Normal file
40
packages/content/src/commissions.ts
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import { z } from "zod"
|
||||||
|
|
||||||
|
export const commissionStatusSchema = z.enum([
|
||||||
|
"new",
|
||||||
|
"scoped",
|
||||||
|
"in_progress",
|
||||||
|
"review",
|
||||||
|
"done",
|
||||||
|
"canceled",
|
||||||
|
])
|
||||||
|
|
||||||
|
export const createCustomerInputSchema = z.object({
|
||||||
|
name: z.string().min(1).max(180),
|
||||||
|
email: z.string().email().max(320).nullable().optional(),
|
||||||
|
phone: z.string().max(80).nullable().optional(),
|
||||||
|
instagram: z.string().max(120).nullable().optional(),
|
||||||
|
notes: z.string().max(4000).nullable().optional(),
|
||||||
|
isRecurring: z.boolean().default(false),
|
||||||
|
})
|
||||||
|
|
||||||
|
export const createCommissionInputSchema = z.object({
|
||||||
|
title: z.string().min(1).max(180),
|
||||||
|
description: z.string().max(4000).nullable().optional(),
|
||||||
|
status: commissionStatusSchema.default("new"),
|
||||||
|
customerId: z.string().uuid().nullable().optional(),
|
||||||
|
assignedUserId: z.string().max(120).nullable().optional(),
|
||||||
|
budgetMin: z.number().nonnegative().nullable().optional(),
|
||||||
|
budgetMax: z.number().nonnegative().nullable().optional(),
|
||||||
|
dueAt: z.date().nullable().optional(),
|
||||||
|
})
|
||||||
|
|
||||||
|
export const updateCommissionStatusInputSchema = z.object({
|
||||||
|
id: z.string().uuid(),
|
||||||
|
status: commissionStatusSchema,
|
||||||
|
})
|
||||||
|
|
||||||
|
export type CommissionStatus = z.infer<typeof commissionStatusSchema>
|
||||||
|
export type CreateCustomerInput = z.infer<typeof createCustomerInputSchema>
|
||||||
|
export type CreateCommissionInput = z.infer<typeof createCommissionInputSchema>
|
||||||
|
export type UpdateCommissionStatusInput = z.infer<typeof updateCommissionStatusInputSchema>
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
|
export * from "./commissions"
|
||||||
export * from "./media"
|
export * from "./media"
|
||||||
|
export * from "./pages-navigation"
|
||||||
export * from "./rbac"
|
export * from "./rbac"
|
||||||
|
|
||||||
export const postStatusSchema = z.enum(["draft", "published"])
|
export const postStatusSchema = z.enum(["draft", "published"])
|
||||||
|
|||||||
57
packages/content/src/pages-navigation.ts
Normal file
57
packages/content/src/pages-navigation.ts
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
import { z } from "zod"
|
||||||
|
|
||||||
|
export const pageStatusSchema = z.enum(["draft", "published"])
|
||||||
|
|
||||||
|
export const createPageInputSchema = z.object({
|
||||||
|
title: z.string().min(1).max(180),
|
||||||
|
slug: z.string().min(1).max(180),
|
||||||
|
status: pageStatusSchema.default("draft"),
|
||||||
|
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 updatePageInputSchema = z.object({
|
||||||
|
id: z.string().uuid(),
|
||||||
|
title: z.string().min(1).max(180).optional(),
|
||||||
|
slug: z.string().min(1).max(180).optional(),
|
||||||
|
status: pageStatusSchema.optional(),
|
||||||
|
summary: z.string().max(500).nullable().optional(),
|
||||||
|
content: z.string().min(1).optional(),
|
||||||
|
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),
|
||||||
|
location: z.string().min(1).max(80).default("primary"),
|
||||||
|
isVisible: z.boolean().default(true),
|
||||||
|
})
|
||||||
|
|
||||||
|
export const createNavigationItemInputSchema = z.object({
|
||||||
|
menuId: z.string().uuid(),
|
||||||
|
label: z.string().min(1).max(180),
|
||||||
|
href: z.string().max(500).nullable().optional(),
|
||||||
|
pageId: z.string().uuid().nullable().optional(),
|
||||||
|
parentId: z.string().uuid().nullable().optional(),
|
||||||
|
sortOrder: z.number().int().min(0).default(0),
|
||||||
|
isVisible: z.boolean().default(true),
|
||||||
|
})
|
||||||
|
|
||||||
|
export const updateNavigationItemInputSchema = z.object({
|
||||||
|
id: z.string().uuid(),
|
||||||
|
label: z.string().min(1).max(180).optional(),
|
||||||
|
href: z.string().max(500).nullable().optional(),
|
||||||
|
pageId: z.string().uuid().nullable().optional(),
|
||||||
|
parentId: z.string().uuid().nullable().optional(),
|
||||||
|
sortOrder: z.number().int().min(0).optional(),
|
||||||
|
isVisible: z.boolean().optional(),
|
||||||
|
})
|
||||||
|
|
||||||
|
export type CreatePageInput = z.infer<typeof createPageInputSchema>
|
||||||
|
export type UpdatePageInput = z.infer<typeof updatePageInputSchema>
|
||||||
|
export type CreateNavigationMenuInput = z.infer<typeof createNavigationMenuInputSchema>
|
||||||
|
export type CreateNavigationItemInput = z.infer<typeof createNavigationItemInputSchema>
|
||||||
|
export type UpdateNavigationItemInput = z.infer<typeof updateNavigationItemInputSchema>
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE "Page" (
|
||||||
|
"id" TEXT NOT NULL,
|
||||||
|
"title" TEXT NOT NULL,
|
||||||
|
"slug" TEXT NOT NULL,
|
||||||
|
"status" TEXT NOT NULL,
|
||||||
|
"summary" TEXT,
|
||||||
|
"content" TEXT NOT NULL,
|
||||||
|
"seoTitle" TEXT,
|
||||||
|
"seoDescription" TEXT,
|
||||||
|
"publishedAt" TIMESTAMP(3),
|
||||||
|
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||||
|
|
||||||
|
CONSTRAINT "Page_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE "NavigationMenu" (
|
||||||
|
"id" TEXT NOT NULL,
|
||||||
|
"name" TEXT NOT NULL,
|
||||||
|
"slug" TEXT NOT NULL,
|
||||||
|
"location" TEXT NOT NULL,
|
||||||
|
"isVisible" BOOLEAN NOT NULL DEFAULT true,
|
||||||
|
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||||
|
|
||||||
|
CONSTRAINT "NavigationMenu_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE "NavigationItem" (
|
||||||
|
"id" TEXT NOT NULL,
|
||||||
|
"menuId" TEXT NOT NULL,
|
||||||
|
"pageId" TEXT,
|
||||||
|
"label" TEXT NOT NULL,
|
||||||
|
"href" TEXT,
|
||||||
|
"parentId" TEXT,
|
||||||
|
"sortOrder" INTEGER NOT NULL DEFAULT 0,
|
||||||
|
"isVisible" BOOLEAN NOT NULL DEFAULT true,
|
||||||
|
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||||
|
|
||||||
|
CONSTRAINT "NavigationItem_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE UNIQUE INDEX "Page_slug_key" ON "Page"("slug");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE INDEX "Page_status_idx" ON "Page"("status");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE UNIQUE INDEX "NavigationMenu_slug_key" ON "NavigationMenu"("slug");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE INDEX "NavigationItem_menuId_idx" ON "NavigationItem"("menuId");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE INDEX "NavigationItem_pageId_idx" ON "NavigationItem"("pageId");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE INDEX "NavigationItem_parentId_idx" ON "NavigationItem"("parentId");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE UNIQUE INDEX "NavigationItem_menuId_parentId_sortOrder_label_key" ON "NavigationItem"("menuId", "parentId", "sortOrder", "label");
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "NavigationItem" ADD CONSTRAINT "NavigationItem_menuId_fkey" FOREIGN KEY ("menuId") REFERENCES "NavigationMenu"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "NavigationItem" ADD CONSTRAINT "NavigationItem_pageId_fkey" FOREIGN KEY ("pageId") REFERENCES "Page"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "NavigationItem" ADD CONSTRAINT "NavigationItem_parentId_fkey" FOREIGN KEY ("parentId") REFERENCES "NavigationItem"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE "Customer" (
|
||||||
|
"id" TEXT NOT NULL,
|
||||||
|
"name" TEXT NOT NULL,
|
||||||
|
"email" TEXT,
|
||||||
|
"phone" TEXT,
|
||||||
|
"instagram" TEXT,
|
||||||
|
"notes" TEXT,
|
||||||
|
"isRecurring" BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||||
|
|
||||||
|
CONSTRAINT "Customer_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE "Commission" (
|
||||||
|
"id" TEXT NOT NULL,
|
||||||
|
"title" TEXT NOT NULL,
|
||||||
|
"description" TEXT,
|
||||||
|
"status" TEXT NOT NULL,
|
||||||
|
"customerId" TEXT,
|
||||||
|
"assignedUserId" TEXT,
|
||||||
|
"budgetMin" DOUBLE PRECISION,
|
||||||
|
"budgetMax" DOUBLE PRECISION,
|
||||||
|
"dueAt" TIMESTAMP(3),
|
||||||
|
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||||
|
|
||||||
|
CONSTRAINT "Commission_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE INDEX "Customer_email_idx" ON "Customer"("email");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE INDEX "Customer_isRecurring_idx" ON "Customer"("isRecurring");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE INDEX "Commission_status_idx" ON "Commission"("status");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE INDEX "Commission_customerId_idx" ON "Commission"("customerId");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE INDEX "Commission_assignedUserId_idx" ON "Commission"("assignedUserId");
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "Commission" ADD CONSTRAINT "Commission_customerId_fkey" FOREIGN KEY ("customerId") REFERENCES "Customer"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "Commission" ADD CONSTRAINT "Commission_assignedUserId_fkey" FOREIGN KEY ("assignedUserId") REFERENCES "user"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||||
@@ -34,6 +34,7 @@ model User {
|
|||||||
isProtected Boolean @default(false)
|
isProtected Boolean @default(false)
|
||||||
sessions Session[]
|
sessions Session[]
|
||||||
accounts Account[]
|
accounts Account[]
|
||||||
|
commissions Commission[] @relation("CommissionAssignee")
|
||||||
|
|
||||||
@@unique([email])
|
@@unique([email])
|
||||||
@@index([role])
|
@@index([role])
|
||||||
@@ -252,3 +253,89 @@ model ArtworkTag {
|
|||||||
@@unique([artworkId, tagId])
|
@@unique([artworkId, tagId])
|
||||||
@@index([tagId])
|
@@index([tagId])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
model Page {
|
||||||
|
id String @id @default(uuid())
|
||||||
|
title String
|
||||||
|
slug String @unique
|
||||||
|
status String
|
||||||
|
summary String?
|
||||||
|
content String
|
||||||
|
seoTitle String?
|
||||||
|
seoDescription String?
|
||||||
|
publishedAt DateTime?
|
||||||
|
createdAt DateTime @default(now())
|
||||||
|
updatedAt DateTime @updatedAt
|
||||||
|
navItems NavigationItem[]
|
||||||
|
|
||||||
|
@@index([status])
|
||||||
|
}
|
||||||
|
|
||||||
|
model NavigationMenu {
|
||||||
|
id String @id @default(uuid())
|
||||||
|
name String
|
||||||
|
slug String @unique
|
||||||
|
location String
|
||||||
|
isVisible Boolean @default(true)
|
||||||
|
createdAt DateTime @default(now())
|
||||||
|
updatedAt DateTime @updatedAt
|
||||||
|
items NavigationItem[]
|
||||||
|
}
|
||||||
|
|
||||||
|
model NavigationItem {
|
||||||
|
id String @id @default(uuid())
|
||||||
|
menuId String
|
||||||
|
pageId String?
|
||||||
|
label String
|
||||||
|
href String?
|
||||||
|
parentId String?
|
||||||
|
sortOrder Int @default(0)
|
||||||
|
isVisible Boolean @default(true)
|
||||||
|
createdAt DateTime @default(now())
|
||||||
|
updatedAt DateTime @updatedAt
|
||||||
|
menu NavigationMenu @relation(fields: [menuId], references: [id], onDelete: Cascade)
|
||||||
|
page Page? @relation(fields: [pageId], references: [id], onDelete: SetNull)
|
||||||
|
parent NavigationItem? @relation("NavigationItemParent", fields: [parentId], references: [id], onDelete: Cascade)
|
||||||
|
children NavigationItem[] @relation("NavigationItemParent")
|
||||||
|
|
||||||
|
@@index([menuId])
|
||||||
|
@@index([pageId])
|
||||||
|
@@index([parentId])
|
||||||
|
@@unique([menuId, parentId, sortOrder, label])
|
||||||
|
}
|
||||||
|
|
||||||
|
model Customer {
|
||||||
|
id String @id @default(uuid())
|
||||||
|
name String
|
||||||
|
email String?
|
||||||
|
phone String?
|
||||||
|
instagram String?
|
||||||
|
notes String?
|
||||||
|
isRecurring Boolean @default(false)
|
||||||
|
createdAt DateTime @default(now())
|
||||||
|
updatedAt DateTime @updatedAt
|
||||||
|
commissions Commission[]
|
||||||
|
|
||||||
|
@@index([email])
|
||||||
|
@@index([isRecurring])
|
||||||
|
}
|
||||||
|
|
||||||
|
model Commission {
|
||||||
|
id String @id @default(uuid())
|
||||||
|
title String
|
||||||
|
description String?
|
||||||
|
status String
|
||||||
|
customerId String?
|
||||||
|
assignedUserId String?
|
||||||
|
budgetMin Float?
|
||||||
|
budgetMax Float?
|
||||||
|
dueAt DateTime?
|
||||||
|
createdAt DateTime @default(now())
|
||||||
|
updatedAt DateTime @updatedAt
|
||||||
|
customer Customer? @relation(fields: [customerId], references: [id], onDelete: SetNull)
|
||||||
|
assignedUser User? @relation("CommissionAssignee", fields: [assignedUserId], references: [id], onDelete: SetNull)
|
||||||
|
|
||||||
|
@@index([status])
|
||||||
|
@@index([customerId])
|
||||||
|
@@index([assignedUserId])
|
||||||
|
}
|
||||||
|
|||||||
@@ -95,6 +95,117 @@ async function main() {
|
|||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const homePage = await db.page.upsert({
|
||||||
|
where: { slug: "home" },
|
||||||
|
update: {},
|
||||||
|
create: {
|
||||||
|
title: "Home",
|
||||||
|
slug: "home",
|
||||||
|
status: "published",
|
||||||
|
summary: "Default homepage seeded for pages/navigation baseline.",
|
||||||
|
content: "Welcome to your new artist CMS homepage.",
|
||||||
|
seoTitle: "Home",
|
||||||
|
seoDescription: "Seeded homepage",
|
||||||
|
publishedAt: new Date(),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const primaryMenu = await db.navigationMenu.upsert({
|
||||||
|
where: { slug: "primary" },
|
||||||
|
update: {},
|
||||||
|
create: {
|
||||||
|
name: "Primary",
|
||||||
|
slug: "primary",
|
||||||
|
location: "header",
|
||||||
|
isVisible: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const existingHomeItem = await db.navigationItem.findFirst({
|
||||||
|
where: {
|
||||||
|
menuId: primaryMenu.id,
|
||||||
|
parentId: null,
|
||||||
|
sortOrder: 0,
|
||||||
|
label: "Home",
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (existingHomeItem) {
|
||||||
|
await db.navigationItem.update({
|
||||||
|
where: {
|
||||||
|
id: existingHomeItem.id,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
pageId: homePage.id,
|
||||||
|
href: "/",
|
||||||
|
isVisible: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
await db.navigationItem.create({
|
||||||
|
data: {
|
||||||
|
menuId: primaryMenu.id,
|
||||||
|
label: "Home",
|
||||||
|
href: "/",
|
||||||
|
pageId: homePage.id,
|
||||||
|
parentId: null,
|
||||||
|
sortOrder: 0,
|
||||||
|
isVisible: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const existingCustomer = await db.customer.findFirst({
|
||||||
|
where: {
|
||||||
|
email: "collector@example.com",
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const seededCustomer = existingCustomer
|
||||||
|
? await db.customer.update({
|
||||||
|
where: {
|
||||||
|
id: existingCustomer.id,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
name: "Collector One",
|
||||||
|
phone: "+1-555-0101",
|
||||||
|
isRecurring: true,
|
||||||
|
notes: "Interested in recurring portrait commissions.",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
: await db.customer.create({
|
||||||
|
data: {
|
||||||
|
name: "Collector One",
|
||||||
|
email: "collector@example.com",
|
||||||
|
phone: "+1-555-0101",
|
||||||
|
isRecurring: true,
|
||||||
|
notes: "Interested in recurring portrait commissions.",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
await db.commission.upsert({
|
||||||
|
where: {
|
||||||
|
id: "11111111-1111-1111-1111-111111111111",
|
||||||
|
},
|
||||||
|
update: {},
|
||||||
|
create: {
|
||||||
|
id: "11111111-1111-1111-1111-111111111111",
|
||||||
|
title: "Portrait Commission Baseline",
|
||||||
|
description: "Initial seeded commission request for MVP1 board validation.",
|
||||||
|
status: "new",
|
||||||
|
customerId: seededCustomer.id,
|
||||||
|
budgetMin: 400,
|
||||||
|
budgetMax: 900,
|
||||||
|
dueAt: new Date(Date.now() + 14 * 24 * 60 * 60 * 1000),
|
||||||
|
},
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|||||||
64
packages/db/src/commissions.test.ts
Normal file
64
packages/db/src/commissions.test.ts
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
import { beforeEach, describe, expect, it, vi } from "vitest"
|
||||||
|
|
||||||
|
const { mockDb } = vi.hoisted(() => ({
|
||||||
|
mockDb: {
|
||||||
|
customer: {
|
||||||
|
create: vi.fn(),
|
||||||
|
findMany: vi.fn(),
|
||||||
|
},
|
||||||
|
commission: {
|
||||||
|
create: vi.fn(),
|
||||||
|
findMany: vi.fn(),
|
||||||
|
update: vi.fn(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
|
||||||
|
vi.mock("./client", () => ({
|
||||||
|
db: mockDb,
|
||||||
|
}))
|
||||||
|
|
||||||
|
import { createCommission, createCustomer, updateCommissionStatus } from "./commissions"
|
||||||
|
|
||||||
|
describe("commissions service", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
for (const value of Object.values(mockDb)) {
|
||||||
|
for (const fn of Object.values(value)) {
|
||||||
|
if (typeof fn === "function") {
|
||||||
|
fn.mockReset()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
it("creates customer and commission payloads", async () => {
|
||||||
|
mockDb.customer.create.mockResolvedValue({ id: "customer-1" })
|
||||||
|
mockDb.commission.create.mockResolvedValue({ id: "commission-1" })
|
||||||
|
|
||||||
|
await createCustomer({
|
||||||
|
name: "Ada Lovelace",
|
||||||
|
email: "ada@example.com",
|
||||||
|
isRecurring: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
await createCommission({
|
||||||
|
title: "Portrait Request",
|
||||||
|
status: "new",
|
||||||
|
customerId: "550e8400-e29b-41d4-a716-446655440000",
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(mockDb.customer.create).toHaveBeenCalledTimes(1)
|
||||||
|
expect(mockDb.commission.create).toHaveBeenCalledTimes(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("updates commission status", async () => {
|
||||||
|
mockDb.commission.update.mockResolvedValue({ id: "commission-1", status: "done" })
|
||||||
|
|
||||||
|
await updateCommissionStatus({
|
||||||
|
id: "550e8400-e29b-41d4-a716-446655440001",
|
||||||
|
status: "done",
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(mockDb.commission.update).toHaveBeenCalledTimes(1)
|
||||||
|
})
|
||||||
|
})
|
||||||
66
packages/db/src/commissions.ts
Normal file
66
packages/db/src/commissions.ts
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
import {
|
||||||
|
commissionStatusSchema,
|
||||||
|
createCommissionInputSchema,
|
||||||
|
createCustomerInputSchema,
|
||||||
|
updateCommissionStatusInputSchema,
|
||||||
|
} from "@cms/content"
|
||||||
|
|
||||||
|
import { db } from "./client"
|
||||||
|
|
||||||
|
export const commissionKanbanOrder = commissionStatusSchema.options
|
||||||
|
|
||||||
|
export async function listCustomers(limit = 200) {
|
||||||
|
return db.customer.findMany({
|
||||||
|
orderBy: [{ updatedAt: "desc" }],
|
||||||
|
take: limit,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createCustomer(input: unknown) {
|
||||||
|
const payload = createCustomerInputSchema.parse(input)
|
||||||
|
|
||||||
|
return db.customer.create({
|
||||||
|
data: payload,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function listCommissions(limit = 300) {
|
||||||
|
return db.commission.findMany({
|
||||||
|
orderBy: [{ updatedAt: "desc" }],
|
||||||
|
take: limit,
|
||||||
|
include: {
|
||||||
|
customer: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
name: true,
|
||||||
|
email: true,
|
||||||
|
isRecurring: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
assignedUser: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
name: true,
|
||||||
|
username: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createCommission(input: unknown) {
|
||||||
|
const payload = createCommissionInputSchema.parse(input)
|
||||||
|
|
||||||
|
return db.commission.create({
|
||||||
|
data: payload,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updateCommissionStatus(input: unknown) {
|
||||||
|
const payload = updateCommissionStatusInputSchema.parse(input)
|
||||||
|
|
||||||
|
return db.commission.update({
|
||||||
|
where: { id: payload.id },
|
||||||
|
data: { status: payload.status },
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -1,4 +1,12 @@
|
|||||||
export { db } from "./client"
|
export { db } from "./client"
|
||||||
|
export {
|
||||||
|
commissionKanbanOrder,
|
||||||
|
createCommission,
|
||||||
|
createCustomer,
|
||||||
|
listCommissions,
|
||||||
|
listCustomers,
|
||||||
|
updateCommissionStatus,
|
||||||
|
} from "./commissions"
|
||||||
export {
|
export {
|
||||||
attachArtworkRendition,
|
attachArtworkRendition,
|
||||||
createAlbum,
|
createAlbum,
|
||||||
@@ -16,6 +24,22 @@ export {
|
|||||||
listMediaFoundationGroups,
|
listMediaFoundationGroups,
|
||||||
updateMediaAsset,
|
updateMediaAsset,
|
||||||
} from "./media-foundation"
|
} from "./media-foundation"
|
||||||
|
export type { PublicNavigationItem } from "./pages-navigation"
|
||||||
|
export {
|
||||||
|
createNavigationItem,
|
||||||
|
createNavigationMenu,
|
||||||
|
createPage,
|
||||||
|
deleteNavigationItem,
|
||||||
|
deletePage,
|
||||||
|
getPageById,
|
||||||
|
getPublishedPageBySlug,
|
||||||
|
listNavigationMenus,
|
||||||
|
listPages,
|
||||||
|
listPublicNavigation,
|
||||||
|
listPublishedPageSlugs,
|
||||||
|
updateNavigationItem,
|
||||||
|
updatePage,
|
||||||
|
} from "./pages-navigation"
|
||||||
export {
|
export {
|
||||||
createPost,
|
createPost,
|
||||||
deletePost,
|
deletePost,
|
||||||
|
|||||||
123
packages/db/src/pages-navigation.test.ts
Normal file
123
packages/db/src/pages-navigation.test.ts
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
import { beforeEach, describe, expect, it, vi } from "vitest"
|
||||||
|
|
||||||
|
const { mockDb } = vi.hoisted(() => ({
|
||||||
|
mockDb: {
|
||||||
|
page: {
|
||||||
|
create: vi.fn(),
|
||||||
|
update: vi.fn(),
|
||||||
|
delete: vi.fn(),
|
||||||
|
findUnique: vi.fn(),
|
||||||
|
findMany: vi.fn(),
|
||||||
|
},
|
||||||
|
navigationMenu: {
|
||||||
|
create: vi.fn(),
|
||||||
|
findMany: vi.fn(),
|
||||||
|
findFirst: vi.fn(),
|
||||||
|
},
|
||||||
|
navigationItem: {
|
||||||
|
create: vi.fn(),
|
||||||
|
update: vi.fn(),
|
||||||
|
delete: vi.fn(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
|
||||||
|
vi.mock("./client", () => ({
|
||||||
|
db: mockDb,
|
||||||
|
}))
|
||||||
|
|
||||||
|
import {
|
||||||
|
createNavigationItem,
|
||||||
|
createNavigationMenu,
|
||||||
|
createPage,
|
||||||
|
listPublicNavigation,
|
||||||
|
updatePage,
|
||||||
|
} from "./pages-navigation"
|
||||||
|
|
||||||
|
describe("pages-navigation service", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
for (const value of Object.values(mockDb)) {
|
||||||
|
for (const fn of Object.values(value)) {
|
||||||
|
if (typeof fn === "function") {
|
||||||
|
fn.mockReset()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
it("creates published pages with publishedAt", async () => {
|
||||||
|
mockDb.page.create.mockResolvedValue({ id: "page-1" })
|
||||||
|
|
||||||
|
await createPage({
|
||||||
|
title: "About",
|
||||||
|
slug: "about",
|
||||||
|
status: "published",
|
||||||
|
content: "hello",
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(mockDb.page.create).toHaveBeenCalledTimes(1)
|
||||||
|
expect(mockDb.page.create.mock.calls[0]?.[0].data.publishedAt).toBeInstanceOf(Date)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("updates page status publication timestamp", async () => {
|
||||||
|
mockDb.page.update.mockResolvedValue({ id: "page-1" })
|
||||||
|
|
||||||
|
await updatePage({
|
||||||
|
id: "550e8400-e29b-41d4-a716-446655440000",
|
||||||
|
status: "draft",
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(mockDb.page.update).toHaveBeenCalledTimes(1)
|
||||||
|
expect(mockDb.page.update.mock.calls[0]?.[0].data.publishedAt).toBeNull()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("creates menus and items with schema parsing", async () => {
|
||||||
|
mockDb.navigationMenu.create.mockResolvedValue({ id: "menu-1" })
|
||||||
|
mockDb.navigationItem.create.mockResolvedValue({ id: "item-1" })
|
||||||
|
|
||||||
|
await createNavigationMenu({
|
||||||
|
name: "Primary",
|
||||||
|
slug: "primary",
|
||||||
|
location: "header",
|
||||||
|
})
|
||||||
|
|
||||||
|
await createNavigationItem({
|
||||||
|
menuId: "550e8400-e29b-41d4-a716-446655440001",
|
||||||
|
label: "Home",
|
||||||
|
href: "/",
|
||||||
|
sortOrder: 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(mockDb.navigationMenu.create).toHaveBeenCalledTimes(1)
|
||||||
|
expect(mockDb.navigationItem.create).toHaveBeenCalledTimes(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("maps public navigation href from linked pages", async () => {
|
||||||
|
mockDb.navigationMenu.findFirst.mockResolvedValue({
|
||||||
|
id: "menu-1",
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
id: "item-1",
|
||||||
|
label: "Home",
|
||||||
|
href: null,
|
||||||
|
parentId: null,
|
||||||
|
page: {
|
||||||
|
slug: "home",
|
||||||
|
status: "published",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
const navigation = await listPublicNavigation("header")
|
||||||
|
|
||||||
|
expect(navigation).toEqual([
|
||||||
|
{
|
||||||
|
id: "item-1",
|
||||||
|
label: "Home",
|
||||||
|
href: "/",
|
||||||
|
children: [],
|
||||||
|
},
|
||||||
|
])
|
||||||
|
})
|
||||||
|
})
|
||||||
240
packages/db/src/pages-navigation.ts
Normal file
240
packages/db/src/pages-navigation.ts
Normal file
@@ -0,0 +1,240 @@
|
|||||||
|
import {
|
||||||
|
createNavigationItemInputSchema,
|
||||||
|
createNavigationMenuInputSchema,
|
||||||
|
createPageInputSchema,
|
||||||
|
updateNavigationItemInputSchema,
|
||||||
|
updatePageInputSchema,
|
||||||
|
} from "@cms/content"
|
||||||
|
|
||||||
|
import { db } from "./client"
|
||||||
|
|
||||||
|
export type PublicNavigationItem = {
|
||||||
|
id: string
|
||||||
|
label: string
|
||||||
|
href: string
|
||||||
|
children: PublicNavigationItem[]
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolvePublishedAt(status: string): Date | null {
|
||||||
|
return status === "published" ? new Date() : null
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function listPages(limit = 50) {
|
||||||
|
return db.page.findMany({
|
||||||
|
orderBy: [{ updatedAt: "desc" }],
|
||||||
|
take: limit,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function listPublishedPageSlugs() {
|
||||||
|
const pages = await db.page.findMany({
|
||||||
|
where: { status: "published" },
|
||||||
|
orderBy: { updatedAt: "desc" },
|
||||||
|
select: {
|
||||||
|
slug: true,
|
||||||
|
updatedAt: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
return pages
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getPageById(id: string) {
|
||||||
|
return db.page.findUnique({
|
||||||
|
where: { id },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getPublishedPageBySlug(slug: string) {
|
||||||
|
return db.page.findFirst({
|
||||||
|
where: {
|
||||||
|
slug,
|
||||||
|
status: "published",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createPage(input: unknown) {
|
||||||
|
const payload = createPageInputSchema.parse(input)
|
||||||
|
|
||||||
|
return db.page.create({
|
||||||
|
data: {
|
||||||
|
...payload,
|
||||||
|
publishedAt: resolvePublishedAt(payload.status),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updatePage(input: unknown) {
|
||||||
|
const payload = updatePageInputSchema.parse(input)
|
||||||
|
const { id, ...data } = payload
|
||||||
|
|
||||||
|
return db.page.update({
|
||||||
|
where: { id },
|
||||||
|
data: {
|
||||||
|
...data,
|
||||||
|
publishedAt:
|
||||||
|
data.status === undefined ? undefined : data.status === "published" ? new Date() : null,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function deletePage(id: string) {
|
||||||
|
return db.page.delete({
|
||||||
|
where: { id },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function listNavigationMenus() {
|
||||||
|
return db.navigationMenu.findMany({
|
||||||
|
orderBy: [{ location: "asc" }, { name: "asc" }],
|
||||||
|
include: {
|
||||||
|
items: {
|
||||||
|
orderBy: [{ sortOrder: "asc" }, { label: "asc" }],
|
||||||
|
include: {
|
||||||
|
page: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
title: true,
|
||||||
|
slug: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolveNavigationHref(item: {
|
||||||
|
href: string | null
|
||||||
|
page: {
|
||||||
|
slug: string
|
||||||
|
status: string
|
||||||
|
} | null
|
||||||
|
}): string | null {
|
||||||
|
if (item.href) {
|
||||||
|
return item.href
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item.page?.status === "published") {
|
||||||
|
return item.page.slug === "home" ? "/" : `/${item.page.slug}`
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function listPublicNavigation(location = "header"): Promise<PublicNavigationItem[]> {
|
||||||
|
const menu = await db.navigationMenu.findFirst({
|
||||||
|
where: {
|
||||||
|
location,
|
||||||
|
isVisible: true,
|
||||||
|
},
|
||||||
|
orderBy: { updatedAt: "desc" },
|
||||||
|
include: {
|
||||||
|
items: {
|
||||||
|
where: {
|
||||||
|
isVisible: true,
|
||||||
|
},
|
||||||
|
orderBy: [{ sortOrder: "asc" }, { label: "asc" }],
|
||||||
|
include: {
|
||||||
|
page: {
|
||||||
|
select: {
|
||||||
|
slug: true,
|
||||||
|
status: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!menu) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
const itemMap = new Map<
|
||||||
|
string,
|
||||||
|
{
|
||||||
|
id: string
|
||||||
|
label: string
|
||||||
|
href: string
|
||||||
|
parentId: string | null
|
||||||
|
children: PublicNavigationItem[]
|
||||||
|
}
|
||||||
|
>()
|
||||||
|
|
||||||
|
for (const item of menu.items) {
|
||||||
|
const href = resolveNavigationHref(item)
|
||||||
|
|
||||||
|
if (!href) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
itemMap.set(item.id, {
|
||||||
|
id: item.id,
|
||||||
|
label: item.label,
|
||||||
|
href,
|
||||||
|
parentId: item.parentId,
|
||||||
|
children: [],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const roots: PublicNavigationItem[] = []
|
||||||
|
|
||||||
|
for (const entry of itemMap.values()) {
|
||||||
|
if (entry.parentId) {
|
||||||
|
const parent = itemMap.get(entry.parentId)
|
||||||
|
|
||||||
|
if (parent) {
|
||||||
|
parent.children.push({
|
||||||
|
id: entry.id,
|
||||||
|
label: entry.label,
|
||||||
|
href: entry.href,
|
||||||
|
children: entry.children,
|
||||||
|
})
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
roots.push({
|
||||||
|
id: entry.id,
|
||||||
|
label: entry.label,
|
||||||
|
href: entry.href,
|
||||||
|
children: entry.children,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return roots
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createNavigationMenu(input: unknown) {
|
||||||
|
const payload = createNavigationMenuInputSchema.parse(input)
|
||||||
|
|
||||||
|
return db.navigationMenu.create({
|
||||||
|
data: payload,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createNavigationItem(input: unknown) {
|
||||||
|
const payload = createNavigationItemInputSchema.parse(input)
|
||||||
|
|
||||||
|
return db.navigationItem.create({
|
||||||
|
data: payload,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updateNavigationItem(input: unknown) {
|
||||||
|
const payload = updateNavigationItemInputSchema.parse(input)
|
||||||
|
const { id, ...data } = payload
|
||||||
|
|
||||||
|
return db.navigationItem.update({
|
||||||
|
where: { id },
|
||||||
|
data,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function deleteNavigationItem(id: string) {
|
||||||
|
return db.navigationItem.delete({
|
||||||
|
where: { id },
|
||||||
|
})
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user