diff --git a/frontend/src/pages/Asesores.jsx b/frontend/src/pages/Asesores.jsx index d71ec72..5e739a3 100644 --- a/frontend/src/pages/Asesores.jsx +++ b/frontend/src/pages/Asesores.jsx @@ -14,6 +14,27 @@ export default function Asesores() { const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [cambiando, setCambiando] = useState(null); + const [histAsesor, setHistAsesor] = useState(null); // { nombre, email } + const [histFilas, setHistFilas] = useState([]); + const [histLoading, setHistLoading] = useState(false); + + async function verHistorial(ag) { + const nombre = ag.name || ag.available_name || "—"; + setHistAsesor({ nombre, email: ag.email }); + setHistFilas([]); setHistLoading(true); + try { + const r = await api.asesorHistorial(ag.email); + setHistFilas(r.historial || []); + } catch (e) { setHistFilas([]); } + setHistLoading(false); + } + + const fmtHora = (iso) => { + if (!iso) return "—"; + const d = new Date(iso); + return d.toLocaleString("es-PE", { day:"2-digit", month:"2-digit", year:"numeric", + hour:"2-digit", minute:"2-digit", hour12:true }); + }; const cargar = useCallback(() => { setLoading(true); setError(null); @@ -55,51 +76,114 @@ export default function Asesores() { {loading ? : error ? : <> -
-
👥
Total Asesores
{total}
-
🟢
En Línea
{enLinea}
-
🟡
Ocupados
{ocupados}
-
🔴
Fuera de Línea
{offline}
-
-
- +
-
- - - - {agentes.map((ag)=>{ - const est = ESTADO_INFO[ag.availability_status] || ESTADO_INFO.offline; - const isOnline = ag.availability_status==="online"; - return ( - - - - - - - - ); - })} - -
ASESOREMAILROLESTADOACCIÓN
{ag.name || ag.available_name || "—"}{ag.email || "—"}{ag.role || "agent"} - ● {est.txt} - - -
+
+ {agentes.map((ag)=>{ + const est = ESTADO_INFO[ag.availability_status] || ESTADO_INFO.offline; + const isOnline = ag.availability_status==="online"; + const nombre = ag.name || ag.available_name || "—"; + const inicial = nombre.trim().charAt(0).toUpperCase(); + const esAdmin = String(ag.role||"agent").toLowerCase().includes("admin"); + return ( +
+ {/* Avatar con punto de estado */} +
+
+ {inicial} +
+ +
+ {/* Nombre + email */} +
+
+ {nombre} + {esAdmin && ( + ADMIN + )} +
+
{ag.email || "—"}
+
+ {/* Historial */} + + {/* Switch ON / OFF */} +
+ + {isOnline ? "ON" : "OFF"} + +
cambiando===ag.id ? null : toggle(ag)} + style={{ width:40, height:22, borderRadius:999, cursor: cambiando===ag.id ? "wait" : "pointer", + background: isOnline ? "#10b981" : "#cbd5e1", position:"relative", + transition:"background .2s", opacity: cambiando===ag.id ? .6 : 1 }}> +
+
+
+
+ ); + })}
} + + {histAsesor && ( +
setHistAsesor(null)} + style={{ position:"fixed", inset:0, background:"rgba(15,23,42,.55)", backdropFilter:"blur(2px)", + display:"flex", alignItems:"center", justifyContent:"center", zIndex:1000, padding:16 }}> +
e.stopPropagation()} + style={{ background:"#fff", borderRadius:18, width:520, maxWidth:"94vw", maxHeight:"85vh", + display:"flex", flexDirection:"column", overflow:"hidden", + boxShadow:"0 30px 80px rgba(15,23,42,.4)", border:"1px solid #e2e8f0" }}> +
+
+
📋 Historial de conexión
+
{histAsesor.nombre}
+
+ +
+
+ {histLoading ?
Cargando...
: + histFilas.length === 0 ?
Sin registros.
: +
+ {histFilas.map((h, i) => { + const on = h.accion === "ON"; + return ( +
+ + + {on ? "🟢 Se conectó" : "⚪ Se desconectó"} + + {fmtHora(h.fecha_hora)} + {h.origen} +
+ ); + })} +
} +
+
+
+ )}
); }