fix(admin): layout 3 columnas en invite form, banner de confirmación visible
Email/Organización/botón en una fila en desktop, apilado en mobile. El mensaje de éxito/error ahora es un banner (no texto inline) visible al menos 4s o hasta que el usuario vuelva a tocar el formulario. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
'use client'
|
||||
import { useActionState } from 'react'
|
||||
import { useActionState, useEffect, useState } from 'react'
|
||||
import { inviteUser, type InviteUserResult } from '@/app/actions/invite-user'
|
||||
|
||||
interface OrgOption {
|
||||
@@ -8,6 +8,7 @@ interface OrgOption {
|
||||
}
|
||||
|
||||
const INITIAL_STATE: InviteUserResult = { success: false, error: '' }
|
||||
const BANNER_VISIBLE_MS = 4000
|
||||
|
||||
const ERROR_MESSAGES: Record<string, string> = {
|
||||
no_autenticado: 'Tu sesión expiró — volvé a iniciar sesión.',
|
||||
@@ -30,38 +31,59 @@ export function InviteForm({ organizations }: { organizations: OrgOption[] }) {
|
||||
async (_prev: InviteUserResult, formData: FormData) => inviteUser(formData),
|
||||
INITIAL_STATE
|
||||
)
|
||||
const [bannerVisible, setBannerVisible] = useState(false)
|
||||
|
||||
// Banner visible al menos BANNER_VISIBLE_MS tras cada resultado nuevo, o
|
||||
// hasta que el usuario vuelva a tocar el formulario (lo que pase primero).
|
||||
useEffect(() => {
|
||||
const hasMessage = state.success || (!state.success && state.error !== '')
|
||||
setBannerVisible(hasMessage)
|
||||
if (!hasMessage) return
|
||||
const timer = setTimeout(() => setBannerVisible(false), BANNER_VISIBLE_MS)
|
||||
return () => clearTimeout(timer)
|
||||
}, [state])
|
||||
|
||||
return (
|
||||
<form action={formAction} className="login-form">
|
||||
<div className="login-field">
|
||||
<label htmlFor="email" className="login-label">Email</label>
|
||||
<input
|
||||
id="email"
|
||||
name="email"
|
||||
type="email"
|
||||
required
|
||||
disabled={isPending}
|
||||
className="text-short-input"
|
||||
/>
|
||||
<form
|
||||
action={formAction}
|
||||
className="invite-form"
|
||||
onChange={() => setBannerVisible(false)}
|
||||
>
|
||||
<div className="invite-form-row">
|
||||
<div className="login-field">
|
||||
<label htmlFor="email" className="login-label">Email</label>
|
||||
<input
|
||||
id="email"
|
||||
name="email"
|
||||
type="email"
|
||||
required
|
||||
disabled={isPending}
|
||||
className="text-short-input"
|
||||
/>
|
||||
</div>
|
||||
<div className="login-field">
|
||||
<label htmlFor="orgId" className="login-label">Organización</label>
|
||||
<select id="orgId" name="orgId" required disabled={isPending} className="admin-survey-select">
|
||||
<option value="">Seleccioná una organización</option>
|
||||
{organizations.map((org) => (
|
||||
<option key={org.id} value={org.id}>{org.name}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" disabled={isPending} className="login-submit">
|
||||
{isPending ? 'Enviando…' : 'Enviar invitación'}
|
||||
</button>
|
||||
</div>
|
||||
<div className="login-field">
|
||||
<label htmlFor="orgId" className="login-label">Organización</label>
|
||||
<select id="orgId" name="orgId" required disabled={isPending} className="admin-survey-select">
|
||||
<option value="">Seleccioná una organización</option>
|
||||
{organizations.map((org) => (
|
||||
<option key={org.id} value={org.id}>{org.name}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
{!state.success && state.error && (
|
||||
<p role="alert" className="field-error login-error">{describeError(state.error)}</p>
|
||||
{bannerVisible && !state.success && state.error && (
|
||||
<p role="alert" className="invite-banner invite-banner-error">
|
||||
{describeError(state.error)}
|
||||
</p>
|
||||
)}
|
||||
{state.success && (
|
||||
<p className="admin-subtitle" role="status">Invitación enviada correctamente.</p>
|
||||
{bannerVisible && state.success && (
|
||||
<p role="status" className="invite-banner invite-banner-success">
|
||||
Invitación enviada correctamente.
|
||||
</p>
|
||||
)}
|
||||
<button type="submit" disabled={isPending} className="login-submit">
|
||||
{isPending ? 'Enviando…' : 'Enviar invitación'}
|
||||
</button>
|
||||
</form>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user