-
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
feat(actions): Restructure ActionFormIndex and utilize ModalContext in forms #299
Conversation
export const WithdrawPackage = () => ( | ||
<PackageActionForm> | ||
<WithdrawPackageForm /> | ||
</PackageActionForm> |
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.
BEGONE ye ol' dependency! One example of how we no longer need to wrap these as the responsibilities handled by this are now handled in ActionFormIndex
(breadcrumbs and page container), and ActionFormSwitch
(item fetching and piping as props).
const { id, type } = useParams("/action/:id/:type"); | ||
return ( | ||
<SimplePageContainer> | ||
<ModalProvider> |
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.
Notably we add a dependency, but isolate its usage to a point that wraps all action forms instead of wrapping them individually, and provides a replicable solution for future form indexes (i.e. Submission forms when refactored to a dynamic-path approach like Actions forms).
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.
I'm liking the refactor decisions for these package actions 👍.
Leaving some suggestions/comments.
{attachmentList.map(({ name, label, required }) => ( | ||
<I.FormField | ||
key={name} | ||
control={form.control} | ||
name="additionalInformation" | ||
name={`attachments.${name}`} | ||
render={({ field }) => ( | ||
<I.FormItem> | ||
<h3 className="font-bold text-2xl font-sans"> | ||
Additional Information | ||
</h3> | ||
<I.FormLabel className="font-normal"> | ||
Add anything else that you would like to share with CMS. | ||
<I.FormLabel> | ||
{label} | ||
{required ? <I.RequiredIndicator /> : ""} | ||
</I.FormLabel> | ||
<I.Textarea {...field} className="h-[200px] resize-none" /> | ||
<I.FormDescription>4,000 characters allowed</I.FormDescription> | ||
<I.Upload | ||
files={field?.value ?? []} | ||
setFiles={field.onChange} | ||
/> | ||
<I.FormMessage /> | ||
</I.FormItem> | ||
)} | ||
/> |
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.
Continuing on from my initial comment, RespondToRai would look like this:
// attachments
{attachmentList.map(({ name, label, required }) => (
<I.FormField
key={name}
control={form.control}
name={`attachments.${name}`}
render={SlotAttachments({
label: (
<>
{label}
{required ? <I.RequiredIndicator /> : ""}
</>
),
message: <I.FormMessage />,
})}
/>
))}
// additionalInfo
<I.FormField
control={form.control}
name="additionalInformation"
render={SlotAdditionalInfo({
label: "Add anything else that you would like to share with CMS.",
description: "4,000 characters allowed",
})}
/>
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.
Left a few comments/questions for you
const { setCancelModalOpen, setSuccessModalOpen, setErrorModalOpen } = | ||
useModalContext(); |
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.
I don't know why but when I see context I smile inside lol
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.
When Paul is good with this I am. I like what you got going here
cf0bfe3
to
1b64581
Compare
🎉 This PR is included in version 1.5.0-val.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Purpose
To eliminate complexity created by
PackageActionForm
and each form handling their own modals.Linked Issues to Close
N/A
(Part of ongoing CHIP Actions work)
Approach
Previously, we piped in props to an action form within the
PackageActionForm
component by cloning the children and piping data from the parent thru as new props. This gets confusing and convoluted whenever you want to add new props, have a unique prop for a specific form, etc. It also creates weird nesting dependencies for our form pages.🤢 Yucky icky gross complexity, yikez
So, to remedy this complexity and open us up to more accessible props, we now handle the following responsibilities from
PackageActionForm
within theActionFormSwitch
component:item
(package)item
object through to the form page (Form pages have additionally been made to use the prop instead of using a fetch)😍 Beautiful gorgeous wonderful simplicity, yay
One layer up, in
ActionFormIndex
where we render the switch, we also wrap it in a page container, the modal context, and provide breadcrumbs so form pages can remain singularly focused on rendering form fields and controlling their data.Assorted Notes/Considerations/Learning
In testing CHIP actions, we've identified cases where control over props is a large advantage, so this untangling of prop control for action forms becomes even more useful as we move into waiver actions that have additional requirements.