|
1 | 1 | 'use client' |
2 | 2 | import { Button } from '@/components/ui/button' |
| 3 | +import { zodResolver } from '@hookform/resolvers/zod' |
| 4 | +import { useForm } from 'react-hook-form' |
3 | 5 | import { FcGoogle } from 'react-icons/fc' |
| 6 | +import { z } from 'zod' |
4 | 7 |
|
| 8 | +import { |
| 9 | + Form, |
| 10 | + FormControl, |
| 11 | + FormField, |
| 12 | + FormItem, |
| 13 | + FormMessage, |
| 14 | +} from '@/components/ui/form' |
| 15 | +import { Input } from '@/components/ui/input' |
5 | 16 | import { googleSignIn } from '@/lib/google-signin' |
6 | 17 |
|
7 | | -// export const metadata: Metadata = { |
8 | | -// title: 'Sign In', |
9 | | -// description: 'Sign In to your account', |
10 | | -// } |
| 18 | +const formSchema = z.object({ |
| 19 | + email: z.string().email({ |
| 20 | + message: 'Please enter a valid email address', |
| 21 | + }), |
| 22 | +}) |
| 23 | + |
| 24 | +type FormValues = z.infer<typeof formSchema> |
11 | 25 |
|
12 | 26 | const SignInPage = () => { |
13 | | - const handleSignIn = async () => { |
14 | | - await googleSignIn() |
| 27 | + const form = useForm<FormValues>({ |
| 28 | + resolver: zodResolver(formSchema), |
| 29 | + defaultValues: { |
| 30 | + email: '', |
| 31 | + }, |
| 32 | + }) |
| 33 | + |
| 34 | + function onSubmit(values: FormValues) { |
| 35 | + console.log(values) |
15 | 36 | } |
16 | 37 |
|
17 | 38 | return ( |
18 | | - <div className="flex-center flex-col gap-10"> |
| 39 | + <div className="flex-center flex-col gap-10 lg:w-1/4"> |
19 | 40 | <div className="flex-center flex-col gap-2"> |
20 | | - <h1 className="font-bold text-4xl">Welcome</h1> |
21 | | - <p className="text-lg text-muted-foreground"> |
| 41 | + <h1 className="font-bold text-4xl text-zinc-900">Welcome Back</h1> |
| 42 | + <p className="text-center text-lg text-muted-foreground"> |
22 | 43 | Sign in to your account to continue |
23 | 44 | </p> |
24 | 45 | </div> |
25 | | - <Button onClick={handleSignIn} className="w-full p-6 text-lg"> |
26 | | - <FcGoogle className="size-6" /> |
27 | | - Sign in with Google |
28 | | - </Button> |
| 46 | + <div className="flex w-full flex-col gap-4"> |
| 47 | + <Form {...form}> |
| 48 | + <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8"> |
| 49 | + <FormField |
| 50 | + control={form.control} |
| 51 | + name="email" |
| 52 | + render={({ field }) => ( |
| 53 | + <FormItem> |
| 54 | + <FormControl> |
| 55 | + <Input |
| 56 | + placeholder="Your email" |
| 57 | + {...field} |
| 58 | + className="bg-zinc-100 p-6 lg:text-lg" |
| 59 | + type="email" |
| 60 | + /> |
| 61 | + </FormControl> |
| 62 | + <FormMessage /> |
| 63 | + </FormItem> |
| 64 | + )} |
| 65 | + /> |
| 66 | + <Button type="submit" className="w-full p-6 text-base "> |
| 67 | + Sign in |
| 68 | + </Button> |
| 69 | + </form> |
| 70 | + </Form> |
| 71 | + <p className="text-center text-zinc-500">OR</p> |
| 72 | + <Button |
| 73 | + onClick={async () => await googleSignIn()} |
| 74 | + className="p-6 text-base" |
| 75 | + > |
| 76 | + <FcGoogle className="size-6" /> |
| 77 | + Continue with Google |
| 78 | + </Button> |
| 79 | + </div> |
29 | 80 | </div> |
30 | 81 | ) |
31 | 82 | } |
|
0 commit comments