Hotfix/Event Type Save Error with Multiple Durations#6154
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
hariombalhara
left a comment
There was a problem hiding this comment.
Self review done
| onChange={(e) => { | ||
| formMethods.setValue("length", Number(e.target.value)); | ||
| }} | ||
| {...formMethods.register("length")} |
There was a problem hiding this comment.
Use standard RHF approach. This ensures that length is defined without onChange as well. But it causes length to be become a string and tRPC requires it to be a number. That has been handled by introducing zodResolver and adding a string to number transform.
Recent duration-related code checks length and it is undefined if onchange hasn't occurred.
I could have fixed the duration code as well, but it seems unintuitive to have length be undefined.
| selectedMultipleDuration.find((opt) => opt.value === option?.value) ?? null | ||
| ); | ||
| formMethods.setValue("length", Number(option?.value)); | ||
| formMethods.setValue("length", option?.value); |
There was a problem hiding this comment.
It was already a number here, because it is picked from options[number].value which is a number.
| .object({ | ||
| // Length if string, is converted to a number or it can be a number | ||
| // Make it optional because it's not submitted from all tabs of the page | ||
| length: z.union([z.string().transform((val) => +val), z.number()]).optional(), |
There was a problem hiding this comment.
In Multiple durations case, it is already a number. In single duration case, it is a string and thus requires conversion to number.
What does this PR do?
Fixes # (issue)
See loom
Environment: Production
Type of change