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 - - . -
+ + + + + ( + + + + + + )} + /> + ( + + +