651d8deafc
Se externaliza el texto español hardcodeado de ~55 archivos a next-intl y se añaden traducciones al inglés, con paridad de claves es/en. Nuevos namespaces: History, CharService, CharServiceB, Points, Legal, UI, Misc (+ altas en Common/Admin). - Historiales (PD/PV, transacciones, sanciones, seguridad), servicios de personaje (transfer, send-gift, quest, restore-*, change-*, customize, level-up, gold, rename), PD/pagos (d-points, trade, promo, transfer-dp, rename-guild, DPointsTabs), páginas legales (cookies, privacidad, términos, reembolsos, aviso legal, contacto), layout (cabecera, footer, cookies, 2FA, descargas, jugadores, recluta) y páginas varias (home, reino, ayuda, addons, 2falogin). - Textos con markup inline via t.rich; interpolación con ICU. - Componente <NoteLegend/> para la leyenda NOTA/NOTE compartida. - payLabel/confirmText de los servicios de pago traducidos. - Verificado: tsc OK, next build OK, todas las claves t() resuelven en es y en, todos los t.rich casan etiquetas, páginas 200 en /es/ y /en/ sin claves crudas. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
84 lines
2.6 KiB
TypeScript
84 lines
2.6 KiB
TypeScript
'use client'
|
|
|
|
import { useState } from 'react'
|
|
import { useTranslations } from 'next-intl'
|
|
import { useRouter } from '@/i18n/navigation'
|
|
|
|
function promoErrorKey(error?: string): string {
|
|
switch (error) {
|
|
case 'missingCode':
|
|
case 'notFound':
|
|
case 'expired':
|
|
case 'exhausted':
|
|
case 'alreadyUsed':
|
|
case 'notAuthenticated':
|
|
return error
|
|
default:
|
|
return 'generic'
|
|
}
|
|
}
|
|
|
|
export function PromoCodeForm() {
|
|
const t = useTranslations('Points')
|
|
const promoError = (error?: string) => t(`promo.errors.${promoErrorKey(error)}`)
|
|
const router = useRouter()
|
|
const [code, setCode] = useState('')
|
|
const [busy, setBusy] = useState(false)
|
|
const [message, setMessage] = useState<{ ok: boolean; text: string } | null>(null)
|
|
|
|
async function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
|
|
e.preventDefault()
|
|
if (busy || !code.trim()) return
|
|
setBusy(true)
|
|
setMessage(null)
|
|
try {
|
|
const res = await fetch('/api/promo/redeem', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
credentials: 'same-origin',
|
|
body: JSON.stringify({ code: code.trim() }),
|
|
})
|
|
const data: { success?: boolean; error?: string; pd?: number; pv?: number } = await res.json()
|
|
if (data.success) {
|
|
const parts: string[] = []
|
|
if (data.pd) parts.push(t('promo.rewardPd', { pd: data.pd }))
|
|
if (data.pv) parts.push(t('promo.rewardPv', { pv: data.pv }))
|
|
const reward = parts.length ? parts.join(` ${t('promo.and')} `) : t('promo.rewardDefault')
|
|
setMessage({ ok: true, text: t('promo.success', { reward }) })
|
|
setCode('')
|
|
router.refresh()
|
|
} else {
|
|
setMessage({ ok: false, text: promoError(data.error) })
|
|
}
|
|
} catch {
|
|
setMessage({ ok: false, text: promoError() })
|
|
} finally {
|
|
setBusy(false)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="centered">
|
|
<br />
|
|
<form onSubmit={handleSubmit} acceptCharset="utf-8">
|
|
<input
|
|
type="text"
|
|
maxLength={64}
|
|
placeholder={t('promo.placeholder')}
|
|
value={code}
|
|
onChange={(e) => setCode(e.target.value)}
|
|
required
|
|
/>
|
|
<br />
|
|
<button type="submit" className="dnt-button" disabled={busy || !code.trim()}>
|
|
{busy ? t('promo.redeeming') : t('promo.redeemButton')}
|
|
</button>
|
|
</form>
|
|
<hr />
|
|
<div className="alert-message" style={{ display: message ? 'block' : 'none' }}>
|
|
{message && <span className={message.ok ? 'ok-form-response' : 'red-form-response'}>{message.text}</span>}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|