Skip to content

Commit

Permalink
added multiple choice tally field
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsrehtanz committed Apr 21, 2024
1 parent 4b2918d commit 6ca0530
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion components/application/applicationField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const ApplicationValue = ({ field }: ApplicationFieldProps) => {
</div>
);

case "DROPDOWN" || "MULTIPLE_CHOICE":
case "DROPDOWN":
const value = field.options?.find((opt) => opt.id === field.value?.at(0));
if (value) {
return (
Expand All @@ -89,6 +89,16 @@ const ApplicationValue = ({ field }: ApplicationFieldProps) => {
);
}

case "MULTIPLE_CHOICE":
const selected_value = field.options?.find(
(opt) => opt.id === field.value?.at(0),
);
if (selected_value) {
return <p>{selected_value.text}</p>;
}

return <p>No value</p>;

case "TEXTAREA":
return <Textarea value={field.value} />;

Expand Down
2 changes: 1 addition & 1 deletion lib/schemas/tally.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const TallyCheckboxes = z.object({

const TallyMultipleChoice = z.object({
type: z.literal("MULTIPLE_CHOICE"),
value: z.union([z.boolean(), z.string().uuid()]),
value: z.array(z.string().uuid()).nullable(),
options: z.array(z.object({ id: z.string(), text: z.string() })).optional(),
});

Expand Down

0 comments on commit 6ca0530

Please sign in to comment.