-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
95 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
import { Textarea, Input, Button } from "@chakra-ui/react" | ||
import { Textarea, Input, Button } from '@chakra-ui/react' | ||
import { zodResolver } from '@hookform/resolvers/zod' | ||
import { postFeedback } from 'api/postFeedbackData' | ||
import { useToast } from 'hooks/useToast' | ||
import { useRef, useState } from 'react' | ||
import ReCAPTCHA from 'react-google-recaptcha' | ||
import { useForm } from 'react-hook-form' | ||
import { Controller, useForm } from 'react-hook-form' | ||
import { RECAPTCHA_SITE_KEY } from 'utils/credentials' | ||
import { | ||
anonymousFeedbackFormSchema, | ||
feedbackFormSchema, | ||
type FeedbackFormValues, | ||
} from 'utils/helpers/schema' | ||
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from 'components/ui/Form' | ||
import { Switch } from 'components/ui/switch' | ||
import { Switch } from 'components/ui/Switch' | ||
import { Label } from './ui/Label' | ||
|
||
export function FeedbackForm() { | ||
const [isAnonymous, setIsAnonymous] = useState(false) | ||
|
@@ -65,92 +65,82 @@ export function FeedbackForm() { | |
} | ||
|
||
return ( | ||
<Form {...form}> | ||
<form | ||
onSubmit={form.handleSubmit(onSubmit)} | ||
className="space-y-8 rounded-lg border p-4 py-8 w-full max-w-screen-lg mx-auto" | ||
> | ||
<h1 className="w-full text-center font-bold">Feedback form</h1> | ||
{!isAnonymous && ( | ||
<div className="w-full flex justify-between items-center gap-4"> | ||
<FormField | ||
control={form.control} | ||
name="name" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Name</FormLabel> | ||
<FormControl> | ||
<Input | ||
placeholder="Your name" | ||
className="border border-border rounded-lg p-4" | ||
{...field} | ||
/> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
<form | ||
onSubmit={form.handleSubmit(onSubmit)} | ||
className="mx-auto w-full max-w-screen-lg space-y-8 rounded-lg border p-4 py-8" | ||
> | ||
<h1 className="w-full text-center font-bold">Feedback form</h1> | ||
{!isAnonymous && ( | ||
<div className="flex w-full items-center justify-between gap-4"> | ||
<div className=""> | ||
<Label htmlFor="name">Name</Label> | ||
<Input | ||
placeholder="Your name" | ||
id="name" | ||
className="rounded-lg border border-border p-4" | ||
{...form.register('name')} | ||
/> | ||
<FormField | ||
control={form.control} | ||
name="email" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Email</FormLabel> | ||
<FormControl> | ||
<Input | ||
placeholder="[email protected]" | ||
className="border border-border rounded-lg p-4" | ||
{...field} | ||
/> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
{form.formState.errors.name && ( | ||
<p className="mt-1 text-xs text-red-500">{form.formState.errors.name.message}</p> | ||
)} | ||
</div> | ||
<div> | ||
<Label htmlFor="email">Email</Label> | ||
<Input | ||
placeholder="[email protected]" | ||
id="email" | ||
className="rounded-lg border border-border p-4" | ||
{...form.register('email')} | ||
/> | ||
{form.formState.errors.email && ( | ||
<p className="mt-1 text-xs text-red-500">{form.formState.errors.email.message}</p> | ||
)} | ||
</div> | ||
)} | ||
<FormField | ||
control={form.control} | ||
name="message" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Message</FormLabel> | ||
<FormControl> | ||
<Textarea | ||
placeholder="Your feedback here..." | ||
className="border border-border rounded-lg p-4" | ||
{...field} | ||
/> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
</div> | ||
)} | ||
<div> | ||
<Label htmlFor="message">Message</Label> | ||
<Textarea | ||
placeholder="Your feedback here..." | ||
id="message" | ||
className="rounded-lg border border-border p-4" | ||
{...form.register('message')} | ||
/> | ||
<FormField | ||
control={form.control} | ||
{form.formState.errors.message && ( | ||
<p className="mt-1 text-xs text-red-500">{form.formState.errors.message.message}</p> | ||
)} | ||
</div> | ||
|
||
<div className="flex flex-row items-center justify-between gap-4 rounded-lg border border-border p-4"> | ||
<div className="space-y-0.5"> | ||
<Label htmlFor="is_anonymous" className="text-base"> | ||
Anonymous Feedback | ||
</Label> | ||
</div> | ||
<Controller | ||
name="is_anonymous" | ||
render={({ field }) => ( | ||
<FormItem className="flex flex-row items-center justify-between gap-4 rounded-lg border border-border p-4"> | ||
<div className="space-y-0.5"> | ||
<FormLabel className="text-base">Anonymous Feedback</FormLabel> | ||
</div> | ||
<FormControl> | ||
<Switch | ||
checked={field.value} | ||
onCheckedChange={({ checked }: { checked: boolean }) => { | ||
field.onChange(checked) | ||
setIsAnonymous(checked) | ||
}} | ||
/> | ||
</FormControl> | ||
</FormItem> | ||
control={form.control} | ||
render={({ field: { onChange, value } }) => ( | ||
<Switch | ||
checked={value} | ||
onCheckedChange={({ checked }: { checked: boolean }) => { | ||
onChange(checked) | ||
setIsAnonymous(checked) | ||
}} | ||
/> | ||
)} | ||
/> | ||
<ReCAPTCHA sitekey={RECAPTCHA_SITE_KEY} ref={captchaRef} /> | ||
<Button className="p-2 px-4 bg-primary text-white dark:text-gray-800" variant='solid' type="submit" aria-label="Submit Feedback" disabled={form.formState.isSubmitting}> | ||
{form.formState.isSubmitting ? 'Submitting...' : 'Submit Feedback'} | ||
</Button> | ||
</form> | ||
</Form> | ||
</div> | ||
<ReCAPTCHA sitekey={RECAPTCHA_SITE_KEY} ref={captchaRef} /> | ||
<Button | ||
className="bg-primary p-2 px-4 text-white dark:text-gray-800" | ||
variant="solid" | ||
type="submit" | ||
aria-label="Submit Feedback" | ||
disabled={form.formState.isSubmitting} | ||
> | ||
{form.formState.isSubmitting ? 'Submitting...' : 'Submit Feedback'} | ||
</Button> | ||
</form> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters