since3-portal/app/admin/templates/[id]/page.tsx
2026-10-05 08:23:02 +02:00

34 lines
1.5 KiB
TypeScript

import { notFound, redirect } from "next/navigation"
import { verifySession } from "@/lib/supabase/dal"
import { getClients } from "@/modules/admin/queries/clients"
import { resolveContent } from "@/modules/templates/lib/content"
import { shareState } from "@/modules/templates/lib/preview"
import { getTemplate } from "@/modules/templates/lib/registry"
import { getVariant } from "@/modules/templates/queries/variants"
import { VariantEditor } from "@/modules/templates/ui/views/variant-editor"
export default async function VariantEditorPage({ params }: PageProps<"/admin/templates/[id]">) {
const session = await verifySession()
if (!session.isAdmin) redirect("/client/dashboard")
const { id } = await params
const [variant, clients] = await Promise.all([getVariant(id), getClients()])
const def = variant ? getTemplate(variant.template_key) : undefined
if (!variant || !def) notFound()
return (
<VariantEditor
variant={{
id: variant.id,
name: variant.name,
templateKey: def.key,
clientId: variant.client_id,
content: resolveContent(def, variant.content),
shareToken: variant.share_token,
shareExpiresAt: variant.share_expires_at,
shareState: shareState(variant.share_token, variant.share_expires_at),
}}
clients={clients.map(({ id, name }) => ({ id, name }))}
/>
)
}