Del look editorial (verde #1B4332, esquinas a 0, botones en mayusculas) al sistema NovaSpark: primario azul #2563EB, detalle naranja #F97316, fondo #F8FAFC con tarjetas blancas rounded-xl + shadow-sm, chips rounded-full semanticos, focus ring azul, transiciones 100-200ms. Incluye headers de tabla en los PDFs (cotizador y estado de cuenta).
91 lines
3.3 KiB
TypeScript
91 lines
3.3 KiB
TypeScript
import { useState, type FormEvent } from 'react'
|
|
import { login, ErrorLogin, type UsuarioSesion } from '../services/auth'
|
|
|
|
/** Pantalla de login NovaSpark: marca FRASA, usuario + contraseña, Enter envía */
|
|
export default function LoginScreen({ onLogin }: { onLogin: (usuario: UsuarioSesion) => void }) {
|
|
const [username, setUsername] = useState('')
|
|
const [password, setPassword] = useState('')
|
|
const [error, setError] = useState<string | null>(null)
|
|
const [cargando, setCargando] = useState(false)
|
|
|
|
async function enviar(e: FormEvent) {
|
|
e.preventDefault()
|
|
setError(null)
|
|
setCargando(true)
|
|
try {
|
|
onLogin(await login(username, password))
|
|
} catch (err) {
|
|
setError(err instanceof ErrorLogin ? err.message : 'Usuario o contraseña incorrectos')
|
|
} finally {
|
|
setCargando(false)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="flex min-h-screen items-center justify-center bg-[#F8FAFC] px-4">
|
|
<div className="w-full max-w-sm rounded-xl border border-[#E5E7EB] bg-white p-8 shadow-sm">
|
|
<div className="mb-8 text-center">
|
|
<p className="text-lg font-bold tracking-wide">
|
|
FRASA<span className="text-[#F97316]">.</span>
|
|
</p>
|
|
<p className="mt-2 text-xs font-medium text-[#64748B]">
|
|
Acceso al ecosistema
|
|
</p>
|
|
</div>
|
|
<form onSubmit={enviar} className="space-y-6">
|
|
<div>
|
|
<label
|
|
htmlFor="login-usuario"
|
|
className="mb-2 block text-xs font-medium text-[#4B5563]"
|
|
>
|
|
Usuario
|
|
</label>
|
|
<input
|
|
id="login-usuario"
|
|
type="text"
|
|
value={username}
|
|
onChange={(e) => setUsername(e.target.value)}
|
|
autoComplete="username"
|
|
autoFocus
|
|
required
|
|
className="w-full rounded-lg border border-[#D1D5DB] bg-white px-3 py-2.5 text-sm transition-colors focus:border-accent focus:ring-2 focus:ring-accent/20 focus:outline-none"
|
|
/>
|
|
</div>
|
|
<div>
|
|
<label
|
|
htmlFor="login-password"
|
|
className="mb-2 block text-xs font-medium text-[#4B5563]"
|
|
>
|
|
Contraseña
|
|
</label>
|
|
<input
|
|
id="login-password"
|
|
type="password"
|
|
value={password}
|
|
onChange={(e) => setPassword(e.target.value)}
|
|
autoComplete="current-password"
|
|
required
|
|
className="w-full rounded-lg border border-[#D1D5DB] bg-white px-3 py-2.5 text-sm transition-colors focus:border-accent focus:ring-2 focus:ring-accent/20 focus:outline-none"
|
|
/>
|
|
</div>
|
|
{error && (
|
|
<p
|
|
role="alert"
|
|
className="rounded-lg bg-red-50 px-4 py-3 text-xs font-medium text-red-700"
|
|
>
|
|
{error}
|
|
</p>
|
|
)}
|
|
<button
|
|
type="submit"
|
|
disabled={cargando}
|
|
className="w-full rounded-lg bg-accent px-5 py-2.5 text-sm font-medium text-white shadow-sm transition-all duration-100 ease-out hover:bg-accent-hover disabled:opacity-50"
|
|
>
|
|
{cargando ? 'Entrando…' : 'Entrar'}
|
|
</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|