|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import { z } from "zod"; |
| 4 | +import { useForm } from "react-hook-form"; |
| 5 | +import { zodResolver } from "@hookform/resolvers/zod"; |
| 6 | +import { |
| 7 | + Form, |
| 8 | + FormControl, |
| 9 | + FormDescription, |
| 10 | + FormField, |
| 11 | + FormItem, |
| 12 | + FormLabel, |
| 13 | + FormMessage, |
| 14 | +} from "@/components/ui/form"; |
| 15 | +import { Input } from "@/components/ui/input"; |
| 16 | +import { Button } from "@/components/ui/button"; |
| 17 | +import { signinAction } from "@/app/services/auth/sign-in.action"; |
| 18 | +import { signupAction } from "@/app/services/auth/sign-up.action"; |
| 19 | + |
| 20 | +const formSchema = z.object({ |
| 21 | + email: z.string().email(), |
| 22 | + password: z.string().min(6), |
| 23 | +}); |
| 24 | + |
| 25 | +export default function SignInOrSignUp() { |
| 26 | + const form = useForm<z.infer<typeof formSchema>>({ |
| 27 | + resolver: zodResolver(formSchema), |
| 28 | + defaultValues: { |
| 29 | + email: "", |
| 30 | + password: "", |
| 31 | + }, |
| 32 | + }); |
| 33 | + |
| 34 | + return ( |
| 35 | + <div className="max-w-sm mx-auto mt-32"> |
| 36 | + <Form {...form}> |
| 37 | + <form className="space-y-12"> |
| 38 | + <div className="space-y-4"> |
| 39 | + <FormField |
| 40 | + control={form.control} |
| 41 | + name="email" |
| 42 | + render={({ field }) => ( |
| 43 | + <FormItem> |
| 44 | + <FormLabel>email</FormLabel> |
| 45 | + <FormControl> |
| 46 | + <Input placeholder="Enter your em@1l" {...field} /> |
| 47 | + </FormControl> |
| 48 | + <FormMessage /> |
| 49 | + </FormItem> |
| 50 | + )} |
| 51 | + /> |
| 52 | + <FormField |
| 53 | + control={form.control} |
| 54 | + name="password" |
| 55 | + render={({ field }) => ( |
| 56 | + <FormItem> |
| 57 | + <FormLabel>password</FormLabel> |
| 58 | + <FormControl> |
| 59 | + <Input |
| 60 | + type="password" |
| 61 | + placeholder="Enter p@ssw0rd" |
| 62 | + {...field} |
| 63 | + /> |
| 64 | + </FormControl> |
| 65 | + <FormMessage /> |
| 66 | + </FormItem> |
| 67 | + )} |
| 68 | + /> |
| 69 | + </div> |
| 70 | + <div className="space-y-4"> |
| 71 | + <Button formAction={signinAction} type="submit" className="w-full"> |
| 72 | + Sign In |
| 73 | + </Button> |
| 74 | + <Button formAction={signupAction} type="submit" className="w-full"> |
| 75 | + Sign Up |
| 76 | + </Button> |
| 77 | + </div> |
| 78 | + </form> |
| 79 | + </Form> |
| 80 | + </div> |
| 81 | + ); |
| 82 | +} |
0 commit comments