Skip to content

Convert ProductForm to react-hook-form with new RHFForm component#5310

Draft
Copilot wants to merge 7 commits intomainfrom
copilot/com-2741-setup-react-hook-form-storybook
Draft

Convert ProductForm to react-hook-form with new RHFForm component#5310
Copilot wants to merge 7 commits intomainfrom
copilot/com-2741-setup-react-hook-form-storybook

Conversation

Copy link
Contributor

Copilot AI commented Mar 13, 2026

Converts demo/admin/src/products/ProductForm.tsx from FinalForm to react-hook-form and introduces a new RHFForm component in @comet/admin that encapsulates the SaveBoundary wiring pattern.

RHFForm component (@comet/admin)

New component that replaces the manual Savable + handleSubmit + isDirtyRef boilerplate. Requires a SaveBoundary ancestor.

const form = useForm<FormValues>({
    defaultValues: { ... },
    values: formValues,          // drives reset when data loads
    resetOptions: { keepDirtyValues: true },
});

return (
    <RHFForm onSubmit={onSubmit} {...form}>
        <RHFTextField control={form.control} name="title" ... />
    </RHFForm>
);

Internally, RHFForm:

  • Wraps children in FormProvider
  • Renders an internal SavableRHF that uses useFormContext() + useFormState() to register with SaveBoundary
  • Handles <form onSubmit> by delegating to saveBoundaryApi.save()

ProductForm.tsx changes

  • Replaced useEffect(() => reset(data, { keepDirtyValues: true }), [data]) with useForm({ values, resetOptions: { keepDirtyValues: true } }) — react-hook-form's built-in mechanism for syncing external data
  • Removed manual doSave / isDirtyRef / hasChanges wiring; RHFForm handles all of that
  • useSaveConflict is retained; checkForConflicts() is called inside onSubmit
  • Not-yet-implemented field types (DateField, SelectField, AsyncSelectField, etc.) remain commented out

Storybook story

Added storybook/src/docs/form/components/ReactHookForm.stories.tsx with EditProductForm and AddProductForm stories using MockedProvider and the same RHFForm pattern.


📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

…ield (COM-2777)

Co-authored-by: nsams <50764+nsams@users.noreply.github.com>
Copilot AI changed the title [WIP] [COM-2741] Setup Storybook for React Hook Form fields COM-2777: Storybook React Hook Form Setup Mar 13, 2026
Copilot AI requested a review from nsams March 13, 2026 09:16
@nsams
Copy link
Member

nsams commented Mar 13, 2026

@copilot fields should be in library, @comet/admin, and admin has it's own storybook (in the package source) use that.

…n package storybook

Co-authored-by: nsams <50764+nsams@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 13, 2026

@copilot fields should be in library, @comet/admin, and admin has it's own storybook (in the package source) use that.

Done in e1e93fd. RHFTextField and RHFNumberField are now in @comet/admin (packages/admin/admin/src/form/fields/) with their stories co-located in the admin package's storybook under __stories__/. The helper files and stories in the main storybook have been removed.

Copilot AI changed the title COM-2777: Storybook React Hook Form Setup COM-2777: React Hook Form Setup — RHFTextField and RHFNumberField in @comet/admin Mar 13, 2026
@nsams
Copy link
Member

nsams commented Mar 13, 2026

@copilot move form fields to react-hook-form/fields

Co-authored-by: nsams <50764+nsams@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 13, 2026

@copilot move form fields to react-hook-form/fields

Done in 0670b69. Both RHFTextField and RHFNumberField (along with their stories) are now under packages/admin/admin/src/form/react-hook-form/fields/.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • iojs.org
    • Triggering command: /usr/bin/curl curl -q --fail --compressed -L -s REDACTED -o - (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title COM-2777: React Hook Form Setup — RHFTextField and RHFNumberField in @comet/admin COM-2777: Add RHFTextField and RHFNumberField to @comet/admin Mar 13, 2026
Co-authored-by: nsams <50764+nsams@users.noreply.github.com>
Copilot AI changed the title COM-2777: Add RHFTextField and RHFNumberField to @comet/admin Add required prop to RHFTextField and RHFNumberField; fix endAdornment composition Mar 13, 2026
Copilot stopped work on behalf of nsams due to an error March 14, 2026 10:55
Co-authored-by: nsams <50764+nsams@users.noreply.github.com>
Copilot AI changed the title Add required prop to RHFTextField and RHFNumberField; fix endAdornment composition Convert ProductForm to react-hook-form with RHF storybook story Mar 14, 2026
Co-authored-by: nsams <50764+nsams@users.noreply.github.com>
Copilot AI changed the title Convert ProductForm to react-hook-form with RHF storybook story Convert ProductForm to react-hook-form with new RHFForm component Mar 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants