feat(form): show response totals and queue numbers
This commit is contained in:
+14
-4
@@ -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>
|
||||
</>
|
||||
|
||||
Reference in New Issue
Block a user