From e1983eee9e529b13fa308ab824350a60d3f9e7ab Mon Sep 17 00:00:00 2001 From: adevopg Date: Mon, 13 Jul 2026 15:28:09 +0000 Subject: [PATCH] =?UTF-8?q?web-next:=20selector=20de=20cuenta=20de=20juego?= =?UTF-8?q?=20(WOW1/WOW2=E2=80=A6)=20en=20/account?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Si la Battle.net tiene más de una cuenta de juego, /account muestra un desplegable «Cargar datos de la cuenta» (WOW1, WOW2…). Al cambiar, fija la cuenta activa en la sesión vía /api/auth/select-account y refresca → toda la página (datos, personajes, servicios, compras) opera sobre la cuenta elegida (la sesión.accountId manda). Con una sola cuenta no aparece (como hasta ahora). components/GameAccountSwitcher.tsx (client) + getGameAccounts en la page. Co-Authored-By: Claude Opus 4.8 (1M context) --- web-next/app/[locale]/account/page.tsx | 9 ++++ web-next/components/GameAccountSwitcher.tsx | 59 +++++++++++++++++++++ web-next/messages/en.json | 3 +- web-next/messages/es.json | 3 +- 4 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 web-next/components/GameAccountSwitcher.tsx diff --git a/web-next/app/[locale]/account/page.tsx b/web-next/app/[locale]/account/page.tsx index d839664..cd34cec 100644 --- a/web-next/app/[locale]/account/page.tsx +++ b/web-next/app/[locale]/account/page.tsx @@ -2,9 +2,11 @@ import { getTranslations, setRequestLocale } from 'next-intl/server' import { redirect, Link } from '@/i18n/navigation' import { getSession } from '@/lib/session' import { getAccountDashboard, getAccountRank } from '@/lib/account' +import { getGameAccounts } from '@/lib/auth' import { isAdmin } from '@/lib/admin' import { PageShell } from '@/components/PageShell' import { AccountTools } from '@/components/AccountTools' +import { GameAccountSwitcher } from '@/components/GameAccountSwitcher' export const dynamic = 'force-dynamic' @@ -39,9 +41,16 @@ export default async function AccountPage({ params }: { params: Promise<{ locale const data = await getAccountDashboard(session) const admin = await isAdmin(session) const rank = getAccountRank(data.dp) + // Cuentas de juego de la Battle.net (para el selector si hay más de una). + const games = await getGameAccounts(session.bnetId ?? 0) return ( + {/* Selector de cuenta de juego (WOW1/WOW2…) si la bnet tiene más de una */} + {games.length > 1 && ( + + )} + {/* Información: dos fieldsets como en Django */}
diff --git a/web-next/components/GameAccountSwitcher.tsx b/web-next/components/GameAccountSwitcher.tsx new file mode 100644 index 0000000..b3ac667 --- /dev/null +++ b/web-next/components/GameAccountSwitcher.tsx @@ -0,0 +1,59 @@ +'use client' + +import { useState } from 'react' +import { useTranslations } from 'next-intl' +import { useRouter } from '@/i18n/navigation' + +/** + * Desplegable para cambiar la cuenta de juego activa (WOW1, WOW2…) cuando la + * Battle.net tiene más de una. Al cambiar, fija la cuenta en la sesión + * (/api/auth/select-account) y refresca → todo /account (datos, personajes, + * servicios, compras…) pasa a operar sobre la cuenta seleccionada. + */ +export function GameAccountSwitcher({ + accounts, + currentId, +}: { + accounts: { id: number; index: number }[] + currentId: number +}) { + const t = useTranslations('Account') + const router = useRouter() + const [busy, setBusy] = useState(false) + + async function onChange(e: React.ChangeEvent) { + const id = Number(e.target.value) + if (id === currentId || busy) return + setBusy(true) + 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 d = await res.json() + if (d.success) router.refresh() + else setBusy(false) + } catch { + setBusy(false) + } + } + + return ( +
+
+

+ {t('switchAccountLabel')}{' '} + +

+
+
+ ) +} diff --git a/web-next/messages/en.json b/web-next/messages/en.json index 7b9ba74..b3df851 100644 --- a/web-next/messages/en.json +++ b/web-next/messages/en.json @@ -151,7 +151,8 @@ "accountName": "Account name", "twofaLabel": "2FA (Two-step verification)", "twofaOff": "Disabled", - "banHistoryLink": "View history" + "banHistoryLink": "View history", + "switchAccountLabel": "Load account data:" }, "SelectAccount": { "title": "Select your game account", diff --git a/web-next/messages/es.json b/web-next/messages/es.json index 0bdc83b..f92a436 100644 --- a/web-next/messages/es.json +++ b/web-next/messages/es.json @@ -151,7 +151,8 @@ "accountName": "Nombre de la cuenta", "twofaLabel": "2FA (Verificación en 2 pasos)", "twofaOff": "Desactivado", - "banHistoryLink": "Consultar historial" + "banHistoryLink": "Consultar historial", + "switchAccountLabel": "Cargar datos de la cuenta:" }, "SelectAccount": { "title": "Selecciona tu cuenta de juego",