import { useState } from 'react' // Reusable "create a game account" form (its own username + password — the game // client credentials, distinct from the website login). Calls `submit(account, // password)` which should POST /player/shard/account; on success calls onCreated. // Used by the player portal (self-serve) and the invite-accept page alike. export default function CreateGameAccountForm({ submit, onCreated, compact = false }) { const [account, setAccount] = useState('') const [password, setPassword] = useState('') const [busy, setBusy] = useState(false) const [msg, setMsg] = useState('') const [error, setError] = useState('') async function onSubmit(e) { e.preventDefault() setMsg(''); setError('') if (!/^[A-Za-z0-9][A-Za-z0-9_.-]{2,29}$/.test(account)) { return setError('Account name must be 3–30 letters, numbers, . _ or -.') } if (password.length < 8) return setError('Password must be at least 8 characters.') setBusy(true) try { await submit(account, password) setMsg(`Game account “${account}” created and linked.`) setAccount(''); setPassword('') if (onCreated) await onCreated() } catch (err) { if (err.status === 409) setError('That account name is already taken.') else if (err.status === 429) setError('The account limit for your network has been reached.') else if (err.status === 403) setError('Game-account signup is not available right now.') else if (err.status === 503) setError('The game server is unavailable — try again shortly.') else setError(err.message || 'Could not create the account right now.') } finally { setBusy(false) } } return (
) }