-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(actions): Updating action template and forms content #322
Conversation
if (addDataConditions?.length) { | ||
const errors = addDataConditions | ||
.map((fn) => fn(data)) | ||
.filter((err) => err) // Filter out nulls | ||
.map((err) => err?.message); | ||
if (errors.length) | ||
throw Error(`Additional conditions were not met: ${errors}`); | ||
} | ||
// TODO: Type update for submit generic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced by ZodObject.superRefine
, see below
.superRefine((val, ctx) => { | ||
if ( | ||
!val.attachments.supportingDocumentation?.length && | ||
val.additionalInformation === undefined | ||
) { | ||
ctx.addIssue({ | ||
message: "An Attachment or Additional Information is required.", | ||
code: z.ZodIssueCode.custom, | ||
fatal: true, | ||
}); | ||
// Zod says this is to appease types | ||
// https://github.com/colinhacks/zod?tab=readme-ov-file#type-refinements | ||
return z.NEVER; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The superRefine
method adds an issue to zod's context via ctx.addIssue
, and it displays here
<DetailsSection id="package-details" title="Medicaid Package Details"> | ||
<DetailsSection | ||
id="package-details" | ||
title={`${data._source.planType} Package Details`} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dynamic titling on Details page: "CHIP SPA Package Details", "Medicaid SPA Package Details", ...
@@ -36,5 +36,4 @@ export const zAttachmentRequired = ({ | |||
|
|||
export const zAdditionalInfo = z | |||
.string() | |||
.max(4000, "This field may only be up to 4000 characters.") | |||
.optional(); | |||
.max(4000, "This field may only be up to 4000 characters."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaving .optional()
up to each schema instead of pre-defining in zod variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all looks good to me. I'll defer approval to someone else, so there's more eyes on it. I recommend not merging until after the 1130 demo this (wed) morning.
import { AttachmentRecipe } from "@/lib"; | ||
|
||
export type FormSetup = { | ||
schema: ZodObject<any>; | ||
schema: ZodObject<any> | ZodEffects<any>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I was just curious what ZodEffects are. Is this for the super refine business
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, ZodEffects is the return type of superRefine
so I plugged it in as a union here :)
|
||
export const defaultIssueRaiSetup = { | ||
schema: z.object({ | ||
additionalInformation: z.string().max(4000), | ||
additionalInformation: zAdditionalInfo, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good reuse opportunity there with additional information. It will also lead to better consistency across the board I bet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep! Merging submission forms into the same pattern will also help consolidate things.
.superRefine((val, ctx) => { | ||
if ( | ||
!val.attachments.supportingDocumentation?.length && | ||
val.additionalInformation === undefined | ||
) { | ||
ctx.addIssue({ | ||
message: "An Attachment or Additional Information is required.", | ||
code: z.ZodIssueCode.custom, | ||
fatal: true, | ||
}); | ||
// Zod says this is to appease types | ||
// https://github.com/colinhacks/zod?tab=readme-ov-file#type-refinements | ||
return z.NEVER; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is truly an amazing find. I have nothing bad to say. The ability to keep our validations all in one place will, one speed up the app, but also make it much simpler
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Left one minor change request. Curious on your thoughts
🎉 This PR is included in version 1.5.0-val.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Purpose
This PR makes content fixes/updates to Action forms, particularly the Additional Info instructions. Additionally, it refactors our approach to use zod's
superRefine
rather than our bespoke submission conditions.Linked Issues to Close
https://qmacbis.atlassian.net/browse/OY2-27065
https://qmacbis.atlassian.net/browse/OY2-27013
https://qmacbis.atlassian.net/browse/OY2-27040
Approach
superRefine
in place of our hook's additional requirements function array. This tool supplements our need while staying within thezod
package toolsAssorted Notes/Considerations/Learning
We love a good template 💅🏼😎