import { FormEvent, useState } from "react"; import { useTranslation } from "react-i18next"; import { Link, useNavigate } from "react-router-dom"; import { authApi } from "@/api"; import { useAuthStore } from "@/store/auth"; import { Button } from "@/components/ui/Button"; import { Input } from "@/components/ui/Input"; import { Card, CardBody } from "@/components/ui/Card"; export function RegisterPage() { const { t } = useTranslation(); const navigate = useNavigate(); const { setAuth } = useAuthStore(); const [email, setEmail] = useState(""); const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(""); const [loading, setLoading] = useState(false); const onSubmit = async (e: FormEvent) => { e.preventDefault(); setError(""); setLoading(true); try { const { access_token, user } = await authApi.register(email, username, password); setAuth(access_token, user); navigate("/dashboard"); } catch (err: any) { setError(err.response?.data?.detail || t("errors.unknown")); } finally { setLoading(false); } }; return (

{t("auth.register_title")}

setEmail(e.target.value)} required /> setUsername(e.target.value)} required /> setPassword(e.target.value)} required minLength={6} /> {error &&

{error}

}

{t("auth.have_account")}

); }