e10f73b12a
Como el original (/store-bennu). El slug sale de acore_auth.realmlist, así que no puede ser una carpeta fija: lo resuelve la ruta dinámica `[realm]`, que ya servía /<slug>-realm y /<slug>-players con este mismo patrón. Solo hubo que añadirle el tipo `store`; el contenido de la página se mueve a components/StorePage.tsx. /store da 404 sin código extra: al no existir ya la carpeta estática `store`, entra por `[realm]`, no resuelve y cae en el notFound() que ya estaba. Enlaces actualizados: el de /my-account (AccountTools, que es cliente y recibe el href ya calculado) y el cancelUrl de la pasarela, que devolvía a /store. Verificado: /es/store-trinity y /en/store-trinity dan 200 y la tienda carga el catálogo; /es/store y /en/store dan 404; un slug ajeno (/es/store-bennu) también 404; /es/trinity-realm y /es/trinity-players siguen bien; y el enlace de /my-account apunta a /es/store-trinity. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
72 lines
2.6 KiB
TypeScript
72 lines
2.6 KiB
TypeScript
import type { Metadata } from 'next'
|
|
import { getTranslations, setRequestLocale } from 'next-intl/server'
|
|
import { notFound } from 'next/navigation'
|
|
import { getRealmName, realmSlug } from '@/lib/realm'
|
|
import { RealmInfo } from '@/components/RealmInfo'
|
|
import { StorePage } from '@/components/StorePage'
|
|
import { PlayersBoard } from '@/components/PlayersBoard'
|
|
|
|
export const dynamic = 'force-dynamic'
|
|
|
|
type Kind = 'realm' | 'players' | 'store'
|
|
|
|
// Rutas dinámicas del reino (el slug viene de acore_auth.realmlist):
|
|
// /<slug>-realm → información del reino (Rates/Horarios)
|
|
// /<slug>-players → estadísticas de personajes (datos reales de la BD)
|
|
// /store-<slug> → la tienda (así la nombra el original: /store-bennu)
|
|
// Cualquier otro valor cae en notFound(), y por eso /store a secas da 404: al no
|
|
// existir ya una ruta estática `store`, entra por aquí y no resuelve.
|
|
async function resolve(param: string): Promise<{ name: string; kind: Kind } | null> {
|
|
const name = await getRealmName()
|
|
const slug = realmSlug(name)
|
|
if (param === `${slug}-realm`) return { name, kind: 'realm' }
|
|
if (param === `${slug}-players`) return { name, kind: 'players' }
|
|
if (param === `store-${slug}`) return { name, kind: 'store' }
|
|
return null
|
|
}
|
|
|
|
export async function generateMetadata({
|
|
params,
|
|
}: {
|
|
params: Promise<{ locale: string; realm: string }>
|
|
}): Promise<Metadata> {
|
|
const { realm } = await params
|
|
const r = await resolve(realm)
|
|
if (!r) return {}
|
|
if (r.kind === 'store') {
|
|
const t = await getTranslations({ locale: (await params).locale, namespace: 'Store' })
|
|
return { title: `${t('title')} - ${r.name}` }
|
|
}
|
|
return { title: `${r.kind === 'players' ? 'Personajes' : 'Reino'} - ${r.name}` }
|
|
}
|
|
|
|
export default async function RealmPage({
|
|
params,
|
|
}: {
|
|
params: Promise<{ locale: string; realm: string }>
|
|
}) {
|
|
const { locale, realm } = await params
|
|
setRequestLocale(locale)
|
|
const r = await resolve(realm)
|
|
if (!r) notFound()
|
|
// La tienda trae su propia cabecera y sus comprobaciones de sesión.
|
|
if (r.kind === 'store') return <StorePage locale={locale} realm={r.name} />
|
|
|
|
const t = await getTranslations('Misc')
|
|
|
|
const heading = r.kind === 'players' ? t('realm.charactersHeading') : t('realm.realmHeading')
|
|
|
|
return (
|
|
<div className="main-page">
|
|
<div className="middle-content">
|
|
<div className="body-content">
|
|
<div className="title-content">
|
|
<h1>{heading} - <span className="blue-info">{r.name.toUpperCase()}</span></h1>
|
|
</div>
|
|
{r.kind === 'realm' ? <RealmInfo /> : <PlayersBoard />}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|