From 7e2ffd8d2b1fab3cce1e4c9d79be37d8186cc51c Mon Sep 17 00:00:00 2001 From: Luke Vella Date: Sat, 3 Aug 2024 22:16:11 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20crash=20when=20options=20c?= =?UTF-8?q?hange=20mid=20voting=20(#1239)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../poll/desktop-poll/participant-row-form.tsx | 4 ++-- apps/web/src/components/poll/voting-form.tsx | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/apps/web/src/components/poll/desktop-poll/participant-row-form.tsx b/apps/web/src/components/poll/desktop-poll/participant-row-form.tsx index f67eb4b38..71277c59f 100644 --- a/apps/web/src/components/poll/desktop-poll/participant-row-form.tsx +++ b/apps/web/src/components/poll/desktop-poll/participant-row-form.tsx @@ -111,13 +111,13 @@ const ParticipantRowForm = ({ onClick={() => { field.onChange({ optionId, - type: toggleVote(field.value.type), + type: toggleVote(field.value?.type), }); }} className="absolute inset-0 flex cursor-pointer items-center justify-center hover:bg-gray-100 active:bg-gray-200/50 active:ring-1 active:ring-inset active:ring-gray-200" > { field.onChange({ optionId, type: vote }); }} diff --git a/apps/web/src/components/poll/voting-form.tsx b/apps/web/src/components/poll/voting-form.tsx index 6e22e8969..9ab886839 100644 --- a/apps/web/src/components/poll/voting-form.tsx +++ b/apps/web/src/components/poll/voting-form.tsx @@ -24,10 +24,12 @@ const formSchema = z.object({ mode: z.enum(["new", "edit", "view"]), participantId: z.string().optional(), votes: z.array( - z.object({ - optionId: z.string(), - type: z.enum(["yes", "no", "ifNeedBe"]).optional(), - }), + z + .object({ + optionId: z.string(), + type: z.enum(["yes", "no", "ifNeedBe"]).optional(), + }) + .optional(), ), });