42 lines
1018 B
TypeScript
42 lines
1018 B
TypeScript
import { db } from "@/db";
|
|
import FormEditorClient from "./client";
|
|
import { notFound } from "next/navigation";
|
|
import { RealtimeRefresh } from "@/components/realtime-refresh";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
export default async function AdminDashboardPage(
|
|
props: {
|
|
params: Promise<{ id: string }>;
|
|
}
|
|
) {
|
|
const params = await props.params;
|
|
const form = await db.query.forms.findFirst({
|
|
where: (f, { eq }) => eq(f.id, params.id),
|
|
});
|
|
|
|
if (!form) {
|
|
return notFound();
|
|
}
|
|
|
|
const questionsList = await db.query.questions.findMany({
|
|
where: (q, { eq }) => eq(q.formId, form.id),
|
|
orderBy: (q, { asc }) => [asc(q.displayOrder)],
|
|
});
|
|
|
|
return (
|
|
<>
|
|
<RealtimeRefresh topic="forms" formId={form.id} />
|
|
<div className="w-full p-4 pb-12 md:p-6">
|
|
<FormEditorClient
|
|
form={{
|
|
...form,
|
|
closesAt: form.closesAt?.toISOString() ?? null,
|
|
}}
|
|
initialQuestions={questionsList}
|
|
/>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|