página de login
This commit is contained in:
109
frontend/components/LoginPage.tsx
Normal file
109
frontend/components/LoginPage.tsx
Normal file
@@ -0,0 +1,109 @@
|
||||
// components/LoginPage.tsx
|
||||
import React, { useState } from 'react';
|
||||
import { motion } from 'framer-motion';
|
||||
import { Lock, User } from 'lucide-react';
|
||||
import toast from 'react-hot-toast';
|
||||
import { useAuth } from '../utils/AuthContext';
|
||||
|
||||
const LoginPage: React.FC = () => {
|
||||
const { login } = useAuth();
|
||||
const [username, setUsername] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (!username || !password) {
|
||||
toast.error('Introduce usuario y contraseña');
|
||||
return;
|
||||
}
|
||||
|
||||
setIsSubmitting(true);
|
||||
try {
|
||||
await login(username, password);
|
||||
toast.success('Sesión iniciada');
|
||||
} catch (err) {
|
||||
console.error('Error en login', err);
|
||||
const msg =
|
||||
err instanceof Error ? err.message : 'Error al iniciar sesión';
|
||||
toast.error(msg);
|
||||
} finally {
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gradient-to-br from-indigo-500 via-sky-500 to-slate-900 flex items-center justify-center px-4">
|
||||
<motion.div
|
||||
initial={{ opacity: 0, y: 24 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
transition={{ duration: 0.5 }}
|
||||
className="w-full max-w-md bg-white/95 rounded-3xl shadow-2xl p-8 space-y-6"
|
||||
>
|
||||
<div className="space-y-2 text-center">
|
||||
<div className="inline-flex items-center justify-center w-12 h-12 rounded-2xl bg-indigo-100 text-indigo-600 mb-1">
|
||||
<Lock className="w-6 h-6" />
|
||||
</div>
|
||||
<h1 className="text-2xl font-semibold text-slate-900">
|
||||
Beyond Diagnostic
|
||||
</h1>
|
||||
<p className="text-sm text-slate-500">
|
||||
Inicia sesión para acceder al análisis
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
<div className="space-y-1">
|
||||
<label className="block text-sm font-medium text-slate-700">
|
||||
Usuario
|
||||
</label>
|
||||
<div className="relative">
|
||||
<span className="absolute inset-y-0 left-0 pl-3 flex items-center text-slate-400">
|
||||
<User className="w-4 h-4" />
|
||||
</span>
|
||||
<input
|
||||
type="text"
|
||||
autoComplete="username"
|
||||
className="block w-full rounded-2xl border border-slate-200 pl-9 pr-3 py-2 text-sm shadow-sm focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-transparent"
|
||||
value={username}
|
||||
onChange={(e) => setUsername(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-1">
|
||||
<label className="block text-sm font-medium text-slate-700">
|
||||
Contraseña
|
||||
</label>
|
||||
<div className="relative">
|
||||
<span className="absolute inset-y-0 left-0 pl-3 flex items-center text-slate-400">
|
||||
<Lock className="w-4 h-4" />
|
||||
</span>
|
||||
<input
|
||||
type="password"
|
||||
autoComplete="current-password"
|
||||
className="block w-full rounded-2xl border border-slate-200 pl-9 pr-3 py-2 text-sm shadow-sm focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-transparent"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
disabled={isSubmitting}
|
||||
className="w-full inline-flex items-center justify-center rounded-2xl bg-indigo-600 text-white text-sm font-medium py-2.5 shadow-sm hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 disabled:opacity-60 disabled:cursor-not-allowed"
|
||||
>
|
||||
{isSubmitting ? 'Entrando…' : 'Entrar'}
|
||||
</button>
|
||||
|
||||
<p className="text-[11px] text-slate-400 text-center mt-2">
|
||||
La sesión permanecerá activa durante 1 hora.
|
||||
</p>
|
||||
</form>
|
||||
</motion.div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default LoginPage;
|
||||
@@ -10,6 +10,7 @@ import DataInputRedesigned from './DataInputRedesigned';
|
||||
import DashboardReorganized from './DashboardReorganized';
|
||||
import { generateAnalysis } from '../utils/analysisGenerator';
|
||||
import toast from 'react-hot-toast';
|
||||
import { useAuth } from '../utils/AuthContext';
|
||||
|
||||
const SinglePageDataRequestIntegrated: React.FC = () => {
|
||||
const [selectedTier, setSelectedTier] = useState<TierKey>('silver');
|
||||
@@ -21,6 +22,9 @@ const SinglePageDataRequestIntegrated: React.FC = () => {
|
||||
setSelectedTier(tier);
|
||||
};
|
||||
|
||||
const { authHeader, logout } = useAuth();
|
||||
|
||||
|
||||
const handleAnalyze = (config: {
|
||||
costPerHour: number;
|
||||
avgCsat: number;
|
||||
@@ -44,6 +48,12 @@ const SinglePageDataRequestIntegrated: React.FC = () => {
|
||||
toast.error('Por favor, sube un archivo, introduce una URL o genera datos sintéticos.');
|
||||
return;
|
||||
}
|
||||
|
||||
// 🔐 Si usamos CSV real, exigir estar logado
|
||||
if (config.file && !config.useSynthetic && !authHeader) {
|
||||
toast.error('Debes iniciar sesión para analizar datos reales.');
|
||||
return;
|
||||
}
|
||||
|
||||
setIsAnalyzing(true);
|
||||
toast.loading('Generando análisis...', { id: 'analyzing' });
|
||||
@@ -58,7 +68,8 @@ const SinglePageDataRequestIntegrated: React.FC = () => {
|
||||
config.segmentMapping,
|
||||
config.file,
|
||||
config.sheetUrl,
|
||||
config.useSynthetic
|
||||
config.useSynthetic,
|
||||
authHeader || undefined
|
||||
);
|
||||
console.log('✅ Analysis generated successfully');
|
||||
|
||||
@@ -74,7 +85,15 @@ const SinglePageDataRequestIntegrated: React.FC = () => {
|
||||
console.error('❌ Error generating analysis:', error);
|
||||
setIsAnalyzing(false);
|
||||
toast.dismiss('analyzing');
|
||||
toast.error('Error al generar el análisis: ' + (error as Error).message);
|
||||
|
||||
const msg = (error as Error).message || '';
|
||||
|
||||
if (msg.includes('401')) {
|
||||
toast.error('Sesión caducada o credenciales incorrectas. Vuelve a iniciar sesión.');
|
||||
logout();
|
||||
} else {
|
||||
toast.error('Error al generar el análisis: ' + msg);
|
||||
}
|
||||
}
|
||||
}, 1500);
|
||||
};
|
||||
@@ -131,6 +150,12 @@ const SinglePageDataRequestIntegrated: React.FC = () => {
|
||||
<p className="text-lg text-slate-600">
|
||||
Análisis de Readiness Agéntico para Contact Centers
|
||||
</p>
|
||||
<button
|
||||
onClick={logout}
|
||||
className="text-xs text-slate-500 hover:text-slate-800 underline mt-1"
|
||||
>
|
||||
Cerrar sesión
|
||||
</button>
|
||||
</motion.div>
|
||||
|
||||
{/* Tier Selection */}
|
||||
|
||||
Reference in New Issue
Block a user