40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { db } from "@/db";
|
|
import { forms } from "@/db/schema";
|
|
import FormEditorClient from "./client";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
export default async function AdminDashboardPage() {
|
|
let form = await db.query.forms.findFirst();
|
|
if (!form) {
|
|
const [newForm] = await db
|
|
.insert(forms)
|
|
.values({
|
|
title: "Erika Custom Form",
|
|
description: "Welcome! Please fill out the form below.",
|
|
})
|
|
.returning();
|
|
form = newForm;
|
|
}
|
|
|
|
const questionsList = await db.query.questions.findMany({
|
|
where: (q, { eq }) => eq(q.formId, form.id),
|
|
orderBy: (q, { asc }) => [asc(q.displayOrder)],
|
|
});
|
|
|
|
return (
|
|
<div className="space-y-6 max-w-4xl mx-auto pb-12">
|
|
<div className="flex items-center justify-between">
|
|
<div>
|
|
<h1 className="text-3xl font-bold tracking-tight">Admin Dashboard</h1>
|
|
<p className="text-muted-foreground mt-1">
|
|
Customize form settings, add/edit questions, or upload images.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<FormEditorClient form={form} initialQuestions={questionsList} />
|
|
</div>
|
|
);
|
|
}
|