diff --git a/src/app/admin/polls/poll-form.tsx b/src/app/admin/polls/poll-form.tsx index 98883888..c61681ac 100644 --- a/src/app/admin/polls/poll-form.tsx +++ b/src/app/admin/polls/poll-form.tsx @@ -17,17 +17,27 @@ import { import { Switch } from "@/components/ui/switch"; import { Textarea } from "@/components/ui/textarea"; import { useServerAction } from "@/hooks/use-server-action"; -import type { CreatePollInput } from "@/lib/validators/poll"; +import type { CreatePollInput, UpdatePollInput } from "@/lib/validators/poll"; interface PollFormProps { defaultValues?: Partial & { id?: number }; } +interface PollFormValues { + title: string; + description: string | null; + status: string; + showResults: number; + multipleChoice: number; + startsAt?: Date | null; + endsAt?: Date | null; +} + export function PollForm({ defaultValues }: PollFormProps) { const { run, isPending } = useServerAction(); const isEditing = !!defaultValues?.id; - const form = useForm({ + const form = useForm({ defaultValues: { title: "", description: "", @@ -38,14 +48,13 @@ export function PollForm({ defaultValues }: PollFormProps) { }, }); - // biome-ignore lint/suspicious/noExplicitAny: explicitly chosen here, see surrounding code - function onSubmit(data: any) { + function onSubmit(data: PollFormValues) { if (isEditing) { - run(() => updatePoll({ id: defaultValues!.id, ...data }), { + run(() => updatePoll({ id: defaultValues!.id, ...data } as UpdatePollInput), { successMessage: "Poll updated!", }); } else { - run(() => createPoll(data), { + run(() => createPoll(data as CreatePollInput), { successMessage: "Poll created!", onSuccess: (result) => { const data = result.data as Record | undefined; @@ -106,9 +115,8 @@ export function PollForm({ defaultValues }: PollFormProps) { - form.setValue("startsAt", d as any, { shouldDirty: true }) + form.setValue("startsAt", d, { shouldDirty: true }) } placeholder="Select start date" /> @@ -117,9 +125,8 @@ export function PollForm({ defaultValues }: PollFormProps) { - form.setValue("endsAt", d as any, { shouldDirty: true }) + form.setValue("endsAt", d, { shouldDirty: true }) } placeholder="Select end date" />