feat(form): show response totals and queue numbers

This commit is contained in:
2026-07-26 15:54:20 +07:00 Unverified
parent 1b58d2c363
commit 73bd6ef5d2
6 changed files with 148 additions and 10 deletions
+14 -4
View File
@@ -10,6 +10,7 @@ import {
decodeCheckboxAnswer,
type FormAnswerValue,
} from "@/lib/form-answer-values";
import { getFormSubmissionStats } from "@/lib/form-submission-stats";
export const dynamic = "force-dynamic";
@@ -43,10 +44,17 @@ export default async function FormsSubmitPage(
orderBy: (q, { asc }) => [asc(q.displayOrder)],
});
const existingSubmission = await db.query.submissions.findFirst({
where: (s, { eq, and }) =>
and(eq(s.formId, form.id), eq(s.userDiscordId, discordId)),
});
const [existingSubmission, submissionStats] = await Promise.all([
db.query.submissions.findFirst({
where: (s, { eq, and }) =>
and(eq(s.formId, form.id), eq(s.userDiscordId, discordId)),
}),
getFormSubmissionStats([form.id], discordId),
]);
const stats = submissionStats.get(form.id) ?? {
totalAnswers: 0,
queueNumber: null,
};
const initialAnswers: Record<string, FormAnswerValue> = {};
if (existingSubmission) {
@@ -71,6 +79,8 @@ export default async function FormsSubmitPage(
questions={questionsList}
initialAnswers={initialAnswers}
hasSubmission={Boolean(existingSubmission)}
totalAnswers={stats.totalAnswers}
queueNumber={stats.queueNumber}
/>
</div>
</>