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

89 lines
3.5 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 { useAuth } from "@/lib/auth";
import { useRouter } from "next/navigation";
import Link from "next/link";
export default function RegisterPage() {
const { register } = useAuth();
const router = useRouter();
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [inviteCode, setInviteCode] = useState("");
const [error, setError] = useState("");
const [loading, setLoading] = useState(false);
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setError("");
if (password.length < 6) {
setError("密码至少6位");
return;
}
setLoading(true);
try {
await register(email, password, inviteCode);
router.push("/");
} catch (err: any) {
setError(err.message || "注册失败");
} finally {
setLoading(false);
}
};
return (
<div className="min-h-screen bg-slate-50 flex items-center justify-center p-4">
<div className="w-full max-w-md">
<div className="bg-white rounded-xl shadow-sm border border-slate-200 p-8">
<div className="text-center mb-8">
<h1 className="text-2xl font-bold text-slate-800"> Arbitrage Engine</h1>
<p className="text-slate-500 text-sm mt-2"></p>
</div>
<form onSubmit={handleSubmit} className="space-y-4">
<div>
<label className="block text-sm font-medium text-slate-700 mb-1"></label>
<input
type="text" value={inviteCode} onChange={e => setInviteCode(e.target.value.toUpperCase())}
className="w-full px-3 py-2 border border-slate-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent font-mono tracking-wider"
placeholder="输入邀请码" required
/>
</div>
<div>
<label className="block text-sm font-medium text-slate-700 mb-1"></label>
<input
type="email" value={email} onChange={e => setEmail(e.target.value)}
className="w-full px-3 py-2 border border-slate-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
placeholder="you@example.com" required
/>
</div>
<div>
<label className="block text-sm font-medium text-slate-700 mb-1"></label>
<input
type="password" value={password} onChange={e => setPassword(e.target.value)}
className="w-full px-3 py-2 border border-slate-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
placeholder="至少6位" required minLength={6}
/>
</div>
{error && <p className="text-red-500 text-sm">{error}</p>}
<button
type="submit" disabled={loading}
className="w-full bg-blue-600 hover:bg-blue-700 text-white py-2.5 rounded-lg font-medium text-sm transition-colors disabled:opacity-50"
>
{loading ? "注册中..." : "注册"}
</button>
</form>
<p className="text-center text-sm text-slate-500 mt-6">
{" "}
<Link href="/login" className="text-blue-600 hover:underline"></Link>
</p>
</div>
</div>
</div>
);
}