From a9fdb09c66aa1a27d962222d3426af5cc93ff2a1 Mon Sep 17 00:00:00 2001 From: Gildas Garcia <1122076+djhi@users.noreply.github.com> Date: Fri, 10 Apr 2026 12:11:30 +0200 Subject: [PATCH] chore: migrate docs feedback modal to react-hook-form (#44739) ## Problem The Docs feedback modal still uses the old `Form` component with `formik` ## Solution Migrate it to `react-hook-form` ## Summary by CodeRabbit * **Improvements** * Enhanced feedback form with schema-driven validation requiring title and comment before submission. * Submission buttons disable while submitting; cancel now also resets the form state. * **Chores** * Added form handling and validation libraries to support the improved feedback experience. --- .../components/Feedback/FeedbackModal.tsx | 170 ++++++++++-------- apps/docs/package.json | 2 + pnpm-lock.yaml | 28 ++- 3 files changed, 120 insertions(+), 80 deletions(-) diff --git a/apps/docs/components/Feedback/FeedbackModal.tsx b/apps/docs/components/Feedback/FeedbackModal.tsx index 80c7dcec2d5..c62328be3ba 100644 --- a/apps/docs/components/Feedback/FeedbackModal.tsx +++ b/apps/docs/components/Feedback/FeedbackModal.tsx @@ -1,10 +1,24 @@ -import { Button, Form, Input, Modal } from 'ui' +import { zodResolver } from '@hookform/resolvers/zod' +import { SubmitHandler, useForm } from 'react-hook-form' +import { + Button, + Form_Shadcn_, + FormControl_Shadcn_, + FormField_Shadcn_, + Input_Shadcn_, + Modal, + Textarea, +} from 'ui' +import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout' +import * as z from 'zod' -export type FeedbackFields = { - page: string - title: string - comment: string -} +const formSchema = z.object({ + page: z.string(), + title: z.string().min(1, 'Required'), + comment: z.string().min(1, 'Required'), +}) + +export type FeedbackFields = z.infer type FeedbackModalProps = { visible: boolean @@ -14,78 +28,92 @@ type FeedbackModalProps = { } function FeedbackModal({ visible, page, onCancel, onSubmit }: FeedbackModalProps) { + const form = useForm({ + defaultValues: { page, title: '', comment: '' }, + resolver: zodResolver(formSchema), + }) + const { reset } = form + const { isSubmitting } = form.formState + + const handleCancel = () => { + reset() + onCancel() + } + + const handleSubmit: SubmitHandler = (values) => { + onSubmit(values) + reset() + } + return ( -
{ - const errors: Partial = {} - - if (!vals.title) { - errors.title = 'Required' - } - - if (!vals.comment) { - errors.comment = 'Required' - } - - return errors - }} - onReset={onCancel} - onSubmit={onSubmit} - > - {({ isSubmitting }: { isSubmitting: boolean }) => ( - <> - - - - -
- 💡 -
- Need help or support? This feedback form is for documentation - improvements only. For technical support, please submit a{' '} - - support request - - . -
+ + + + + ( + + + + + + )} + /> + ( + + +