|
1 | | -import { LoginForm } from "@/components/login-form"; |
| 1 | +"use client"; |
| 2 | +import { login } from "@/api/auth"; |
| 3 | +import DevsocText from "@/assets/images/DevsocText.svg"; |
| 4 | +import { Button } from "@/components/ui/button"; |
| 5 | +import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; |
| 6 | +import { Input } from "@/components/ui/input"; |
| 7 | +import { Label } from "@/components/ui/label"; |
| 8 | +import { cn } from "@/lib/utils"; |
| 9 | +import { Loader2 } from "lucide-react"; |
| 10 | +import Image from "next/image"; |
| 11 | +import { useRouter } from "next/navigation"; |
| 12 | +import { useState } from "react"; |
| 13 | +import toast from "react-hot-toast"; |
2 | 14 |
|
3 | 15 | export default function HomePage() { |
| 16 | + const [email, setEmail] = useState<string>(""); |
| 17 | + const [password, setPassword] = useState<string>(""); |
| 18 | + const [loading, setLoading] = useState<boolean>(false); |
| 19 | + const router = useRouter(); |
| 20 | + |
| 21 | + const handleLogin = async (e: { preventDefault: () => void }) => { |
| 22 | + e.preventDefault(); |
| 23 | + setLoading(true); |
| 24 | + try { |
| 25 | + const response = await login(email, password); |
| 26 | + if (response.status === "success") { |
| 27 | + toast.success("Login successful"); |
| 28 | + router.push("/users"); |
| 29 | + } |
| 30 | + } catch (err) { |
| 31 | + toast.error("Error logging you in"); |
| 32 | + } finally { |
| 33 | + setLoading(false); |
| 34 | + } |
| 35 | + }; |
| 36 | + |
4 | 37 | return ( |
5 | | - <> |
6 | | - <div className="flex h-screen items-center justify-center bg-black p-6 md:p-10"> |
7 | | - <div className="w-full max-w-sm"> |
8 | | - <LoginForm /> |
| 38 | + <div className="flex h-screen items-center justify-center bg-black p-6 md:p-10"> |
| 39 | + <div className="w-full max-w-sm"> |
| 40 | + <div className={cn("flex flex-col gap-6")}> |
| 41 | + <Card> |
| 42 | + <CardHeader> |
| 43 | + <Image |
| 44 | + src={DevsocText as HTMLImageElement} |
| 45 | + alt="DevSOC" |
| 46 | + height={200} |
| 47 | + width={600} |
| 48 | + className="mx-auto h-auto w-full max-w-xs" |
| 49 | + /> |
| 50 | + <CardTitle className="mx-auto text-xl"> Welcome Back</CardTitle> |
| 51 | + </CardHeader> |
| 52 | + <CardContent> |
| 53 | + <form onSubmit={handleLogin}> |
| 54 | + <div className="flex flex-col gap-6"> |
| 55 | + <div className="grid gap-2"> |
| 56 | + <Label htmlFor="email">Email</Label> |
| 57 | + <Input |
| 58 | + value={email} |
| 59 | + id="email" |
| 60 | + type="email" |
| 61 | + placeholder="m@example.com" |
| 62 | + required |
| 63 | + onChange={(e) => setEmail(e.target.value)} |
| 64 | + /> |
| 65 | + </div> |
| 66 | + <div className="grid gap-2"> |
| 67 | + <div className="flex items-center"> |
| 68 | + <Label htmlFor="password">Password</Label> |
| 69 | + </div> |
| 70 | + <Input |
| 71 | + value={password} |
| 72 | + onChange={(e) => setPassword(e.target.value)} |
| 73 | + id="password" |
| 74 | + type="password" |
| 75 | + required |
| 76 | + /> |
| 77 | + </div> |
| 78 | + <Button type="submit" className="w-full" disabled={loading}> |
| 79 | + {loading ? ( |
| 80 | + <> |
| 81 | + <Loader2 className="mr-2 h-4 w-4 animate-spin" /> |
| 82 | + Logging in... |
| 83 | + </> |
| 84 | + ) : ( |
| 85 | + "Login" |
| 86 | + )} |
| 87 | + </Button> |
| 88 | + </div> |
| 89 | + </form> |
| 90 | + </CardContent> |
| 91 | + </Card> |
9 | 92 | </div> |
10 | 93 | </div> |
11 | | - </> |
| 94 | + </div> |
12 | 95 | ); |
13 | 96 | } |
0 commit comments