Spaces:
Sleeping
Sleeping
File size: 11,202 Bytes
59ad4aa 9f6e84b 59ad4aa d738108 9f6e84b d738108 59ad4aa d738108 59ad4aa 475d02c 59ad4aa d738108 59ad4aa d738108 59ad4aa 475d02c 59ad4aa d738108 59ad4aa d738108 59ad4aa d738108 59ad4aa d738108 59ad4aa | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | import { useState } from "react";
import { useNavigate } from "react-router";
import { LogIn, Loader2 } from "lucide-react";
import { login } from "../../services/api";
import logoUrl from "../../assets/logo.png";
export default function Login() {
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [error, setError] = useState("");
const [isLoading, setIsLoading] = useState(false);
const navigate = useNavigate();
const handleLogin = async (e: React.FormEvent) => {
e.preventDefault();
setError("");
if (!email || !password) {
setError("Please enter both email and password");
return;
}
if (!/\S+@\S+\.\S+/.test(email)) {
setError("Please enter a valid email address");
return;
}
setIsLoading(true);
try {
const res = await login(email, password);
const user = {
user_id: res.data.id,
email: res.data.email,
name: res.data.fullname,
loginTime: new Date().toISOString(),
};
localStorage.setItem("chatbot_user", JSON.stringify(user));
navigate("/");
} catch (err: unknown) {
setError(err instanceof Error ? err.message : "Login failed");
} finally {
setIsLoading(false);
}
};
return (
<div className="relative min-h-screen flex items-center justify-center overflow-hidden bg-[#1e2d45]">
{/* ββ Dot grid texture ββ */}
<div
className="absolute inset-0 z-0 opacity-20"
style={{
backgroundImage: "radial-gradient(circle, #334155 1px, transparent 1px)",
backgroundSize: "28px 28px",
}}
/>
{/* ββ Gradient orbs β glowing on dark bg ββ */}
{/* Cyan β top left */}
<div
className="absolute -top-32 -left-32 w-[520px] h-[520px] rounded-full blur-3xl opacity-[0.18] animate-pulse"
style={{ background: "#0ea5e9", animationDuration: "5s" }}
/>
{/* Orange β bottom right */}
<div
className="absolute -bottom-40 -right-40 w-[560px] h-[560px] rounded-full blur-3xl opacity-[0.16] animate-pulse"
style={{ background: "#f97316", animationDuration: "7s" }}
/>
{/* Green β top right */}
<div
className="absolute -top-24 right-1/4 w-[320px] h-[320px] rounded-full blur-3xl opacity-[0.12] animate-pulse"
style={{ background: "#10b981", animationDuration: "9s" }}
/>
{/* Purple accent β center left */}
<div
className="absolute top-1/2 -left-40 w-[360px] h-[360px] rounded-full blur-3xl opacity-[0.10] animate-pulse"
style={{ background: "#8b5cf6", animationDuration: "11s" }}
/>
{/* ββ Neural network β bottom left ββ */}
<svg
className="absolute bottom-8 left-8 opacity-[0.35] animate-float-slow"
width="200" height="200" viewBox="0 0 200 200"
fill="none" xmlns="http://www.w3.org/2000/svg"
>
<line x1="20" y1="150" x2="65" y2="90" stroke="#0ea5e9" strokeWidth="1"/>
<line x1="20" y1="150" x2="55" y2="170" stroke="#0ea5e9" strokeWidth="1"/>
<line x1="65" y1="90" x2="110" y2="125" stroke="#0ea5e9" strokeWidth="1"/>
<line x1="65" y1="90" x2="130" y2="55" stroke="#10b981" strokeWidth="1"/>
<line x1="110" y1="125" x2="170" y2="105" stroke="#0ea5e9" strokeWidth="1"/>
<line x1="130" y1="55" x2="170" y2="105" stroke="#10b981" strokeWidth="1"/>
<line x1="130" y1="55" x2="175" y2="30" stroke="#10b981" strokeWidth="1"/>
<line x1="55" y1="170" x2="110" y2="125" stroke="#0ea5e9" strokeWidth="1"/>
<line x1="175" y1="30" x2="170" y2="105" stroke="#10b981" strokeWidth="1"/>
<circle cx="20" cy="150" r="3.5" fill="#0ea5e9" fillOpacity="0.7"/>
<circle cx="55" cy="170" r="2.5" fill="#0ea5e9" fillOpacity="0.5"/>
<circle cx="65" cy="90" r="5" fill="#0ea5e9" fillOpacity="0.9"/>
<circle cx="110" cy="125" r="3.5" fill="#0ea5e9" fillOpacity="0.7"/>
<circle cx="130" cy="55" r="5" fill="#10b981" fillOpacity="0.9"/>
<circle cx="170" cy="105" r="3.5" fill="#10b981" fillOpacity="0.7"/>
<circle cx="175" cy="30" r="2.5" fill="#10b981" fillOpacity="0.5"/>
</svg>
{/* ββ Neural network β top right ββ */}
<svg
className="absolute top-8 right-8 opacity-[0.30] animate-float"
style={{ "--float-rotate": "0deg" } as React.CSSProperties}
width="180" height="180" viewBox="0 0 180 180"
fill="none" xmlns="http://www.w3.org/2000/svg"
>
<line x1="160" y1="30" x2="115" y2="80" stroke="#f97316" strokeWidth="1"/>
<line x1="115" y1="80" x2="70" y2="55" stroke="#f97316" strokeWidth="1"/>
<line x1="115" y1="80" x2="130" y2="135" stroke="#0ea5e9" strokeWidth="1"/>
<line x1="70" y1="55" x2="25" y2="90" stroke="#f97316" strokeWidth="1"/>
<line x1="25" y1="90" x2="80" y2="155" stroke="#0ea5e9" strokeWidth="1"/>
<line x1="80" y1="155" x2="130" y2="135" stroke="#0ea5e9" strokeWidth="1"/>
<line x1="70" y1="55" x2="30" y2="25" stroke="#f97316" strokeWidth="1"/>
<circle cx="160" cy="30" r="3.5" fill="#f97316" fillOpacity="0.7"/>
<circle cx="115" cy="80" r="5" fill="#f97316" fillOpacity="0.9"/>
<circle cx="70" cy="55" r="3.5" fill="#f97316" fillOpacity="0.7"/>
<circle cx="130" cy="135" r="2.5" fill="#0ea5e9" fillOpacity="0.5"/>
<circle cx="25" cy="90" r="3.5" fill="#0ea5e9" fillOpacity="0.7"/>
<circle cx="80" cy="155" r="2.5" fill="#0ea5e9" fillOpacity="0.5"/>
<circle cx="30" cy="25" r="2.5" fill="#f97316" fillOpacity="0.5"/>
</svg>
{/* ββ Large ring β top right ββ */}
<div className="absolute -top-24 -right-24 w-80 h-80 rounded-full border border-slate-700 animate-float-slow opacity-50" />
<div className="absolute -top-10 -right-10 w-48 h-48 rounded-full border border-slate-800 opacity-60" />
{/* ββ Rotated square β bottom left ββ */}
<div
className="absolute bottom-16 left-16 w-24 h-24 border border-slate-200 opacity-50 animate-float"
style={{ transform: "rotate(20deg)", "--float-rotate": "20deg" } as React.CSSProperties}
/>
<div
className="absolute bottom-28 left-28 w-12 h-12 border border-slate-200 opacity-40"
style={{ transform: "rotate(45deg)" }}
/>
{/* ββ Hexagon β bottom right ββ */}
<svg
className="absolute bottom-12 right-16 opacity-[0.35] animate-float"
style={{ "--float-rotate": "0deg", animationDelay: "2s" } as React.CSSProperties}
width="80" height="80" viewBox="0 0 160 160"
fill="none" xmlns="http://www.w3.org/2000/svg"
>
<path
d="M 140 80 L 110 132 L 50 132 L 20 80 L 50 28 L 110 28 Z"
stroke="#f97316" strokeWidth="1.5" fill="none"
/>
<path
d="M 122 80 L 101 114 L 59 114 L 38 80 L 59 46 L 101 46 Z"
stroke="#f97316" strokeWidth="1" strokeOpacity="0.5" fill="none"
/>
</svg>
{/* ββ Rotated square β bottom left ββ */}
<div
className="absolute bottom-16 left-16 w-24 h-24 border border-slate-700 opacity-50 animate-float"
style={{ transform: "rotate(20deg)", "--float-rotate": "20deg" } as React.CSSProperties}
/>
<div
className="absolute bottom-28 left-28 w-12 h-12 border border-slate-700 opacity-30"
style={{ transform: "rotate(45deg)" }}
/>
{/* ββ Small floating dots ββ */}
<div className="absolute top-1/4 left-12 w-2 h-2 rounded-full bg-sky-400 opacity-60 animate-float" style={{ animationDelay: "1s" }} />
<div className="absolute top-1/3 right-20 w-1.5 h-1.5 rounded-full bg-orange-400 opacity-60 animate-float-slow" style={{ animationDelay: "3s" }} />
<div className="absolute bottom-1/3 left-1/4 w-1.5 h-1.5 rounded-full bg-emerald-400 opacity-60 animate-float" style={{ animationDelay: "0.5s" }} />
<div className="absolute top-2/3 right-1/3 w-1 h-1 rounded-full bg-violet-400 opacity-50 animate-float-slow" style={{ animationDelay: "4s" }} />
{/* ββ Login card ββ */}
<div className="relative z-10 w-full max-w-md px-4">
<div className="bg-white rounded-2xl shadow-2xl shadow-black/40 p-7 border border-white/10">
{/* Brand logo */}
<div className="flex flex-col items-center gap-3 mb-6">
<img src={logoUrl} alt="DataEyond" className="w-12 h-12 object-contain" />
<div className="text-center">
<h1 className="text-xl font-semibold text-slate-900">Welcome Back</h1>
<p className="text-slate-400 text-sm mt-0.5">Sign in to continue to your chatbot</p>
</div>
</div>
<form onSubmit={handleLogin} className="space-y-4">
<div>
<label htmlFor="email" className="block text-xs font-medium mb-1.5 text-slate-600">
Email Address
</label>
<input
id="email"
type="email"
autoComplete="username"
value={email}
onChange={(e) => setEmail(e.target.value)}
className="w-full px-3 py-2 text-sm rounded-xl border border-slate-200 bg-slate-50 focus:outline-none focus:ring-2 focus:ring-sky-400/30 focus:border-sky-400 placeholder:text-slate-300 transition"
placeholder="you@example.com"
disabled={isLoading}
/>
</div>
<div>
<label htmlFor="password" className="block text-xs font-medium mb-1.5 text-slate-600">
Password
</label>
<input
id="password"
type="password"
autoComplete="current-password"
value={password}
onChange={(e) => setPassword(e.target.value)}
className="w-full px-3 py-2 text-sm rounded-xl border border-slate-200 bg-slate-50 focus:outline-none focus:ring-2 focus:ring-sky-400/30 focus:border-sky-400 placeholder:text-slate-300 transition"
placeholder="Enter your password"
disabled={isLoading}
/>
</div>
{error && (
<div className="bg-red-50 border border-red-100 text-red-600 px-3 py-2 rounded-xl text-xs">
{error}
</div>
)}
<button
type="submit"
disabled={isLoading}
className="w-full flex items-center justify-center gap-2 bg-[#059669] hover:bg-[#047857] active:bg-[#065F46] text-white py-2.5 text-sm rounded-xl transition font-medium disabled:opacity-50 disabled:cursor-not-allowed mt-1"
>
{isLoading ? (
<Loader2 className="w-4 h-4 animate-spin" />
) : (
<LogIn className="w-4 h-4" />
)}
{isLoading ? "Signing inβ¦" : "Sign In"}
</button>
</form>
</div>
</div>
</div>
);
}
|