From 907a4399d05d9643acc8ff9a8e833a7387d4dbb5 Mon Sep 17 00:00:00 2001 From: openhands Date: Sat, 18 Jul 2026 20:18:32 +0200 Subject: [PATCH] refactor: type PollQuestionsManager form with PollQuestionInput --- src/app/admin/polls/[id]/poll-questions.tsx | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/app/admin/polls/[id]/poll-questions.tsx b/src/app/admin/polls/[id]/poll-questions.tsx index 0380f5ee..15b7f16b 100644 --- a/src/app/admin/polls/[id]/poll-questions.tsx +++ b/src/app/admin/polls/[id]/poll-questions.tsx @@ -19,6 +19,7 @@ import { SelectValue, } from "@/components/ui/select"; import { useServerAction } from "@/hooks/use-server-action"; +import type { PollQuestionInput } from "@/lib/validators/poll"; interface Question { id: number; @@ -33,11 +34,14 @@ interface Props { questions: Question[]; } +type PollQuestionUpdateInput = PollQuestionInput & { id: number }; + export function PollQuestionsManager({ pollId, questions }: Props) { const { run, isPending } = useServerAction(); const [showForm, setShowForm] = useState(false); const [editingId, setEditingId] = useState(null); - const [form, setForm] = useState({ + const [form, setForm] = useState({ + pollId, question: "", type: "single", sortOrder: questions.length, @@ -46,6 +50,7 @@ export function PollQuestionsManager({ pollId, questions }: Props) { function resetForm() { setForm({ + pollId, question: "", type: "single", sortOrder: questions.length, @@ -57,8 +62,9 @@ export function PollQuestionsManager({ pollId, questions }: Props) { function handleEdit(q: Question) { setForm({ + pollId, question: q.question, - type: q.type, + type: q.type as PollQuestionInput["type"], sortOrder: q.sortOrder, options: q.options, }); @@ -69,13 +75,11 @@ export function PollQuestionsManager({ pollId, questions }: Props) { function handleSubmit(e: React.FormEvent) { e.preventDefault(); if (editingId) { - // biome-ignore lint/suspicious/noExplicitAny: explicitly chosen here, see surrounding code - run(() => updatePollQuestion({ id: editingId, ...form } as any), { + run(() => updatePollQuestion({ id: editingId, ...form } as PollQuestionUpdateInput), { successMessage: "Question updated!", }); } else { - // biome-ignore lint/suspicious/noExplicitAny: explicitly chosen here, see surrounding code - run(() => addPollQuestion({ pollId, ...form } as any), { + run(() => addPollQuestion(form), { successMessage: "Question added!", }); } @@ -115,7 +119,9 @@ export function PollQuestionsManager({ pollId, questions }: Props) {