6f52d325a6
Sitios de voto: los 4 apuntaban a las fichas de UltimoWoW en los rankings con SUS ids (Gtop100 94649, pingUsername 91402, etc.). No era cosmética: cada voto de nuestros jugadores subía a UltimoWoW en el ranking. Se cambian nombre e ids por un 236588 de relleno, así el enlace deja de acreditar a otro servidor. Las fichas reales de NightSpire están por crear; entonces habrá que poner sus ids. Nota legal: decía "Error 404 es la empresa que representa el servicio", heredado de ultimowow. Al renombrar la marca pasaba a afirmar que una empresa ajena representa a NightSpire, lo cual es falso. Se quita la empresa en ES y EN. Prefijo uw- (de UltimoWoW) -> ns-: 100 identificadores en 11 ficheros (clases CSS, ids de formulario, eventos y la cookie de consentimiento, que pasa a ns_cookie_consent; a los usuarios les reaparecerá el aviso una vez). Se comprobó antes que el CSS del tema no define ninguna clase uw-, así que no rompe estilos. btn-ns-form y ns-cookie-btn-customize se usan sin estar definidas, pero ya era así antes del cambio: eran clases muertas. Repo de Gitea renombrado Inna/NovaWoW -> Inna/NightSpire (era la marca vieja más visible de /changelogs, que forma la URL de cada commit). Gitea redirige la URL antigua con 301. Se actualizan el remoto y lib/changelog.ts. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
151 lines
5.3 KiB
TypeScript
151 lines
5.3 KiB
TypeScript
'use client'
|
|
|
|
import { useState } from 'react'
|
|
import { useTranslations, useLocale } from 'next-intl'
|
|
import type { GmGuild } from '@/lib/guild'
|
|
import { PaymentMethodSelect, pdCostOf, type PayMethod } from '@/components/PaymentMethodSelect'
|
|
|
|
function renameErrorKey(error?: string): string {
|
|
switch (error) {
|
|
case 'missingFields':
|
|
case 'invalidName':
|
|
case 'invalidToken':
|
|
case 'notGuildMaster':
|
|
case 'nameTaken':
|
|
case 'soapError':
|
|
case 'notAuthenticated':
|
|
return error
|
|
case 'insufficientPd': // pago con PD sin saldo -> mensaje específico de hermandad
|
|
return 'insufficientPoints'
|
|
case 'fulfillFailed': // el renombrado por SOAP no se aplicó (se reembolsó)
|
|
return 'soapError'
|
|
default:
|
|
return 'generic'
|
|
}
|
|
}
|
|
|
|
export function RenameGuildForm({ guilds, price, pdBalance }: { guilds: GmGuild[]; price: number; pdBalance: number }) {
|
|
const t = useTranslations('Points')
|
|
const tpay = useTranslations('Pay')
|
|
const locale = useLocale()
|
|
const renameError = (error?: string) => t(`renameGuild.errors.${renameErrorKey(error)}`)
|
|
const [guildId, setGuildId] = useState('')
|
|
const [newName, setNewName] = useState('')
|
|
const [token, setToken] = useState('')
|
|
const [showToken, setShowToken] = useState(false)
|
|
const [method, setMethod] = useState<PayMethod>(pdBalance >= pdCostOf(price) ? 'pd' : 'sumup')
|
|
const [busy, setBusy] = useState(false)
|
|
const [message, setMessage] = useState<{ ok: boolean; text: string } | null>(null)
|
|
|
|
if (guilds.length === 0) {
|
|
return (
|
|
<div className="centered">
|
|
<br />
|
|
<span>{t('renameGuild.noGuilds')}</span>
|
|
<br />
|
|
</div>
|
|
)
|
|
}
|
|
|
|
async function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
|
|
e.preventDefault()
|
|
if (busy) return
|
|
if (!guildId || !newName.trim() || !token.trim()) {
|
|
setMessage({ ok: false, text: renameError('missingFields') })
|
|
return
|
|
}
|
|
const amount = method === 'pd' ? tpay('pdCost', { cost: pdCostOf(price) }) : tpay('eur', { price })
|
|
if (!window.confirm(tpay('confirm', { amount }))) return
|
|
|
|
setBusy(true)
|
|
setMessage(null)
|
|
try {
|
|
const res = await fetch('/api/guild/rename/checkout', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
credentials: 'same-origin',
|
|
body: JSON.stringify({ guildId: Number(guildId), newName: newName.trim(), token: token.trim(), provider: method, locale }),
|
|
})
|
|
const data: { success?: boolean; url?: string; error?: string } = await res.json()
|
|
if (data.success && data.url) {
|
|
window.location.href = data.url // éxito PD, o Checkout (Stripe/SumUp)
|
|
return
|
|
}
|
|
setMessage({ ok: false, text: renameError(data.error) })
|
|
setBusy(false)
|
|
} catch {
|
|
setMessage({ ok: false, text: renameError() })
|
|
setBusy(false)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="centered">
|
|
<form noValidate id="ns-rename-guild-form" onSubmit={handleSubmit} acceptCharset="utf-8">
|
|
<table className="middle-center-table">
|
|
<tbody>
|
|
<tr>
|
|
<td>
|
|
<select value={guildId} onChange={(e) => setGuildId(e.target.value)} required>
|
|
<option value="" disabled>{t('renameGuild.selectGuild')}</option>
|
|
{guilds.map((g) => (
|
|
<option key={g.guildid} value={g.guildid}>{g.name}</option>
|
|
))}
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<input
|
|
type="text"
|
|
maxLength={24}
|
|
name="new-guild-name"
|
|
placeholder={t('renameGuild.newNamePlaceholder')}
|
|
value={newName}
|
|
onChange={(e) => setNewName(e.target.value)}
|
|
required
|
|
/>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<input
|
|
type={showToken ? 'text' : 'password'}
|
|
maxLength={6}
|
|
id="security-token"
|
|
placeholder={t('renameGuild.tokenPlaceholder')}
|
|
value={token}
|
|
onChange={(e) => setToken(e.target.value)}
|
|
required
|
|
/>{' '}
|
|
<span
|
|
className={`far ${showToken ? 'fa-eye-slash' : 'fa-eye'} toggle-token`}
|
|
role="button"
|
|
tabIndex={0}
|
|
onClick={() => setShowToken((s) => !s)}
|
|
/>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<PaymentMethodSelect value={method} onChange={setMethod} priceEur={price} pdBalance={pdBalance} />
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<button type="submit" className="rename-guild-button" disabled={busy}>
|
|
{busy ? t('renameGuild.renaming') : t('renameGuild.renameButton')}
|
|
</button>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</form>
|
|
<hr />
|
|
<div className="alert-message" id="rename-guild-response" style={{ display: message ? 'block' : 'none' }}>
|
|
{message && <span className={message.ok ? 'ok-form-response' : 'red-form-response'}>{message.text}</span>}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|