Actualizar automatizaciones.html
This commit is contained in:
@@ -29,7 +29,7 @@
|
|||||||
<h2 class="text-2xl font-bold text-gray-800 flex items-center gap-2">
|
<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
|
<i data-lucide="bot" class="text-blue-600"></i> Buzón de Automatizaciones
|
||||||
</h2>
|
</h2>
|
||||||
<p class="text-sm text-gray-500 mt-1">Valida e importa servicios de Multiasistencia y HomeServe.</p>
|
<p class="text-sm text-gray-500 mt-1">Valida e importa servicios detectados por los robots.</p>
|
||||||
</div>
|
</div>
|
||||||
<button onclick="loadInbox()" class="bg-blue-600 hover:bg-blue-700 text-white px-5 py-2.5 rounded-xl shadow-lg flex items-center gap-2 font-medium transition-all transform hover:scale-105">
|
<button onclick="loadInbox()" class="bg-blue-600 hover:bg-blue-700 text-white px-5 py-2.5 rounded-xl shadow-lg flex items-center gap-2 font-medium transition-all transform hover:scale-105">
|
||||||
<i data-lucide="refresh-cw" class="w-5 h-5"></i> Actualizar Buzón
|
<i data-lucide="refresh-cw" class="w-5 h-5"></i> Actualizar Buzón
|
||||||
@@ -37,63 +37,63 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="space-y-4" id="inboxContainer">
|
<div class="space-y-4" id="inboxContainer">
|
||||||
<div class="p-12 text-center text-gray-400 bg-white rounded-xl border border-gray-100 shadow-sm">
|
|
||||||
Cargando expedientes de los robots...
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="importModal" class="fixed inset-0 bg-black bg-opacity-50 hidden z-50 flex items-center justify-center backdrop-blur-sm p-4">
|
<div id="importModal" class="fixed inset-0 bg-black bg-opacity-50 hidden z-50 flex items-center justify-center backdrop-blur-sm p-4">
|
||||||
<div class="bg-white rounded-xl shadow-2xl w-full max-w-2xl p-6 animate-slide-in flex flex-col max-h-[90vh] overflow-y-auto no-scrollbar">
|
<div class="bg-white rounded-xl shadow-2xl w-full max-w-2xl p-6 flex flex-col max-h-[90vh] overflow-y-auto no-scrollbar">
|
||||||
<div class="flex justify-between items-center mb-6 border-b pb-4">
|
<div class="flex justify-between items-center mb-6 border-b pb-4">
|
||||||
<h3 class="text-xl font-bold text-gray-800 flex items-center gap-2">
|
<h3 class="text-xl font-bold text-gray-800 flex items-center gap-2">
|
||||||
<i data-lucide="file-check" class="text-green-600"></i> Validar Datos para Importar
|
<i data-lucide="file-check" class="text-green-600"></i> Validar Datos de Importación
|
||||||
</h3>
|
</h3>
|
||||||
<button onclick="closeModal()" class="text-gray-400 hover:text-gray-600"><i data-lucide="x" class="w-6 h-6"></i></button>
|
<button onclick="closeModal()" class="text-gray-400 hover:text-gray-600"><i data-lucide="x" class="w-6 h-6"></i></button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form id="importForm" onsubmit="handleImportSubmit(event)" class="space-y-6">
|
<form id="importForm" onsubmit="handleImportSubmit(event)" class="space-y-5">
|
||||||
<input type="hidden" id="scrapedId">
|
<input type="hidden" id="scrapedId">
|
||||||
|
|
||||||
<div class="bg-gray-50 p-4 rounded-lg border border-gray-200 grid grid-cols-1 md:grid-cols-2 gap-4">
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
<div>
|
<div>
|
||||||
<label class="block text-xs font-bold text-gray-500 uppercase mb-1 tracking-wider">Nombre del Cliente</label>
|
<label class="block text-[10px] font-bold text-gray-400 uppercase mb-1">Nombre del Cliente</label>
|
||||||
<input type="text" id="imp_name" required class="w-full border p-2.5 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 outline-none font-medium">
|
<input type="text" id="imp_name" required class="w-full border p-2.5 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 outline-none">
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label class="block text-xs font-bold text-gray-500 uppercase mb-1 tracking-wider">Teléfono</label>
|
<label class="block text-[10px] font-bold text-gray-400 uppercase mb-1">Teléfono Principal (Limpio)</label>
|
||||||
<input type="text" id="imp_phone" required class="w-full border p-2.5 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 outline-none font-medium">
|
<input type="text" id="imp_phone" required class="w-full border p-2.5 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 outline-none font-mono">
|
||||||
|
<div id="imp_phone_extra" class="text-[10px] text-gray-400 mt-1 italic"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="grid grid-cols-1 md:grid-cols-4 gap-4">
|
||||||
|
<div class="md:col-span-3">
|
||||||
|
<label class="block text-[10px] font-bold text-gray-400 uppercase mb-1">Dirección y Población</label>
|
||||||
|
<input type="text" id="imp_address" required class="w-full border p-2.5 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">C. Postal</label>
|
||||||
|
<input type="text" id="imp_cp" required class="w-full border p-2.5 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 outline-none font-mono">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label class="block text-xs font-bold text-gray-500 uppercase mb-1 tracking-wider">Dirección de la Reparación</label>
|
<label class="block text-[10px] font-bold text-gray-400 uppercase mb-1">Descripción del Trabajo</label>
|
||||||
<div class="relative">
|
<textarea id="imp_desc" rows="4" class="w-full border p-3 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 outline-none"></textarea>
|
||||||
<i data-lucide="map-pin" class="absolute left-3 top-3 w-4 h-4 text-gray-400"></i>
|
|
||||||
<input type="text" id="imp_address" required class="w-full pl-10 pr-3 py-2.5 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm">
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||||
<label class="block text-xs font-bold text-gray-500 uppercase mb-1 tracking-wider">Descripción de Daños (Detectado)</label>
|
|
||||||
<textarea id="imp_desc" rows="5" class="w-full border p-3 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 outline-none bg-yellow-50/30 border-yellow-100" placeholder="Escribe aquí los detalles..."></textarea>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="grid grid-cols-2 md:grid-cols-3 gap-4">
|
|
||||||
<div>
|
<div>
|
||||||
<label class="block text-xs font-bold text-gray-500 uppercase mb-1 tracking-wider">Referencia</label>
|
<label class="block text-[10px] font-bold text-gray-400 uppercase mb-1">Referencia</label>
|
||||||
<input type="text" id="imp_ref" class="w-full border p-2.5 rounded-lg text-sm bg-gray-100 font-mono text-gray-500" readonly>
|
<input type="text" id="imp_ref" class="w-full border p-2.5 rounded-lg text-sm bg-gray-50" readonly>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label class="block text-xs font-bold text-gray-500 uppercase mb-1 tracking-wider">Compañía</label>
|
<label class="block text-[10px] font-bold text-gray-400 uppercase mb-1">Compañía / Origen</label>
|
||||||
<input type="text" id="imp_company" class="w-full border p-2.5 rounded-lg text-sm bg-gray-100 text-gray-500" readonly>
|
<input type="text" id="imp_company" class="w-full border p-2.5 rounded-lg text-sm bg-gray-50 font-bold text-blue-600" readonly>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-span-2 md:col-span-1">
|
<div>
|
||||||
<label class="block text-xs font-bold text-gray-500 uppercase mb-1 tracking-wider">Prioridad</label>
|
<label class="block text-[10px] font-bold text-gray-400 uppercase mb-1">Prioridad</label>
|
||||||
<select id="imp_urgent" class="w-full border p-2.5 rounded-lg text-sm bg-white outline-none">
|
<select id="imp_urgent" class="w-full border p-2.5 rounded-lg text-sm bg-white outline-none">
|
||||||
<option value="false">Normal</option>
|
<option value="false">Normal</option>
|
||||||
<option value="true">🚨 URGENTE</option>
|
<option value="true">🚨 URGENTE</option>
|
||||||
@@ -101,9 +101,10 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="pt-4">
|
<div class="pt-4 flex gap-3">
|
||||||
<button type="submit" id="btnImport" class="w-full bg-blue-600 hover:bg-blue-700 text-white font-bold py-4 rounded-xl shadow-lg shadow-blue-500/30 text-lg transition-all flex justify-center items-center gap-3 active:scale-95">
|
<button type="button" onclick="closeModal()" class="flex-1 bg-gray-100 text-gray-600 py-3 rounded-xl font-bold hover:bg-gray-200 transition-all">Cancelar</button>
|
||||||
<i data-lucide="download-cloud" class="w-6 h-6"></i> IMPORTAR AL CRM
|
<button type="submit" id="btnImport" class="flex-[2] bg-blue-600 hover:bg-blue-700 text-white font-bold py-3 rounded-xl shadow-lg transition-all flex justify-center items-center gap-2">
|
||||||
|
<i data-lucide="download-cloud"></i> IMPORTAR AL CRM
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
@@ -135,7 +136,7 @@
|
|||||||
scrapedData = dataSvc.services || [];
|
scrapedData = dataSvc.services || [];
|
||||||
|
|
||||||
if(scrapedData.length === 0) {
|
if(scrapedData.length === 0) {
|
||||||
container.innerHTML = '<div class="p-12 text-center text-gray-400 bg-white rounded-xl border border-dashed border-gray-200">No hay servicios pendientes en los robots.</div>';
|
container.innerHTML = '<div class="p-12 text-center text-gray-400 bg-white rounded-xl border border-dashed border-gray-200 shadow-sm">No hay expedientes pendientes.</div>';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,30 +145,33 @@
|
|||||||
const raw = svc.raw_data || {};
|
const raw = svc.raw_data || {};
|
||||||
const myMap = mappings.filter(m => m.provider === svc.provider);
|
const myMap = mappings.filter(m => m.provider === svc.provider);
|
||||||
|
|
||||||
// Mapeo dinámico para el resumen de la tarjeta
|
|
||||||
const name = raw[myMap.find(m => m.target_key === 'clientName')?.original_key] || "Desconocido";
|
const name = raw[myMap.find(m => m.target_key === 'clientName')?.original_key] || "Desconocido";
|
||||||
const addr = raw[myMap.find(m => m.target_key === 'address')?.original_key] || "Sin dirección";
|
const addr = raw[myMap.find(m => m.target_key === 'address')?.original_key] || "";
|
||||||
const phone = raw[myMap.find(m => m.target_key === 'phone')?.original_key] || raw['Teléfono'] || "S/T";
|
const pop = raw[myMap.find(m => m.target_key === 'poblacion')?.original_key] || "";
|
||||||
|
const fullAddr = `${addr} ${pop}`.trim() || "Sin dirección";
|
||||||
|
|
||||||
|
const rawPhone = raw[myMap.find(m => m.target_key === 'phone')?.original_key] || raw['Teléfono'] || "";
|
||||||
|
const cleanPhone = rawPhone.match(/[6789]\d{8}/) ? rawPhone.match(/[6789]\d{8}/)[0] : "S/T";
|
||||||
|
|
||||||
const card = document.createElement('div');
|
const card = document.createElement('div');
|
||||||
card.className = "bg-white p-5 rounded-xl border border-gray-100 shadow-sm flex items-center justify-between hover:border-blue-200 transition-all fade-in";
|
card.className = "bg-white p-5 rounded-xl border border-gray-100 shadow-sm flex items-center justify-between hover:border-blue-200 transition-all fade-in";
|
||||||
card.innerHTML = `
|
card.innerHTML = `
|
||||||
<div class="flex items-center gap-6 min-w-0">
|
<div class="flex items-center gap-6 min-w-0">
|
||||||
<div class="w-16 h-16 rounded-xl flex flex-col items-center justify-center shrink-0 ${svc.provider === 'homeserve' ? 'bg-red-50 text-red-600' : 'bg-blue-50 text-blue-600'}">
|
<div class="w-16 h-16 rounded-xl 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>
|
<span class="text-[9px] font-black uppercase tracking-tighter">${svc.provider}</span>
|
||||||
<i data-lucide="file-text" class="w-5 h-5 mt-1"></i>
|
<i data-lucide="file-text" class="w-5 h-5 mt-1"></i>
|
||||||
</div>
|
</div>
|
||||||
<div class="min-w-0">
|
<div class="min-w-0">
|
||||||
<h3 class="font-bold text-gray-900 truncate text-lg">${name}</h3>
|
<h3 class="font-bold text-gray-900 truncate text-lg">${name}</h3>
|
||||||
<p class="text-xs text-gray-500 flex items-center gap-1.5 mt-0.5 truncate"><i data-lucide="map-pin" class="w-3.5 h-3.5"></i> ${addr}</p>
|
<p class="text-xs text-gray-500 flex items-center gap-1.5 mt-0.5 truncate"><i data-lucide="map-pin" class="w-3.5 h-3.5"></i> ${fullAddr}</p>
|
||||||
<div class="mt-2 flex gap-2">
|
<div class="mt-2 flex gap-2">
|
||||||
<span class="text-[10px] bg-gray-100 text-gray-600 px-2 py-0.5 rounded font-bold border border-gray-200">REF: ${svc.service_ref}</span>
|
<span class="text-[10px] bg-gray-100 text-gray-600 px-2 py-0.5 rounded font-bold border border-gray-200">#${svc.service_ref}</span>
|
||||||
<span class="text-[10px] bg-blue-50 text-blue-600 px-2 py-0.5 rounded font-bold border border-blue-100"><i data-lucide="phone" class="w-2.5 h-2.5 inline mr-1"></i>${phone}</span>
|
<span class="text-[10px] bg-blue-50 text-blue-600 px-2 py-0.5 rounded font-bold border border-blue-100">${cleanPhone}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<button onclick="openEditor(${svc.id})" class="bg-white border-2 border-blue-600 text-blue-600 hover:bg-blue-600 hover:text-white p-3 rounded-xl transition-all shadow-md active:scale-95 group">
|
<button onclick="openEditor(${svc.id})" class="bg-blue-600 text-white p-3 rounded-xl transition-all shadow-lg active:scale-95">
|
||||||
<i data-lucide="arrow-right" class="w-6 h-6"></i>
|
<i data-lucide="edit-3" class="w-5 h-5"></i>
|
||||||
</button>
|
</button>
|
||||||
`;
|
`;
|
||||||
container.appendChild(card);
|
container.appendChild(card);
|
||||||
@@ -182,14 +186,31 @@
|
|||||||
const raw = svc.raw_data;
|
const raw = svc.raw_data;
|
||||||
const myMap = mappings.filter(m => m.provider === svc.provider);
|
const myMap = mappings.filter(m => m.provider === svc.provider);
|
||||||
|
|
||||||
|
// 1. LIMPIEZA DE TELÉFONO
|
||||||
|
const phoneVal = raw[myMap.find(m => m.target_key === 'phone')?.original_key] || raw['Teléfono'] || "";
|
||||||
|
const phoneMatch = phoneVal.match(/[6789]\d{8}/);
|
||||||
|
document.getElementById('imp_phone').value = phoneMatch ? phoneMatch[0] : "";
|
||||||
|
document.getElementById('imp_phone_extra').innerText = phoneVal !== (phoneMatch ? phoneMatch[0] : "") ? `Dato original: ${phoneVal}` : "";
|
||||||
|
|
||||||
|
// 2. LIMPIEZA DE CP Y DIRECCIÓN
|
||||||
|
const addr = raw[myMap.find(m => m.target_key === 'address')?.original_key] || "";
|
||||||
|
const pop = raw[myMap.find(m => m.target_key === 'poblacion')?.original_key] || "";
|
||||||
|
const cpVal = raw[myMap.find(m => m.target_key === 'cp')?.original_key] || raw['Población_CP'] || "";
|
||||||
|
const cpMatch = cpVal.match(/\b\d{5}\b/);
|
||||||
|
|
||||||
|
document.getElementById('imp_address').value = `${addr} ${pop}`.trim();
|
||||||
|
document.getElementById('imp_cp').value = cpMatch ? cpMatch[0] : "";
|
||||||
|
|
||||||
|
// 3. PROVEEDOR - COMPAÑÍA
|
||||||
|
const cia = raw[myMap.find(m => m.target_key === 'compania')?.original_key] || raw['Compañía'] || "";
|
||||||
|
document.getElementById('imp_company').value = `${svc.provider.toUpperCase()} - ${cia}`;
|
||||||
|
|
||||||
|
// 4. RESTO DE CAMPOS
|
||||||
document.getElementById('scrapedId').value = scrapedId;
|
document.getElementById('scrapedId').value = scrapedId;
|
||||||
document.getElementById('imp_name').value = raw[myMap.find(m => m.target_key === 'clientName')?.original_key] || "";
|
document.getElementById('imp_name').value = raw[myMap.find(m => m.target_key === 'clientName')?.original_key] || "";
|
||||||
document.getElementById('imp_phone').value = raw[myMap.find(m => m.target_key === 'phone')?.original_key] || raw['Teléfono'] || "";
|
|
||||||
document.getElementById('imp_address').value = raw[myMap.find(m => m.target_key === 'address')?.original_key] || "";
|
|
||||||
document.getElementById('imp_ref').value = svc.service_ref;
|
document.getElementById('imp_ref').value = svc.service_ref;
|
||||||
document.getElementById('imp_company').value = raw[myMap.find(m => m.target_key === 'compania')?.original_key] || svc.provider.toUpperCase();
|
|
||||||
document.getElementById('imp_desc').value = raw[myMap.find(m => m.target_key === 'descripcion')?.original_key] || raw['Descripción'] || "";
|
document.getElementById('imp_desc').value = raw[myMap.find(m => m.target_key === 'descripcion')?.original_key] || raw['Descripción'] || "";
|
||||||
document.getElementById('imp_urgent').value = (raw['Urgente'] === 'Sí').toString();
|
document.getElementById('imp_urgent').value = (raw['Urgente'] === 'Sí' || raw['Urgente'] === 'true').toString();
|
||||||
|
|
||||||
document.getElementById('importModal').classList.remove('hidden');
|
document.getElementById('importModal').classList.remove('hidden');
|
||||||
lucide.createIcons();
|
lucide.createIcons();
|
||||||
@@ -202,29 +223,28 @@
|
|||||||
const btn = document.getElementById('btnImport');
|
const btn = document.getElementById('btnImport');
|
||||||
btn.disabled = true; btn.innerText = "IMPORTANDO...";
|
btn.disabled = true; btn.innerText = "IMPORTANDO...";
|
||||||
|
|
||||||
const id = document.getElementById('scrapedId').value;
|
|
||||||
const payload = {
|
const payload = {
|
||||||
name: document.getElementById('imp_name').value,
|
name: document.getElementById('imp_name').value,
|
||||||
phone: document.getElementById('imp_phone').value,
|
phone: document.getElementById('imp_phone').value,
|
||||||
address: document.getElementById('imp_address').value,
|
address: document.getElementById('imp_address').value,
|
||||||
description: document.getElementById('imp_desc').value,
|
description: `CP: ${document.getElementById('imp_cp').value}\n${document.getElementById('imp_desc').value}`,
|
||||||
company_ref: document.getElementById('imp_ref').value,
|
company_ref: document.getElementById('imp_ref').value,
|
||||||
is_urgent: document.getElementById('imp_urgent').value === 'true'
|
is_urgent: document.getElementById('imp_urgent').value === 'true'
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${API_URL}/providers/import/${id}`, {
|
const res = await fetch(`${API_URL}/providers/import/${document.getElementById('scrapedId').value}`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${localStorage.getItem('token')}` },
|
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${localStorage.getItem('token')}` },
|
||||||
body: JSON.stringify(payload)
|
body: JSON.stringify(payload)
|
||||||
});
|
});
|
||||||
if((await res.json()).ok) {
|
if(res.ok) {
|
||||||
showToast("✅ Importado con éxito");
|
showToast("✅ Servicio importado");
|
||||||
closeModal();
|
closeModal();
|
||||||
loadInbox();
|
loadInbox();
|
||||||
} else { showToast("Error al importar", true); }
|
} else { showToast("Error al importar", true); }
|
||||||
} catch (e) { showToast("Error conexión", true); }
|
} catch (e) { showToast("Error conexión", true); }
|
||||||
finally { btn.disabled = false; btn.innerText = "IMPORTAR AL CRM"; }
|
finally { btn.disabled = false; btn.innerHTML = '<i data-lucide="download-cloud"></i> IMPORTAR AL CRM'; lucide.createIcons(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
function showToast(msg, isError = false) {
|
function showToast(msg, isError = false) {
|
||||||
|
|||||||
Reference in New Issue
Block a user