arbitrage-engine/frontend/app/register/page.tsx

81 lines
3.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use client";
import { useState } from "react";
import { useRouter } from "next/navigation";
export default function RegisterPage() {
const router = useRouter();
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [discordId, setDiscordId] = useState("");
const [error, setError] = useState("");
const [loading, setLoading] = useState(false);
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setLoading(true);
setError("");
try {
const r = await fetch("/api/auth/register", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ email, password, discord_id: discordId || undefined }),
});
const data = await r.json();
if (!r.ok) { setError(data.detail || "注册失败"); return; }
router.push("/login?registered=1");
} catch {
setError("网络错误,请重试");
} finally {
setLoading(false);
}
};
return (
<div className="min-h-[70vh] flex items-center justify-center">
<div className="w-full max-w-md rounded-xl border border-slate-200 bg-white p-8 space-y-6">
<div>
<h1 className="text-2xl font-bold text-slate-900"></h1>
<p className="text-slate-500 text-sm mt-1"></p>
</div>
<form onSubmit={handleSubmit} className="space-y-4">
<div>
<label className="block text-sm text-slate-700 mb-1"></label>
<input
type="email" required value={email} onChange={e => setEmail(e.target.value)}
className="w-full bg-white border border-slate-200 rounded-lg px-3 py-2 text-slate-900 text-sm focus:outline-none focus:border-cyan-500"
placeholder="your@email.com"
/>
</div>
<div>
<label className="block text-sm text-slate-700 mb-1"></label>
<input
type="password" required value={password} onChange={e => setPassword(e.target.value)}
className="w-full bg-white border border-slate-200 rounded-lg px-3 py-2 text-slate-900 text-sm focus:outline-none focus:border-cyan-500"
placeholder="至少8位"
minLength={8}
/>
</div>
<div>
<label className="block text-sm text-slate-700 mb-1">Discord ID <span className="text-slate-500"></span></label>
<input
type="text" value={discordId} onChange={e => setDiscordId(e.target.value)}
className="w-full bg-white border border-slate-200 rounded-lg px-3 py-2 text-slate-900 text-sm focus:outline-none focus:border-cyan-500"
placeholder="例123456789012345678"
/>
</div>
{error && <p className="text-red-400 text-sm">{error}</p>}
<button
type="submit" disabled={loading}
className="w-full bg-cyan-600 hover:bg-cyan-500 disabled:opacity-50 text-white font-medium py-2 rounded-lg text-sm transition-colors"
>
{loading ? "注册中..." : "注册"}
</button>
</form>
<p className="text-center text-sm text-slate-500">
<a href="/login" className="text-blue-600 hover:underline"></a>
</p>
</div>
</div>
);
}