|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import { Button } from "@/components/ui/button"; |
| 4 | +import { |
| 5 | + Card, |
| 6 | + CardContent, |
| 7 | + CardDescription, |
| 8 | + CardHeader, |
| 9 | + CardTitle, |
| 10 | +} from "@/components/ui/card"; |
| 11 | +import { Form } from "@/components/ui/form"; |
| 12 | +import { OnboardMultiStepFormContext } from "@/contexts/OnboardMultiStepFormContext"; |
| 13 | +import { ProficiencyEnum } from "@/types/Proficiency"; |
| 14 | +import { zodResolver } from "@hookform/resolvers/zod"; |
| 15 | +import { MoveLeft } from "lucide-react"; |
| 16 | +import { useCallback, useContext } from "react"; |
| 17 | +import { useForm } from "react-hook-form"; |
| 18 | +import { z } from "zod"; |
| 19 | + |
| 20 | +const FormSchema = z.object({ |
| 21 | + proficiency: ProficiencyEnum, |
| 22 | +}); |
| 23 | + |
| 24 | +export default function ProficiencyForm() { |
| 25 | + const { nextStep, prevStep } = useContext(OnboardMultiStepFormContext); |
| 26 | + |
| 27 | + const form = useForm<z.infer<typeof FormSchema>>({ |
| 28 | + resolver: zodResolver(FormSchema), |
| 29 | + defaultValues: { |
| 30 | + proficiency: ProficiencyEnum.enum.Beginner, |
| 31 | + }, |
| 32 | + }); |
| 33 | + |
| 34 | + const onSubmit = useCallback(() => { |
| 35 | + nextStep(); |
| 36 | + }, [nextStep]); |
| 37 | + |
| 38 | + return ( |
| 39 | + <Card className="mt-3"> |
| 40 | + <CardHeader> |
| 41 | + <CardTitle className="text-xl">Select your proficiency level</CardTitle> |
| 42 | + <CardDescription> |
| 43 | + We will match someone of your proficiency level |
| 44 | + </CardDescription> |
| 45 | + </CardHeader> |
| 46 | + <CardContent> |
| 47 | + <Form {...form}> |
| 48 | + <form |
| 49 | + onSubmit={form.handleSubmit(onSubmit)} |
| 50 | + className="flex flex-col gap-5" |
| 51 | + > |
| 52 | + <div className="flex justify-end gap-2"> |
| 53 | + <Button |
| 54 | + variant="ghost" |
| 55 | + className="self-start" |
| 56 | + onClick={(e) => { |
| 57 | + e.preventDefault(); |
| 58 | + prevStep(); |
| 59 | + }} |
| 60 | + > |
| 61 | + <MoveLeft className="stroke-foreground-100 mr-2" /> |
| 62 | + Back |
| 63 | + </Button> |
| 64 | + <Button className="w-full max-w-40" type="submit"> |
| 65 | + Next |
| 66 | + </Button> |
| 67 | + </div> |
| 68 | + </form> |
| 69 | + </Form> |
| 70 | + </CardContent> |
| 71 | + </Card> |
| 72 | + ); |
| 73 | +} |
0 commit comments