import { FormEvent, useState } from "react"; import { GUEST_EMAIL, GUEST_PASSWORD } from "../constants"; interface Props { onLogin: (email: string, password: string) => Promise; } export function LoginForm({ onLogin }: Props) { const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(""); const [loading, setLoading] = useState(false); async function handleSubmit(e: FormEvent) { e.preventDefault(); setError(""); setLoading(true); try { await onLogin(email, password); } catch { setError("Invalid credentials. Please try again."); } finally { setLoading(false); } } async function handleGuestLogin() { setError(""); setLoading(true); try { await onLogin(GUEST_EMAIL, GUEST_PASSWORD); } catch { setError("Guest login failed. Please try again."); } finally { setLoading(false); } } return (
{/* Header */}

Analytics Viewer

Sign in to access the dashboard

setEmail(e.target.value)} required autoComplete="email" placeholder="you@example.com" className="w-full bg-slate-900 border border-slate-600 rounded-lg px-4 py-2.5 text-white placeholder-slate-500 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-transparent transition" />
setPassword(e.target.value)} required autoComplete="current-password" placeholder="••••••••" className="w-full bg-slate-900 border border-slate-600 rounded-lg px-4 py-2.5 text-white placeholder-slate-500 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-transparent transition" />
{error && (
{error}
)}
); }