diff --git a/frontend/src/components/GuildRenameForm.tsx b/frontend/src/components/GuildRenameForm.tsx new file mode 100644 index 0000000..a5206e8 --- /dev/null +++ b/frontend/src/components/GuildRenameForm.tsx @@ -0,0 +1,114 @@ +import { useState } from 'react' +import { redirectToStripeCheckout } from '../stripe' + +interface Props { + url: string + csrfToken: string + guilds: string[] +} + +export function GuildRenameForm({ url, csrfToken, guilds }: Props) { + const [oldName, setOldName] = useState('') + const [newName, setNewName] = useState('') + const [confName, setConfName] = useState('') + const [password, setPassword] = useState('') + const [token, setToken] = useState('') + const [busy, setBusy] = useState(false) + const [message, setMessage] = useState<{ ok: boolean; html: string } | null>(null) + + async function handleSubmit(e: React.FormEvent) { + e.preventDefault() + if (busy) return + setBusy(true) + setMessage(null) + + const body = new URLSearchParams() + body.set('old-guild-name', oldName) + body.set('new-guild-name', newName.trim()) + body.set('conf-new-guild-name', confName.trim()) + body.set('cur-password', password.trim()) + body.set('security-token', token.trim()) + body.set('csrfmiddlewaretoken', csrfToken) + + try { + const resp = await fetch(url, { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + 'X-CSRFToken': csrfToken, + Accept: 'application/json', + }, + credentials: 'same-origin', + body: body.toString(), + }) + if (!resp.ok) throw new Error(`HTTP ${resp.status}`) + const data: { success?: boolean; message?: string; session_id?: string; stripe_public_key?: string } = + await resp.json() + if (data.success && data.session_id && data.stripe_public_key) { + await redirectToStripeCheckout(data.stripe_public_key, data.session_id) + return + } + setMessage({ ok: !!data.success, html: data.message || '' }) + setBusy(false) + } catch { + setMessage({ ok: false, html: 'Error al iniciar el pago. Inténtalo más tarde.' }) + setBusy(false) + } + } + + return ( + <> +
+La herramienta Renombrar hermandad te permite cambiar de nombre a una hermandad de la cual seas Maestro de Hermandad.