3e47a3d240
Reemplazo masivo de los estilos sueltos repetidos por las clases del sistema visual en ~20 componentes/páginas (auth, cuenta, servicios de personaje, foro, admin, voto): - inputs -> .nw-input, botones primarios -> .nw-btn, tarjetas -> .nw-card. Cohesión visual completa con la home y la cabecera. Verificado: build OK, páginas clave 200/redirect correctos, clases aplicadas. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
'use client'
|
|
|
|
import { useState } from 'react'
|
|
import { useTranslations } from 'next-intl'
|
|
import { useRouter } from '@/i18n/navigation'
|
|
|
|
export function ReplyForm({ topicId }: { topicId: number }) {
|
|
const t = useTranslations('Forum')
|
|
const router = useRouter()
|
|
const [text, setText] = useState('')
|
|
const [busy, setBusy] = useState(false)
|
|
const [error, setError] = useState<string | null>(null)
|
|
|
|
async function handleSubmit(e: React.FormEvent) {
|
|
e.preventDefault()
|
|
if (busy || !text.trim()) return
|
|
setBusy(true)
|
|
setError(null)
|
|
try {
|
|
const res = await fetch('/api/forum/reply', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
credentials: 'same-origin',
|
|
body: JSON.stringify({ topicId, text }),
|
|
})
|
|
const data: { success?: boolean } = await res.json()
|
|
if (data.success) {
|
|
setText('')
|
|
router.refresh()
|
|
} else {
|
|
setError(t('genericError'))
|
|
}
|
|
} catch {
|
|
setError(t('genericError'))
|
|
} finally {
|
|
setBusy(false)
|
|
}
|
|
}
|
|
|
|
const field = 'nw-input'
|
|
return (
|
|
<form onSubmit={handleSubmit} className="mt-6 space-y-3">
|
|
<textarea value={text} onChange={(e) => setText(e.target.value)} placeholder={t('replyText')} rows={3} className={field} />
|
|
<button type="submit" disabled={busy} className="nw-btn disabled:opacity-60">
|
|
{busy ? t('sending') : t('sendReply')}
|
|
</button>
|
|
{error && <p className="text-red-400">{error}</p>}
|
|
</form>
|
|
)
|
|
}
|