Skip to content

Commit

Permalink
fix(AddRequirement): transform requirement data before parsing (#1367)
Browse files Browse the repository at this point in the history
  • Loading branch information
BrickheadJohnny authored Jul 10, 2024
1 parent 767172e commit 4bfb9a2
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4bfb9a2

Please sign in to comment.