- backend: GET/PUT /skeen/frontend/v1/brand leyendo ir.config_parameter skeen.clinic.brand (JSON: nombre, logo_claro, logo_oscuro, pie) con defaults SKEEN; GET publico (el login lo necesita sin sesion), PUT admin con auditoria. frontend_users.xml: 'Administrador SKEEN' -> 'Administrador' - frontend: ClinicBrand + BRAND_DEFAULT en odoo.ts; brand y setBrand en el contexto de auth (fetch al boot + cache localStorage + document.title) - Login/layouts/mensajes/exports leen el brand en vez de strings SKEEN: Login.tsx, SkeenLayout, HomeNestLayout, Cumpleanos (wa + export), Pacientes/Ventas/Cortes/Reportes/Kpis/Alertas/AgendaPrint (titulos), useClinicaPrint (fallback nombre), Login hace GET publico al montar - Configuracion > Clinica: tarjeta 'Identidad de la clinica' (solo admin) para editar nombre/pie/logos con preview - no renombrado (invisible al usuario): rutas API /skeen/*, claves localStorage, nombres de modulos, parametros skeen.* Verificacion API: 11/11 tests OK (defaults, PUT merge, campo invalido ignorado, restore, admin neutral). Deploy: build + rsync + Odoo reiniciado
148 lines
6.3 KiB
TypeScript
148 lines
6.3 KiB
TypeScript
import type { FC, FormEvent } from 'react';
|
|
import { useEffect, useState } from 'react';
|
|
import { useNavigate } from 'react-router-dom';
|
|
import { Eye, EyeOff, LogIn } from 'lucide-react';
|
|
import { Button, Input } from '../components/ui';
|
|
import { odooApi } from '../services/odoo';
|
|
import { useAuth } from '../lib/auth';
|
|
import { useTheme } from '../lib/theme';
|
|
|
|
const Login: FC = () => {
|
|
const { login, brand, setBrand } = useAuth();
|
|
const { theme } = useTheme();
|
|
const navigate = useNavigate();
|
|
const [username, setUsername] = useState('');
|
|
const [password, setPassword] = useState('');
|
|
const [showPassword, setShowPassword] = useState(false);
|
|
const [submitting, setSubmitting] = useState(false);
|
|
const [error, setError] = useState<string | null>(null);
|
|
const isHomeNest = theme === 'homenest';
|
|
// El logo sigue al tema (claro/oscuro) pero el asset lo define el brand.
|
|
const logo = isHomeNest ? brand.logo_oscuro : brand.logo_claro;
|
|
|
|
// Sin sesión aún: el login pide el brand directo (GET público) para pintar
|
|
// nombre/logo de la clínica antes de autenticar.
|
|
useEffect(() => {
|
|
let vivo = true;
|
|
odooApi.getBrand()
|
|
.then((res) => { if (vivo && res.status === 'success' && res.brand) setBrand(res.brand); })
|
|
.catch(() => { /* queda el brand cacheado/default */ });
|
|
return () => { vivo = false; };
|
|
}, [setBrand]);
|
|
|
|
const onSubmit = async (e: FormEvent) => {
|
|
e.preventDefault();
|
|
setError(null);
|
|
if (!username.trim() || !password) {
|
|
setError('Escribe usuario y contraseña');
|
|
return;
|
|
}
|
|
try {
|
|
setSubmitting(true);
|
|
await login(username.trim(), password);
|
|
navigate('/', { replace: true });
|
|
} catch (err) {
|
|
// Mensajes amigables: nunca mostrar errores técnicos crudos.
|
|
const msg = err instanceof Error ? err.message : '';
|
|
if (msg.includes('Credenciales inválidas') || msg.includes('401')) {
|
|
setError('Usuario o contraseña incorrectos');
|
|
} else {
|
|
setError('No se pudo iniciar sesión. Intenta de nuevo.');
|
|
}
|
|
} finally {
|
|
setSubmitting(false);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<div
|
|
className="min-h-screen flex items-center justify-center p-4 relative overflow-hidden transition-colors"
|
|
style={{ backgroundColor: isHomeNest ? 'var(--bg)' : 'var(--color-dark)' }}
|
|
>
|
|
{/* Círculos decorativos de la paleta */}
|
|
<div
|
|
className="absolute top-[-10%] right-[-5%] w-72 h-72 rounded-full blur-3xl"
|
|
style={{ backgroundColor: isHomeNest ? 'var(--color-coral)' : 'var(--color-coral)', opacity: isHomeNest ? 0.2 : 0.2 }}
|
|
/>
|
|
<div
|
|
className="absolute bottom-[-10%] left-[-5%] w-80 h-80 rounded-full blur-3xl"
|
|
style={{ backgroundColor: isHomeNest ? 'var(--color-mint)' : 'var(--color-mint)', opacity: isHomeNest ? 0.3 : 0.15 }}
|
|
/>
|
|
<div
|
|
className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-96 h-96 rounded-full blur-3xl"
|
|
style={{ backgroundColor: isHomeNest ? 'var(--color-sky)' : 'var(--color-lilac)', opacity: isHomeNest ? 0.4 : 0.1 }}
|
|
/>
|
|
|
|
<div className="w-full max-w-sm relative z-10">
|
|
<div className="text-center mb-10">
|
|
<img
|
|
src={logo}
|
|
alt={brand.nombre}
|
|
className="h-10 w-auto object-contain mx-auto mb-6"
|
|
/>
|
|
<h1 className="font-display text-3xl mb-2 tracking-wide" style={{ color: isHomeNest ? 'var(--text-heading)' : '#fff' }}>Bienvenido</h1>
|
|
<p className="text-sm" style={{ color: isHomeNest ? 'var(--text-muted)' : 'rgba(255,255,255,0.6)' }}>Inicia sesión para continuar</p>
|
|
</div>
|
|
|
|
<form
|
|
onSubmit={onSubmit}
|
|
className="rounded-3xl p-7 space-y-5 border"
|
|
style={{
|
|
backgroundColor: isHomeNest ? 'var(--surface)' : 'rgba(255,255,255,0.05)',
|
|
borderColor: isHomeNest ? 'var(--border)' : 'rgba(255,255,255,0.1)',
|
|
backdropFilter: isHomeNest ? 'none' : 'blur(8px)',
|
|
}}
|
|
>
|
|
<Input
|
|
label="Usuario"
|
|
value={username}
|
|
onChange={(e) => setUsername(e.target.value)}
|
|
autoComplete="username"
|
|
autoFocus
|
|
inputClassName={isHomeNest
|
|
? 'bg-theme-bg border-theme-border-strong text-theme-heading placeholder:text-theme-muted/60 focus:border-theme-accent focus:ring-theme-accent/30'
|
|
: 'bg-theme-surface/10 border-white/10 text-white placeholder:text-white/40 focus:border-theme-accent focus:ring-theme-accent/30'
|
|
}
|
|
labelClassName={isHomeNest ? 'text-theme-muted' : 'text-white/70'}
|
|
/>
|
|
<div className="relative">
|
|
<Input
|
|
label="Contraseña"
|
|
type={showPassword ? 'text' : 'password'}
|
|
value={password}
|
|
onChange={(e) => setPassword(e.target.value)}
|
|
autoComplete="current-password"
|
|
inputClassName={`pr-10 ${isHomeNest
|
|
? 'bg-theme-bg border-theme-border-strong text-theme-heading placeholder:text-theme-muted/60 focus:border-theme-accent focus:ring-theme-accent/30'
|
|
: 'bg-theme-surface/10 border-white/10 text-white placeholder:text-white/40 focus:border-theme-accent focus:ring-theme-accent/30'
|
|
}`}
|
|
labelClassName={isHomeNest ? 'text-theme-muted' : 'text-white/70'}
|
|
/>
|
|
<button
|
|
type="button"
|
|
onClick={() => setShowPassword((v) => !v)}
|
|
aria-label={showPassword ? 'Ocultar contraseña' : 'Mostrar contraseña'}
|
|
title={showPassword ? 'Ocultar contraseña' : 'Mostrar contraseña'}
|
|
className="absolute right-3 bottom-2.5 p-1 hover:opacity-80"
|
|
style={{ color: isHomeNest ? 'var(--text-muted)' : 'rgba(255,255,255,0.5)' }}
|
|
>
|
|
{showPassword ? <EyeOff size={16} /> : <Eye size={16} />}
|
|
</button>
|
|
</div>
|
|
{error && <p className="text-sm" style={{ color: 'var(--color-coral)' }}>{error}</p>}
|
|
<Button type="submit" className="w-full" loading={submitting}>
|
|
<LogIn size={16} className="mr-2" />
|
|
Entrar
|
|
</Button>
|
|
</form>
|
|
|
|
<p className="text-center text-xs mt-6" style={{ color: isHomeNest ? 'var(--text-muted)' : 'rgba(255,255,255,0.3)' }}>
|
|
{brand.pie}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default Login;
|