Files
NightSpire/web-next/app/[locale]/select-account/SelectAccountForm.tsx
T
Inna 3e47a3d240 Aplica el sistema de diseño (nw-input/nw-btn/nw-card) a todas las páginas
Reemplazo masivo de los estilos sueltos repetidos por las clases del sistema visual
en ~20 componentes/páginas (auth, cuenta, servicios de personaje, foro, admin, voto):
- inputs -> .nw-input, botones primarios -> .nw-btn, tarjetas -> .nw-card.
Cohesión visual completa con la home y la cabecera.

Verificado: build OK, páginas clave 200/redirect correctos, clases aplicadas.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-13 00:13:22 +00:00

57 lines
1.4 KiB
TypeScript

'use client'
import { useState } from 'react'
import { useTranslations } from 'next-intl'
import { useRouter } from '@/i18n/navigation'
interface GameAccount {
id: number
username: string
}
export function SelectAccountForm({ accounts }: { accounts: GameAccount[] }) {
const t = useTranslations('SelectAccount')
const router = useRouter()
const [busy, setBusy] = useState<number | null>(null)
const [error, setError] = useState<string | null>(null)
async function select(id: number) {
if (busy !== null) return
setBusy(id)
setError(null)
try {
const res = await fetch('/api/auth/select-account', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
credentials: 'same-origin',
body: JSON.stringify({ accountId: id }),
})
const data: { success?: boolean } = await res.json()
if (data.success) router.push('/account')
else {
setError(t('error'))
setBusy(null)
}
} catch {
setError(t('error'))
setBusy(null)
}
}
return (
<div className="space-y-2">
{accounts.map((a) => (
<button
key={a.id}
onClick={() => select(a.id)}
disabled={busy !== null}
className="w-full nw-btn disabled:opacity-60"
>
{busy === a.id ? t('entering') : a.username}
</button>
))}
{error && <p className="text-red-400">{error}</p>}
</div>
)
}