Actualizar automatizaciones.html

This commit is contained in:
2026-02-13 23:56:38 +00:00
parent 51d3a46e24
commit 91ab6e1092

View File

@@ -3,7 +3,7 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Automatizaciones - IntegraRepara</title> <title>Validación - IntegraRepara</title>
<script src="https://cdn.tailwindcss.com"></script> <script src="https://cdn.tailwindcss.com"></script>
<script src="https://unpkg.com/lucide@latest"></script> <script src="https://unpkg.com/lucide@latest"></script>
<style> <style>
@@ -11,8 +11,6 @@
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } } @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.no-scrollbar::-webkit-scrollbar { display: none; } .no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; } .no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }
.action-btn { transition: all 0.2s ease; }
.action-btn:hover:not(:disabled) { transform: translateY(-2px); }
</style> </style>
</head> </head>
<body class="bg-gray-50 text-gray-800 font-sans antialiased overflow-hidden"> <body class="bg-gray-50 text-gray-800 font-sans antialiased overflow-hidden">
@@ -28,254 +26,194 @@
<div class="flex justify-between items-center mb-8"> <div class="flex justify-between items-center mb-8">
<div> <div>
<h2 class="text-2xl font-black text-slate-800 flex items-center gap-3"> <h2 class="text-2xl font-black text-slate-800 flex items-center gap-3">
<span class="bg-blue-600 p-2.5 rounded-xl text-white shadow-lg"> <span class="bg-blue-600 p-2.5 rounded-xl text-white shadow-lg"><i data-lucide="bot"></i></span>
<i data-lucide="bot" class="w-6 h-6"></i>
</span>
Buzón de Automatizaciones Buzón de Automatizaciones
</h2> </h2>
<p class="text-sm text-slate-500 mt-1 font-medium">Gestión inteligente de expedientes externos.</p> <p class="text-sm text-slate-500 mt-1 font-medium">Valida los expedientes bloqueados o listos para importar.</p>
</div> </div>
<button onclick="loadInbox()" class="bg-white border-2 border-slate-200 hover:border-blue-600 hover:text-blue-600 text-slate-600 px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 transition-all active:scale-95 shadow-sm"> <button onclick="loadInbox()" class="bg-white border-2 border-slate-200 hover:border-blue-600 hover:text-blue-600 px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 transition-all shadow-sm">
<i data-lucide="refresh-cw" class="w-4 h-4"></i> Actualizar <i data-lucide="refresh-cw" class="w-4 h-4"></i> Actualizar
</button> </button>
</div> </div>
<div class="space-y-4" id="inboxContainer"> <div id="inboxContainer" class="space-y-4"></div>
</div>
</div> </div>
</main> </main>
</div> </div>
</div> </div>
<div id="importModal" class="fixed inset-0 bg-slate-900/60 hidden z-50 flex items-center justify-center backdrop-blur-md p-4"> <div id="importModal" class="fixed inset-0 bg-slate-900/60 hidden z-[100] flex items-center justify-center backdrop-blur-md p-4">
<div class="bg-white rounded-3xl shadow-2xl w-full max-w-2xl flex flex-col max-h-[90vh] overflow-hidden"> <div class="bg-white rounded-3xl shadow-2xl w-full max-w-4xl flex flex-col max-h-[95vh] overflow-hidden">
<div class="p-6 border-b flex justify-between items-center bg-slate-50"> <div class="p-6 border-b flex justify-between items-center bg-slate-50">
<h3 class="text-xl font-black text-slate-800 flex items-center gap-2"> <h3 class="text-xl font-black text-slate-800 flex items-center gap-2"><i data-lucide="check-square" class="text-emerald-500"></i> Alta de Servicio Automática</h3>
<i data-lucide="clipboard-check" class="text-emerald-500"></i> Validar Datos <button onclick="closeModal()" class="p-2 hover:bg-red-50 hover:text-red-500 rounded-full transition-all"><i data-lucide="x"></i></button>
</h3>
<button onclick="closeModal()" class="bg-white p-2 rounded-full shadow-sm hover:bg-red-50 hover:text-red-500 transition-all">
<i data-lucide="x" class="w-5 h-5"></i>
</button>
</div> </div>
<form id="importForm" onsubmit="handleImportSubmit(event)" class="p-8 space-y-6 overflow-y-auto no-scrollbar"> <form id="importForm" onsubmit="handleFinalImport(event)" class="p-8 space-y-6 overflow-y-auto no-scrollbar">
<input type="hidden" id="scrapedId"> <input type="hidden" id="impScrapedId">
<div class="grid grid-cols-1 md:grid-cols-2 gap-6"> <div class="grid grid-cols-1 md:grid-cols-3 gap-6 bg-slate-50 p-6 rounded-2xl border border-slate-100">
<div class="space-y-1.5"> <div class="md:col-span-2 space-y-1">
<label class="text-[11px] font-black text-slate-400 uppercase tracking-widest">Nombre del Cliente</label> <label class="text-[10px] font-black text-slate-400 uppercase tracking-widest">Nombre Cliente</label>
<input type="text" id="imp_name" required class="w-full border-2 border-slate-100 bg-slate-50 p-3 rounded-2xl text-sm focus:border-blue-500 focus:bg-white outline-none font-bold"> <input type="text" id="impName" required class="w-full border-2 border-white bg-white p-3 rounded-xl text-sm font-bold shadow-sm outline-none focus:border-blue-500">
</div> </div>
<div class="space-y-1.5"> <div class="space-y-1">
<label class="text-[11px] font-black text-slate-400 uppercase tracking-widest">Teléfono Principal</label> <label class="text-[10px] font-black text-slate-400 uppercase tracking-widest">Teléfono</label>
<input type="text" id="imp_phone" required class="w-full border-2 border-slate-100 bg-slate-50 p-3 rounded-2xl text-sm focus:border-blue-500 focus:bg-white outline-none font-black text-blue-600"> <input type="text" id="impPhone" required class="w-full border-2 border-white bg-white p-3 rounded-xl text-sm font-black text-blue-600 shadow-sm outline-none">
<div id="imp_phone_extra" class="text-[10px] text-slate-400 italic px-1"></div> </div>
<div class="md:col-span-2 space-y-1">
<label class="text-[10px] font-black text-slate-400 uppercase tracking-widest">Dirección + Población</label>
<input type="text" id="impAddress" required class="w-full border-2 border-white bg-white p-3 rounded-xl text-sm font-medium shadow-sm outline-none">
</div>
<div class="space-y-1">
<label class="text-[10px] font-black text-slate-400 uppercase tracking-widest">Código Postal</label>
<input type="text" id="impCP" required class="w-full border-2 border-white bg-white p-3 rounded-xl text-sm font-black text-center shadow-sm outline-none">
</div> </div>
</div> </div>
<div class="grid grid-cols-1 md:grid-cols-4 gap-6"> <div class="grid grid-cols-1 md:grid-cols-2 gap-6 p-6 rounded-2xl border-2 border-blue-100 bg-blue-50/30">
<div class="md:col-span-3 space-y-1.5"> <div class="space-y-1">
<label class="text-[11px] font-black text-slate-400 uppercase tracking-widest">Dirección y Población</label> <label class="text-[10px] font-black text-blue-600 uppercase tracking-widest">Gremio (OBLIGATORIO) *</label>
<input type="text" id="imp_address" required class="w-full border-2 border-slate-100 bg-slate-50 p-3 rounded-2xl text-sm focus:border-blue-500 focus:bg-white outline-none font-medium"> <select id="impGuild" required onchange="loadOpsForGuild(this.value)" class="w-full border-2 border-white bg-white p-3 rounded-xl text-sm font-bold shadow-sm outline-none focus:border-blue-500">
<option value="">-- Seleccionar Gremio --</option>
</select>
</div> </div>
<div class="space-y-1.5"> <div class="space-y-1">
<label class="text-[11px] font-black text-slate-400 uppercase tracking-widest">Código Postal</label> <label class="text-[10px] font-black text-blue-600 uppercase tracking-widest">Asignación de Operario</label>
<input type="text" id="imp_cp" required class="w-full border-2 border-slate-100 bg-slate-50 p-3 rounded-2xl text-sm focus:border-blue-500 focus:bg-white outline-none font-black text-center"> <select id="impOperator" class="w-full border-2 border-white bg-white p-3 rounded-xl text-sm font-bold shadow-sm outline-none focus:border-blue-500">
</div> <option value="">-- Automática (Por defecto) --</option>
</div>
<div class="space-y-1.5">
<label class="text-[11px] font-black text-slate-400 uppercase tracking-widest">Descripción de Avería (Limpia)</label>
<textarea id="imp_desc" rows="4" class="w-full border-2 border-slate-100 bg-slate-50 p-4 rounded-2xl text-sm focus:border-blue-500 focus:bg-white outline-none"></textarea>
</div>
<div class="grid grid-cols-1 md:grid-cols-3 gap-6">
<div>
<label class="text-[11px] font-black text-slate-400 uppercase tracking-widest">Ref. Expediente</label>
<input type="text" id="imp_ref" class="w-full border-2 border-slate-100 bg-slate-100 p-3 rounded-2xl text-sm font-bold" readonly>
</div>
<div>
<label class="text-[11px] font-black text-slate-400 uppercase tracking-widest">Compañía</label>
<input type="text" id="imp_company" class="w-full border-2 border-slate-100 bg-slate-100 p-3 rounded-2xl text-sm font-black text-blue-800" readonly>
</div>
<div>
<label class="text-[11px] font-black text-slate-400 uppercase tracking-widest">Urgencia</label>
<select id="imp_urgent" class="w-full border-2 border-slate-100 bg-white p-3 rounded-2xl text-sm font-bold outline-none">
<option value="false">Normal</option>
<option value="true">🚨 URGENTE</option>
</select> </select>
</div> </div>
</div> </div>
<button type="submit" id="btnImport" class="w-full bg-slate-900 hover:bg-blue-600 text-white font-black py-4 rounded-2xl shadow-xl transition-all flex justify-center items-center gap-3 active:scale-95 mt-4 uppercase"> <div class="space-y-4">
<i data-lucide="plus-circle"></i> Importar a Servicios <div class="space-y-1">
<label class="text-[10px] font-black text-slate-400 uppercase tracking-widest">Descripción de Avería</label>
<textarea id="impDesc" rows="3" class="w-full border-2 border-slate-100 p-4 rounded-2xl text-sm focus:border-blue-500 outline-none"></textarea>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div class="space-y-1">
<label class="text-[10px] font-black text-amber-600 uppercase tracking-widest">Notas Internas</label>
<textarea id="impNotesInt" rows="2" class="w-full border-2 border-amber-50 bg-amber-50/20 p-3 rounded-xl text-xs outline-none"></textarea>
</div>
<div class="space-y-1">
<label class="text-[10px] font-black text-blue-600 uppercase tracking-widest">Notas para el Cliente</label>
<textarea id="impNotesExt" rows="2" class="w-full border-2 border-blue-50 bg-blue-50/20 p-3 rounded-xl text-xs outline-none"></textarea>
</div>
</div>
</div>
<div class="grid grid-cols-3 gap-4 border-t pt-6">
<div class="space-y-1 text-center">
<label class="text-[9px] font-black text-slate-400 uppercase">Estado</label>
<div class="p-2 bg-slate-100 rounded-lg text-xs font-black text-slate-500 uppercase">Pendiente</div>
</div>
<div class="space-y-1 text-center">
<label class="text-[9px] font-black text-slate-400 uppercase">Prioridad</label>
<select id="impUrgent" class="w-full border-none bg-transparent text-xs font-black text-center focus:ring-0">
<option value="false">Normal</option>
<option value="true">🚨 URGENTE</option>
</select>
</div>
<button type="submit" class="bg-emerald-600 hover:bg-emerald-700 text-white font-black rounded-2xl shadow-xl transition-all flex items-center justify-center gap-2">
<i data-lucide="send"></i> TRASPASAR A CRM
</button> </button>
</div>
</form> </form>
</div> </div>
</div> </div>
<div id="toast" class="fixed bottom-8 right-8 bg-slate-900 text-white px-8 py-4 rounded-2xl shadow-2xl hidden z-[60] border border-white/10"><span id="toastMsg" class="font-bold text-sm"></span></div>
<script src="js/layout.js"></script> <script src="js/layout.js"></script>
<script> <script>
let mappings = []; let allGuilds = [];
let scrapedData = []; let scrapedData = [];
document.addEventListener("DOMContentLoaded", () => { document.addEventListener("DOMContentLoaded", async () => {
if (!localStorage.getItem("token")) window.location.href = "index.html"; if (!localStorage.getItem("token")) window.location.href = "index.html";
setTimeout(loadInbox, 200); setTimeout(async () => {
await loadGuilds();
await loadInbox();
}, 200);
}); });
async function loadGuilds() {
const res = await fetch(`${API_URL}/guilds`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
const data = await res.json();
allGuilds = data.guilds || [];
const sel = document.getElementById('impGuild');
sel.innerHTML = '<option value="">-- Seleccionar Gremio --</option>';
allGuilds.forEach(g => sel.innerHTML += `<option value="${g.id}">${g.name}</option>`);
}
async function loadOpsForGuild(guildId) {
const sel = document.getElementById('impOperator');
if(!guildId) { sel.innerHTML = '<option value="">-- Automática --</option>'; return; }
const res = await fetch(`${API_URL}/operators?guild_id=${guildId}`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
const data = await res.json();
sel.innerHTML = '<option value="">-- Automática (Por defecto) --</option>';
data.operators.forEach(op => sel.innerHTML += `<option value="${op.id}">${op.full_name}</option>`);
}
async function loadInbox() { async function loadInbox() {
const container = document.getElementById('inboxContainer'); const container = document.getElementById('inboxContainer');
try {
const [resSvc, resMap] = await Promise.all([ const [resSvc, resMap] = await Promise.all([
fetch(`${API_URL}/providers/scraped`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } }), fetch(`${API_URL}/providers/scraped`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } }),
fetch(`${API_URL}/discovery/mappings`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } }) fetch(`${API_URL}/discovery/mappings`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } })
]); ]);
const dataSvc = await resSvc.json(); const dataSvc = await resSvc.json();
mappings = await resMap.json(); const mappings = await resMap.json();
scrapedData = dataSvc.services || []; scrapedData = dataSvc.services || [];
if(scrapedData.length === 0) {
container.innerHTML = `<div class="bg-white p-20 rounded-3xl border-2 border-dashed text-center flex flex-col items-center">
<div class="bg-emerald-50 text-emerald-500 p-5 rounded-full mb-4"><i data-lucide="check-circle" class="w-10 h-10"></i></div>
<h3 class="text-xl font-black">Todo al día</h3>
<p class="text-slate-400 mt-1">No hay expedientes para validar.</p>
</div>`;
lucide.createIcons();
return;
}
container.innerHTML = ""; container.innerHTML = "";
scrapedData.forEach(svc => { scrapedData.forEach(svc => {
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);
const name = raw[myMap.find(m => m.target_key === 'clientName')?.original_key] || "";
const rawName = raw[myMap.find(m => m.target_key === 'clientName')?.original_key] || ""; const addr = raw[myMap.find(m => m.target_key === 'address')?.original_key] || "";
const rawAddr = raw[myMap.find(m => m.target_key === 'address')?.original_key] || ""; const isBlocked = (!name || name.toUpperCase().includes('SIN NOMBRE') || !addr);
const rawCPField = raw[myMap.find(m => m.target_key === 'cp')?.original_key] || raw['Población_CP'] || "";
const cpMatch = rawCPField.match(/\b\d{5}\b/);
const cpOnly = cpMatch ? cpMatch[0] : "";
const popOnly = rawCPField.replace(cpOnly, '').replace('-', '').trim();
const fullAddr = `${rawAddr} ${popOnly}`.trim();
const isBlocked = (!rawName || rawName.toLowerCase().includes('expediente sin nombre') || !rawAddr);
const shortProv = svc.provider === 'multiasistencia' ? 'MULTI' : 'HOME'; const shortProv = svc.provider === 'multiasistencia' ? 'MULTI' : 'HOME';
const card = document.createElement('div'); const card = document.createElement('div');
card.className = `bg-white p-5 rounded-2xl border ${isBlocked ? 'border-slate-200 opacity-60' : 'border-slate-100 shadow-sm'} flex items-center justify-between hover:shadow-md transition-all fade-in group relative overflow-hidden`; card.className = `bg-white p-5 rounded-2xl border ${isBlocked ? 'opacity-60 bg-slate-50' : 'shadow-sm'} flex items-center justify-between group 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-14 h-14 rounded-2xl flex flex-col items-center justify-center shrink-0 ${isBlocked ? 'bg-slate-200' : (svc.provider === 'homeserve' ? 'bg-red-50 text-red-600' : 'bg-blue-50 text-blue-600')}"> <div class="w-14 h-14 rounded-2xl flex flex-col items-center justify-center shrink-0 ${isBlocked ? 'bg-slate-200 text-slate-500' : 'bg-blue-50 text-blue-600'}">
<span class="text-[8px] font-black uppercase tracking-widest">${shortProv}</span> <span class="text-[8px] font-black">${shortProv}</span>
<i data-lucide="${isBlocked ? 'lock' : 'file-text'}" class="w-5 h-5 mt-0.5"></i> <i data-lucide="${isBlocked ? 'lock' : 'file-text'}" class="w-5 h-5"></i>
</div> </div>
<div class="min-w-0"> <div class="min-w-0">
<h3 class="font-black ${isBlocked ? 'text-slate-400' : 'text-slate-800'} truncate text-lg uppercase">${isBlocked ? 'Expediente Bloqueado' : (rawName || 'S/N')}</h3> <h3 class="font-black ${isBlocked ? 'text-slate-400' : 'text-slate-800'} truncate text-lg">${isBlocked ? 'EXPEDIENTE BLOQUEADO' : name}</h3>
<p class="text-xs text-slate-400 flex items-center gap-1.5 mt-0.5 font-medium truncate"> <p class="text-xs text-slate-400 truncate">${isBlocked ? 'Pendiente de acción en compañía' : addr}</p>
<i data-lucide="map-pin" class="w-3 h-3 text-slate-300"></i> ${isBlocked ? 'Pendiente de liberación' : (fullAddr || 'Sin dirección')}
</p>
</div> </div>
</div> </div>
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
${!isBlocked ? ` ${!isBlocked ? `
<div class="hidden group-hover:flex items-center gap-1 pr-4 border-r border-slate-200 mr-2 fade-in"> <div class="hidden group-hover:flex items-center gap-1 pr-4 border-r mr-2">
<a href="https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(fullAddr)}" target="_blank" class="action-btn p-2.5 rounded-xl bg-slate-100 text-slate-400 hover:text-blue-600 hover:bg-white hover:shadow-sm"><i data-lucide="map" class="w-5 h-5"></i></a> <a href="https://www.google.com/maps/search/${encodeURIComponent(addr)}" target="_blank" class="p-2 hover:text-blue-600"><i data-lucide="map" class="w-5 h-5"></i></a>
<button onclick="openEditor(${svc.id})" class="bg-blue-600 hover:bg-slate-900 text-white p-4 rounded-2xl shadow-lg transition-all active:scale-90"> <button onclick="openEditor(${svc.id})" class="bg-blue-600 text-white p-4 rounded-2xl shadow-lg active:scale-90"><i data-lucide="edit-3"></i></button>
<i data-lucide="edit-3" class="w-6 h-6"></i> </div>` : '<i data-lucide="shield-off" class="text-slate-300 mx-4"></i>'}
</button>` : ` </div>`;
<div class="bg-slate-100 text-slate-400 p-4 rounded-2xl border-2 border-dashed">
<i data-lucide="shield-off" class="w-6 h-6"></i>
</div>`}
</div>
`;
container.appendChild(card); container.appendChild(card);
}); });
lucide.createIcons(); lucide.createIcons();
} catch (e) { showToast("Sincronización interrumpida", true); }
} }
function openEditor(scrapedId) { function openEditor(id) {
const svc = scrapedData.find(s => s.id === scrapedId); const svc = scrapedData.find(s => s.id === id);
if(!svc) return;
const raw = svc.raw_data; const raw = svc.raw_data;
const myMap = mappings.filter(m => m.provider === svc.provider); document.getElementById('impScrapedId').value = id;
document.getElementById('impName').value = raw['Nombre Cliente'] || "";
// 1. TELÉFONO LIMPIO document.getElementById('impPhone').value = (raw['Teléfono'] || "").match(/[6789]\d{8}/)?.[0] || "";
const phoneVal = raw[myMap.find(m => m.target_key === 'phone')?.original_key] || raw['Teléfono'] || ""; document.getElementById('impAddress').value = `${raw['Dirección'] || ""} ${raw['Población'] || ""}`.trim();
const phoneMatch = phoneVal.match(/[6789]\d{8}/); document.getElementById('impCP').value = raw['Código Postal'] || "";
document.getElementById('imp_phone').value = phoneMatch ? phoneMatch[0] : ""; document.getElementById('impDesc').value = raw['Descripción'] || "";
document.getElementById('imp_phone_extra').innerText = phoneVal !== (phoneMatch ? phoneMatch[0] : "") ? `Capturado: ${phoneVal}` : ""; document.getElementById('impRef').value = svc.service_ref;
document.getElementById('impCompany').value = svc.provider.toUpperCase();
// 2. SEPARAR CP Y POBLACIÓN
const rawAddr = raw[myMap.find(m => m.target_key === 'address')?.original_key] || "";
const rawCPField = raw[myMap.find(m => m.target_key === 'cp')?.original_key] || raw['Población_CP'] || "";
const cpMatch = rawCPField.match(/\b\d{5}\b/);
const cpOnly = cpMatch ? cpMatch[0] : "";
const popOnly = rawCPField.replace(cpOnly, '').replace('-', '').trim();
document.getElementById('imp_address').value = `${rawAddr} ${popOnly}`.trim();
document.getElementById('imp_cp').value = cpOnly;
// 3. DESCRIPCIÓN TÉCNICA (LIMPIEZA DE HISTORIAL)
let rawDesc = raw[myMap.find(m => m.target_key === 'descripcion')?.original_key] || raw['Descripción'] || "";
// Cortamos el texto justo antes de la primera fecha de registro (formato 00/00/0000)
const idxDate = rawDesc.search(/\b\d{2}\/\d{2}\/\d{4}\b/);
const cleanDesc = idxDate !== -1 ? rawDesc.substring(0, idxDate).trim() : rawDesc;
document.getElementById('imp_desc').value = cleanDesc;
document.getElementById('imp_company').value = `${svc.provider === 'multiasistencia' ? 'MULTI' : 'HOME'} - ${raw[myMap.find(m => m.target_key === 'compania')?.original_key] || raw['Compañía'] || ""}`;
document.getElementById('scrapedId').value = scrapedId;
document.getElementById('imp_name').value = raw[myMap.find(m => m.target_key === 'clientName')?.original_key] || "";
document.getElementById('imp_ref').value = svc.service_ref;
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();
} }
function closeModal() { document.getElementById('importModal').classList.add('hidden'); } function closeModal() { document.getElementById('importModal').classList.add('hidden'); }
async function handleImportSubmit(e) {
e.preventDefault();
const btn = document.getElementById('btnImport');
btn.disabled = true; btn.innerText = "PROCESANDO...";
const payload = {
name: document.getElementById('imp_name').value,
phone: document.getElementById('imp_phone').value,
address: document.getElementById('imp_address').value,
description: `C.P: ${document.getElementById('imp_cp').value}\n${document.getElementById('imp_desc').value}`,
company_ref: document.getElementById('imp_ref').value,
is_urgent: document.getElementById('imp_urgent').value === 'true'
};
try {
const res = await fetch(`${API_URL}/providers/import/${document.getElementById('scrapedId').value}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${localStorage.getItem("token")}` },
body: JSON.stringify(payload)
});
if(res.ok) {
showToast("✅ ¡Expediente importado!");
closeModal();
loadInbox();
} else { showToast("Error al importar", true); }
} catch (e) { showToast("Error de conexión", true); }
finally { btn.disabled = false; btn.innerText = "IMPORTAR A SERVICIOS"; }
}
function showToast(msg, isError = false) {
const t = document.getElementById('toast'), m = document.getElementById('toastMsg');
t.className = `fixed bottom-8 right-8 px-8 py-4 rounded-2xl shadow-2xl z-[60] flex items-center gap-3 transition-all ${isError ? 'bg-red-600' : 'bg-slate-900'} text-white border border-white/10`;
m.innerText = msg; t.classList.remove('hidden');
setTimeout(() => t.classList.add('hidden'), 4000);
}
</script> </script>
</body> </body>
</html> </html>