247 lines
14 KiB
HTML
247 lines
14 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="es">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Automatizaciones - IntegraRepara</title>
|
|
<script src="https://cdn.tailwindcss.com"></script>
|
|
<script src="https://unpkg.com/lucide@latest"></script>
|
|
<style>
|
|
.fade-in { animation: fadeIn 0.3s ease-in-out; }
|
|
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
|
|
.service-card { transition: all 0.2s ease; }
|
|
.service-card:hover { transform: translateY(-2px); }
|
|
</style>
|
|
</head>
|
|
<body class="bg-gray-50 text-gray-800 font-sans h-screen overflow-hidden flex">
|
|
|
|
<div id="sidebar-container" class="h-full shrink-0"></div>
|
|
|
|
<div class="flex-1 flex flex-col h-full relative min-w-0">
|
|
<div id="header-container"></div>
|
|
|
|
<main class="flex-1 overflow-hidden flex flex-col relative">
|
|
|
|
<div class="bg-white border-b border-gray-200 p-4 shrink-0 z-10 shadow-sm">
|
|
<div class="flex flex-col md:flex-row justify-between items-start md:items-center gap-4">
|
|
<div>
|
|
<h2 class="text-2xl font-bold text-gray-800 flex items-center gap-2">
|
|
<i data-lucide="bot" class="text-blue-600"></i> Buzón de Automatizaciones
|
|
</h2>
|
|
<p class="text-xs text-gray-500 mt-1">Revisa e importa servicios detectados por Multiasistencia y HomeServe.</p>
|
|
</div>
|
|
|
|
<button onclick="loadInbox()" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg text-sm font-bold flex items-center gap-2 transition-colors shadow-lg shadow-blue-100">
|
|
<i data-lucide="refresh-cw" class="w-4 h-4"></i> Actualizar Buzón
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="flex-1 overflow-y-auto p-6 space-y-4" id="inboxContainer">
|
|
<div class="flex flex-col items-center justify-center py-20 text-gray-400">
|
|
<div class="animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600 mb-4"></div>
|
|
<p>Sincronizando con los robots...</p>
|
|
</div>
|
|
</div>
|
|
|
|
</main>
|
|
</div>
|
|
|
|
<div id="importModal" class="fixed inset-0 bg-black bg-opacity-50 hidden z-50 flex items-center justify-center backdrop-blur-sm">
|
|
<div class="bg-white rounded-xl shadow-2xl w-full max-w-lg p-6 animate-slide-in flex flex-col max-h-[90vh] overflow-y-auto">
|
|
<div class="flex justify-between items-center mb-4 border-b pb-2">
|
|
<h3 class="text-lg font-bold text-gray-800 flex items-center gap-2">
|
|
<i data-lucide="file-check" class="text-green-600"></i> Validar Datos de Importación
|
|
</h3>
|
|
<button onclick="closeModal()" class="text-gray-400 hover:text-gray-600"><i data-lucide="x" class="w-5 h-5"></i></button>
|
|
</div>
|
|
|
|
<form id="importForm" onsubmit="handleFinalImport(event)" class="space-y-4">
|
|
<input type="hidden" id="impScrapedId">
|
|
|
|
<div class="grid grid-cols-2 gap-3">
|
|
<div class="col-span-2">
|
|
<label class="block text-[10px] font-bold text-gray-400 uppercase mb-1">Nombre del Cliente</label>
|
|
<input type="text" id="impName" required class="w-full border p-2 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 outline-none">
|
|
</div>
|
|
<div>
|
|
<label class="block text-[10px] font-bold text-gray-400 uppercase mb-1">Teléfono</label>
|
|
<input type="text" id="impPhone" required class="w-full border p-2 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 outline-none">
|
|
</div>
|
|
<div>
|
|
<label class="block text-[10px] font-bold text-gray-400 uppercase mb-1">Compañía</label>
|
|
<input type="text" id="impCompany" class="w-full border p-2 rounded-lg text-sm bg-gray-50 font-medium" readonly>
|
|
</div>
|
|
</div>
|
|
|
|
<div>
|
|
<label class="block text-[10px] font-bold text-gray-400 uppercase mb-1">Dirección Completa</label>
|
|
<div class="relative">
|
|
<i data-lucide="map-pin" class="w-4 h-4 absolute left-3 top-2.5 text-gray-400"></i>
|
|
<input type="text" id="impAddress" required class="w-full border pl-9 pr-3 py-2 rounded-lg text-sm outline-none focus:ring-2 focus:ring-blue-500">
|
|
</div>
|
|
</div>
|
|
|
|
<div>
|
|
<label class="block text-[10px] font-bold text-gray-400 uppercase mb-1">Descripción de la Avería</label>
|
|
<textarea id="impDesc" rows="4" class="w-full border p-2 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 outline-none" placeholder="Detalles extraídos por el robot..."></textarea>
|
|
</div>
|
|
|
|
<div class="grid grid-cols-2 gap-3">
|
|
<div>
|
|
<label class="block text-[10px] font-bold text-gray-400 uppercase mb-1">Referencia Externa</label>
|
|
<input type="text" id="impRef" class="w-full border p-2 rounded-lg text-sm bg-gray-50" readonly>
|
|
</div>
|
|
<div>
|
|
<label class="block text-[10px] font-bold text-gray-400 uppercase mb-1">Prioridad</label>
|
|
<select id="impUrgent" class="w-full border p-2 rounded-lg text-sm bg-white outline-none">
|
|
<option value="false">Normal</option>
|
|
<option value="true">🚨 Urgente</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="pt-4">
|
|
<button type="submit" class="w-full bg-green-600 text-white px-4 py-3 rounded-xl text-sm font-bold hover:bg-green-700 shadow-lg shadow-green-100 flex items-center justify-center gap-2 transition-all">
|
|
<i data-lucide="save" class="w-4 h-4"></i> CONFIRMAR Y GUARDAR EN CRM
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="toast" class="fixed bottom-5 right-5 bg-slate-800 text-white px-6 py-3 rounded-lg shadow-2xl hidden z-[100] translate-y-0 transition-all duration-300">
|
|
<span id="toastMsg"></span>
|
|
</div>
|
|
|
|
<script src="js/layout.js"></script>
|
|
<script>
|
|
let globalMappings = [];
|
|
let allScraped = [];
|
|
|
|
document.addEventListener('DOMContentLoaded', async () => {
|
|
if (!localStorage.getItem("token")) window.location.href = "index.html";
|
|
await loadInbox();
|
|
lucide.createIcons();
|
|
});
|
|
|
|
async function loadInbox() {
|
|
const container = document.getElementById('inboxContainer');
|
|
try {
|
|
const [svcRes, mapRes] = await Promise.all([
|
|
fetch(`${API_URL}/providers/scraped`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } }),
|
|
fetch(`${API_URL}/discovery/mappings`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } })
|
|
]);
|
|
|
|
const svcData = await svcRes.json();
|
|
globalMappings = await mapRes.json();
|
|
allScraped = svcData.services || [];
|
|
|
|
if (allScraped.length === 0) {
|
|
container.innerHTML = `
|
|
<div class="flex flex-col items-center justify-center py-20 text-gray-400 bg-white rounded-xl border-2 border-dashed">
|
|
<i data-lucide="check-circle" class="w-12 h-12 mb-2 text-green-500"></i>
|
|
<p class="font-medium">No hay servicios nuevos pendientes.</p>
|
|
</div>`;
|
|
lucide.createIcons();
|
|
return;
|
|
}
|
|
|
|
container.innerHTML = '';
|
|
allScraped.forEach(svc => {
|
|
const raw = svc.raw_data || {};
|
|
const myMap = globalMappings.filter(m => m.provider === svc.provider);
|
|
|
|
const name = raw[myMap.find(m => m.target_key === 'clientName')?.original_key] || "No detectado";
|
|
const addr = raw[myMap.find(m => m.target_key === 'address')?.original_key] || "Sin dirección";
|
|
const phone = raw[myMap.find(m => m.target_key === 'phone')?.original_key] || raw['Teléfono'] || "S/T";
|
|
|
|
const card = document.createElement('div');
|
|
card.className = "service-card bg-white p-4 rounded-xl border border-gray-200 shadow-sm flex items-center gap-4 fade-in";
|
|
card.innerHTML = `
|
|
<div class="w-20 h-20 rounded-lg flex flex-col items-center justify-center shrink-0 ${svc.provider === 'homeserve' ? 'bg-red-50 text-red-600' : 'bg-blue-50 text-blue-600'}">
|
|
<span class="text-[10px] font-black uppercase tracking-tighter">${svc.provider}</span>
|
|
<i data-lucide="${svc.provider === 'homeserve' ? 'home' : 'briefcase'}" class="w-6 h-6 my-1"></i>
|
|
<span class="text-[10px] font-bold">#${svc.service_ref.slice(-4)}</span>
|
|
</div>
|
|
<div class="flex-1 min-w-0">
|
|
<h4 class="font-bold text-gray-900 truncate">${name}</h4>
|
|
<p class="text-xs text-gray-500 flex items-center gap-1 mt-0.5 truncate"><i data-lucide="map-pin" class="w-3 h-3"></i> ${addr}</p>
|
|
<div class="flex gap-2 mt-2">
|
|
<span class="text-[10px] bg-gray-100 px-2 py-0.5 rounded font-bold text-gray-600"><i data-lucide="phone" class="w-2.5 h-2.5 inline mr-1"></i>${phone}</span>
|
|
</div>
|
|
</div>
|
|
<button onclick="openEditor(${svc.id})" class="bg-white border-2 border-green-500 text-green-600 p-3 rounded-full hover:bg-green-50 transition-colors shadow-sm shadow-green-50">
|
|
<i data-lucide="check" class="w-6 h-6"></i>
|
|
</button>
|
|
`;
|
|
container.appendChild(card);
|
|
});
|
|
lucide.createIcons();
|
|
} catch (e) {
|
|
showToast("Error al cargar datos", true);
|
|
}
|
|
}
|
|
|
|
function openEditor(scrapedId) {
|
|
const svc = allScraped.find(s => s.id === scrapedId);
|
|
if (!svc) return;
|
|
|
|
const raw = svc.raw_data;
|
|
const myMap = globalMappings.filter(m => m.provider === svc.provider);
|
|
|
|
document.getElementById('impScrapedId').value = scrapedId;
|
|
document.getElementById('impName').value = raw[myMap.find(m => m.target_key === 'clientName')?.original_key] || "";
|
|
document.getElementById('impPhone').value = raw[myMap.find(m => m.target_key === 'phone')?.original_key] || raw['Teléfono'] || "";
|
|
document.getElementById('impAddress').value = raw[myMap.find(m => m.target_key === 'address')?.original_key] || "";
|
|
document.getElementById('impRef').value = svc.service_ref;
|
|
document.getElementById('impCompany').value = raw[myMap.find(m => m.target_key === 'compania')?.original_key] || svc.provider.toUpperCase();
|
|
document.getElementById('impDesc').value = raw[myMap.find(m => m.target_key === 'descripcion')?.original_key] || raw['Descripción'] || "";
|
|
document.getElementById('impUrgent').value = (raw['Urgente'] === 'Sí' || raw['Urgente'] === 'true').toString();
|
|
|
|
document.getElementById('importModal').classList.remove('hidden');
|
|
lucide.createIcons();
|
|
}
|
|
|
|
function closeModal() {
|
|
document.getElementById('importModal').classList.add('hidden');
|
|
}
|
|
|
|
async function handleFinalImport(e) {
|
|
e.preventDefault();
|
|
const id = document.getElementById('impScrapedId').value;
|
|
const payload = {
|
|
name: document.getElementById('impName').value,
|
|
phone: document.getElementById('impPhone').value,
|
|
address: document.getElementById('impAddress').value,
|
|
description: document.getElementById('impDesc').value,
|
|
company_ref: document.getElementById('impRef').value,
|
|
is_urgent: document.getElementById('impUrgent').value === 'true'
|
|
};
|
|
|
|
try {
|
|
const res = await fetch(`${API_URL}/providers/import/${id}`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${localStorage.getItem('token')}` },
|
|
body: JSON.stringify(payload)
|
|
});
|
|
|
|
if (res.ok) {
|
|
showToast("✅ Servicio importado al CRM");
|
|
closeModal();
|
|
loadInbox();
|
|
} else {
|
|
showToast("Error al importar", true);
|
|
}
|
|
} catch (e) { showToast("Error de conexión", true); }
|
|
}
|
|
|
|
function showToast(msg, isError = false) {
|
|
const t = document.getElementById('toast'), m = document.getElementById('toastMsg');
|
|
t.className = `fixed bottom-5 right-5 px-6 py-3 rounded-lg shadow-2xl z-[100] flex items-center gap-3 ${isError ? 'bg-red-600' : 'bg-slate-800'} text-white font-medium`;
|
|
m.innerText = msg; t.classList.remove('hidden');
|
|
setTimeout(() => t.classList.add('hidden'), 3000);
|
|
}
|
|
</script>
|
|
</body>
|
|
</html> |