import { useState, type FormEvent } from 'react' import { useNavigate, useLocation } from 'react-router-dom' import { toast } from 'sonner' import { Button } from '@/components/ui/Button' import { Input } from '@/components/ui/Input' import { Label } from '@/components/ui/Label' import { useAuth } from '@/contexts/AuthContext' import axios from 'axios' export function LoginPage() { const { login } = useAuth() const navigate = useNavigate() const location = useLocation() const [email, setEmail] = useState('admin@solutionerp.local') const [password, setPassword] = useState('Admin@123456') const [isSubmitting, setIsSubmitting] = useState(false) async function handleSubmit(e: FormEvent) { e.preventDefault() setIsSubmitting(true) try { await login({ email, password }) const redirectTo = (location.state as { from?: { pathname: string } } | null)?.from?.pathname ?? '/dashboard' navigate(redirectTo, { replace: true }) toast.success('Đăng nhập thành công') } catch (err) { const msg = axios.isAxiosError(err) ? err.response?.data?.detail ?? err.response?.data?.title ?? err.message : 'Lỗi kết nối máy chủ' toast.error(`Đăng nhập thất bại: ${msg}`) } finally { setIsSubmitting(false) } } return (

SOLUTION ERP

Trang quản trị

setEmail(e.target.value)} autoComplete="email" required />
setPassword(e.target.value)} autoComplete="current-password" required />
) }