Download src/components/RegisterView.tsx from xx911121/sdex: direct link, hf CLI and curl.
- Browser
- Download file 7.43 kB
-
https://huggingface.co/spaces/xx911121/sdex/resolve/main/src/components/RegisterView.tsx
- Command line
-
hf download hf://spaces/xx911121/sdex/src/components/RegisterView.tsx
-
curl -L -o RegisterView.tsx https://huggingface.co/spaces/xx911121/sdex/resolve/main/src/components/RegisterView.tsx
7.43 kB
| import React, { useState } from "react"; | |
| import { ScreenId, AppState } from "../types"; | |
| import { ArrowLeft, User, Lock, CircleCheck, AlertCircle } from "lucide-react"; | |
| import { BrandLogo } from "./BrandLogo"; | |
| interface RegisterViewProps { | |
| state: AppState; | |
| onNavigate: (screen: ScreenId) => void; | |
| onSetState: (updater: (prev: AppState) => AppState) => void; | |
| } | |
| export const RegisterView: React.FC<RegisterViewProps> = ({ state, onNavigate, onSetState }) => { | |
| const [username, setUsername] = useState(""); | |
| const [password, setPassword] = useState(""); | |
| const [confirmPassword, setConfirmPassword] = useState(""); | |
| const [error, setError] = useState(""); | |
| const [success, setSuccess] = useState(false); | |
| const handleRegister = (e: React.FormEvent) => { | |
| e.preventDefault(); | |
| if (!username || !password || !confirmPassword) { | |
| setError("请填写所有必填字段 Feel all fields."); | |
| return; | |
| } | |
| if (username.length < 5) { | |
| setError("用户名长度不能少于5个字符 (Username must be >= 5 chars)"); | |
| return; | |
| } | |
| if (password.length < 6) { | |
| setError("密码必须至少有6个字符 (Password must be >= 6 chars)"); | |
| return; | |
| } | |
| if (password !== confirmPassword) { | |
| setError("两次填写的密码不一致 (Passwords mismatch)"); | |
| return; | |
| } | |
| setError(""); | |
| setSuccess(true); | |
| // Auto register the user | |
| onSetState((prev) => ({ | |
| ...prev, | |
| username: username, | |
| isLoggedIn: true, | |
| balance: 14250.00 // Seed initial game trial balance | |
| })); | |
| setTimeout(() => { | |
| onNavigate(ScreenId.HOME); | |
| }, 1500); | |
| }; | |
| return ( | |
| <div className="bg-[#000B14] text-[#d1e4ff] min-h-screen font-sans flex flex-col select-none"> | |
| {/* Header */} | |
| <header className="bg-[#0b2135] h-14 border-b border-[#414755] flex items-center px-4 relative"> | |
| <button | |
| onClick={() => onNavigate(ScreenId.HOME)} | |
| className="p-1 rounded-full text-[#afc6ff] hover:bg-[#22364c]" | |
| > | |
| <ArrowLeft className="w-6 h-6" /> | |
| </button> | |
| <span className="text-white text-base font-bold mx-auto absolute left-1/2 -translate-x-1/2"> | |
| Create Account / 注册会员 | |
| </span> | |
| </header> | |
| {/* Hero Logo Banner */} | |
| <div className="flex flex-col items-center py-10 px-6"> | |
| <BrandLogo className="h-16" alignment="center" /> | |
| <p className="text-xs text-amber-500 font-bold tracking-widest mt-3"> | |
| 港资老牌信誉大牌 · 免流水直充直提 | |
| </p> | |
| </div> | |
| {/* Registration Card */} | |
| <main className="flex-1 px-4 max-w-md mx-auto w-full pb-10"> | |
| <div className="bg-[#0b2135] border border-white/5 rounded-2xl p-6 shadow-xl"> | |
| {success ? ( | |
| <div className="py-8 text-center flex flex-col items-center justify-center animate-pulse"> | |
| <CircleCheck className="w-16 h-16 text-emerald-400 mb-3" /> | |
| <h3 className="text-lg font-bold text-white mb-2">注册成功!</h3> | |
| <p className="text-xs text-[#c1c6d7]">正在为您自动登录并进入游戏中心...</p> | |
| </div> | |
| ) : ( | |
| <form onSubmit={handleRegister} className="space-y-4"> | |
| {error && ( | |
| <div className="bg-red-950/50 border border-red-500/30 text-red-300 rounded-lg p-3 text-xs flex items-center gap-2"> | |
| <AlertCircle className="w-4 h-4 shrink-0 text-red-400" /> | |
| <span>{error}</span> | |
| </div> | |
| )} | |
| {/* Username Input */} | |
| <div className="space-y-1"> | |
| <label className="text-xs font-semibold text-[#c1c6d7]">用户名 (Username) *</label> | |
| <div className="relative"> | |
| <div className="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none text-[#afc6ff]"> | |
| <User className="w-4 h-4" /> | |
| </div> | |
| <input | |
| type="text" | |
| value={username} | |
| onChange={(e) => setUsername(e.target.value.trim().toLowerCase())} | |
| placeholder="请输入5-15位字母加数字" | |
| className="w-full bg-[#001428] border border-[#414755]/50 rounded-xl py-2.5 pl-10 pr-4 text-sm text-white placeholder-slate-500 focus:outline-none focus:border-[#528dff] font-mono text-center tracking-wide" | |
| /> | |
| </div> | |
| </div> | |
| {/* Password Input */} | |
| <div className="space-y-1"> | |
| <label className="text-xs font-semibold text-[#c1c6d7]">登录密码 (Password) *</label> | |
| <div className="relative"> | |
| <div className="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none text-[#afc6ff]"> | |
| <Lock className="w-4 h-4" /> | |
| </div> | |
| <input | |
| type="password" | |
| value={password} | |
| onChange={(e) => setPassword(e.target.value.trim())} | |
| placeholder="请输入密码长度>=6位" | |
| className="w-full bg-[#001428] border border-[#414755]/50 rounded-xl py-2.5 pl-10 pr-4 text-sm text-white placeholder-slate-500 focus:outline-none focus:border-[#528dff] font-mono text-center" | |
| /> | |
| </div> | |
| </div> | |
| {/* Confirm Password Input */} | |
| <div className="space-y-1"> | |
| <label className="text-xs font-semibold text-[#c1c6d7]">确认密码 (Confirm Password) *</label> | |
| <div className="relative"> | |
| <div className="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none text-[#afc6ff]"> | |
| <Lock className="w-4 h-4" /> | |
| </div> | |
| <input | |
| type="password" | |
| value={confirmPassword} | |
| onChange={(e) => setConfirmPassword(e.target.value.trim())} | |
| placeholder="请再次输入相同密码" | |
| className="w-full bg-[#001428] border border-[#414755]/50 rounded-xl py-2.5 pl-10 pr-4 text-sm text-white placeholder-slate-500 focus:outline-none focus:border-[#528dff] font-mono text-center" | |
| /> | |
| </div> | |
| </div> | |
| {/* Submit Buttons */} | |
| <div className="pt-2"> | |
| <button | |
| type="submit" | |
| className="w-full py-3 bg-[#528dff] hover:bg-[#528dff]/90 text-[#00275f] font-bold rounded-xl shadow-lg hover:shadow-xl active:scale-[0.98] transition-all text-sm uppercase tracking-wider cursor-pointer" | |
| > | |
| 立即免费注册 (Register Now) | |
| </button> | |
| </div> | |
| <div className="flex justify-between items-center text-xs pt-2"> | |
| <span className="text-[#c1c6d7]">已有账号?</span> | |
| <button | |
| type="button" | |
| onClick={() => onNavigate(ScreenId.LOGIN)} | |
| className="text-amber-500 hover:underline font-semibold" | |
| > | |
| 返回登录 (Sign In) > | |
| </button> | |
| </div> | |
| </form> | |
| )} | |
| </div> | |
| </main> | |
| </div> | |
| ); | |
| }; | |