import {useState, type FormEvent} from "react"; import {useNavigate, Link} from "react-router-dom"; import {toast} from "sonner"; import {useAuth} from "@/auth"; import {ApiError} from "@/api"; import {Button} from "@/components/ui/button"; import {Input} from "@/components/ui/input"; import {Label} from "@/components/ui/label"; import {Card, CardHeader, CardTitle, CardContent, CardFooter} from "@/components/ui/card"; export function LoginPage() { const {login} = useAuth(); const navigate = useNavigate(); const [form, setForm] = useState({login: "", password: ""}); const [busy, setBusy] = useState(false); const submit = async (e: FormEvent) => { e.preventDefault(); setBusy(true); try { await login(form.login, form.password); navigate("/"); } catch (err) { const msg = err instanceof ApiError ? (err.body?.message ?? "Failed to sign in") : "Network unavailable"; toast.error(msg); } finally { setBusy(false); } }; return ( Sign in
setForm({...form, login: e.target.value})} />
setForm({...form, password: e.target.value})} />
No account yet?  Sign up
); }