From 4bfb9a2ca6558c2638c2f8c92f834836da887fdb Mon Sep 17 00:00:00 2001 From: BrickheadJohnny <92519134+BrickheadJohnny@users.noreply.github.com> Date: Wed, 10 Jul 2024 15:38:55 +0200 Subject: [PATCH] fix(AddRequirement): transform requirement data before parsing (#1367) --- .../Requirements/components/AddRequirement.tsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/components/create-guild/Requirements/components/AddRequirement.tsx b/src/components/create-guild/Requirements/components/AddRequirement.tsx index 1405576123..fd1534d538 100644 --- a/src/components/create-guild/Requirements/components/AddRequirement.tsx +++ b/src/components/create-guild/Requirements/components/AddRequirement.tsx @@ -48,6 +48,7 @@ import { } from "requirements/requirementProvidedValues" import { RequirementType } from "requirements/types" import { Requirement } from "types" +import preprocessRequirement from "utils/preprocessRequirement" import useCreateRequirement from "../hooks/useCreateRequirement" import BalancyFooter from "./BalancyFooter" import IsNegatedPicker from "./IsNegatedPicker" @@ -242,10 +243,19 @@ const AddRequirementForm = forwardRef( const { type, ...requirementData } = data - const requirement = schemas.RequirementCreationPayloadSchema.parse({ - type: type ?? selectedType, + /** + * TODO: This was a quick solution to avoid Zod errors when submitting a + * CONTRACT requirement. The type of data.params is {value: number}[] on our + * frontend, but it's just a simple number array in the schema. We should fix + * this and make sure to not use preprocessRequirements. + */ + const preprocessedRequirement = preprocessRequirement({ + type: (type ?? selectedType) as any, ...requirementData, }) + const requirement = schemas.RequirementCreationPayloadSchema.parse( + preprocessedRequirement + ) if (!roleId) { onAdd?.(requirement)