Skip to content
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

Merged
merged 21 commits into from
Jan 19, 2024
Merged

Conversation

hannasage
Copy link

@hannasage hannasage commented Jan 16, 2024

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

  • Update instructional texts where missing/incorrect
  • Update configs where additional requirements were necessary
    • This includes using superRefine in place of our hook's additional requirements function array. This tool supplements our need while staying within the zod package tools
  • Update details page title to use plan type

Assorted Notes/Considerations/Learning

We love a good template 💅🏼😎

@hannasage hannasage self-assigned this Jan 16, 2024
@hannasage hannasage marked this pull request as ready for review January 16, 2024 17:16
@hannasage hannasage marked this pull request as draft January 16, 2024 21:02
Comment on lines -27 to -35
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
Copy link
Author

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

Comment on lines 16 to 29
.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;
}
Copy link
Author

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`}
Copy link
Author

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.");
Copy link
Author

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.

@hannasage hannasage marked this pull request as ready for review January 17, 2024 15:07
Copy link
Contributor

@mdial89f mdial89f left a 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>;
Copy link
Collaborator

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

Copy link
Author

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,
Copy link
Collaborator

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

Copy link
Author

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.

Comment on lines 16 to 29
.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;
}
Copy link
Collaborator

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

Copy link
Collaborator

@13bfrancis 13bfrancis left a 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

src/services/ui/src/pages/actions/template.tsx Outdated Show resolved Hide resolved
@hannasage hannasage added the In Testing This PR is being tested by QA label Jan 17, 2024
@hannasage hannasage changed the title fix(actions): Add missing additional info instructions fix(actions): Updating action template and forms content Jan 18, 2024
@hannasage hannasage requested a review from 13bfrancis January 18, 2024 15:08
@hannasage hannasage merged commit f7cbba5 into master Jan 19, 2024
16 checks passed
@hannasage hannasage deleted the nstrctns branch January 19, 2024 16:04
@hannasage hannasage removed the In Testing This PR is being tested by QA label Jan 22, 2024
@pkim-gswell pkim-gswell added the type: FIX Submit bug fixes label Jan 24, 2024
Copy link
Contributor

🎉 This PR is included in version 1.5.0-val.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants