import { useState } from "react" import { useNavigate, useLocation } from "react-router-dom" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Eye, EyeOff } from "lucide-react" import { toast } from "sonner" import { authService } from "@/services" import { errorTracker } from "@/lib/error-tracker" export default function LoginPage() { const navigate = useNavigate() const location = useLocation() const [email, setEmail] = useState("") const [password, setPassword] = useState("") const [showPassword, setShowPassword] = useState(false) const [isLoading, setIsLoading] = useState(false) const from = (location.state as any)?.from?.pathname || "/admin/dashboard" const handleLogin = async (e: React.FormEvent) => { e.preventDefault() setIsLoading(true) try { const response = await authService.login({ email, password }) // Check if user is admin if (response.user.role !== 'ADMIN') { toast.error("Access denied. Admin privileges required.") setIsLoading(false) return } // Set user context for error tracking errorTracker.setUser({ id: response.user.id, email: response.user.email, name: `${response.user.firstName} ${response.user.lastName}`, }) // Show success message toast.success("Login successful!") // Navigate to dashboard navigate(from, { replace: true }) } catch (error: any) { console.error('Login error:', error) const message = error.response?.data?.message || "Invalid email or password" toast.error(message) // Track login error errorTracker.trackError(error, { extra: { email, action: 'login' } }) setIsLoading(false) } } return (