Actualizar configuracion.html
This commit is contained in:
@@ -8,11 +8,6 @@
|
|||||||
<script src="https://unpkg.com/lucide@latest"></script>
|
<script src="https://unpkg.com/lucide@latest"></script>
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/qrcodejs/1.0.0/qrcode.min.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/qrcodejs/1.0.0/qrcode.min.js"></script>
|
||||||
<style>
|
<style>
|
||||||
:root {
|
|
||||||
--primary: #2563eb;
|
|
||||||
--secondary: #f59e0b;
|
|
||||||
--app-bg: #f4f7f9;
|
|
||||||
}
|
|
||||||
.fade-in { animation: fadeIn 0.3s ease-in-out; }
|
.fade-in { animation: fadeIn 0.3s ease-in-out; }
|
||||||
.scroller::-webkit-scrollbar { width: 6px; }
|
.scroller::-webkit-scrollbar { width: 6px; }
|
||||||
.scroller::-webkit-scrollbar-thumb { background-color: #cbd5e1; border-radius: 4px; }
|
.scroller::-webkit-scrollbar-thumb { background-color: #cbd5e1; border-radius: 4px; }
|
||||||
@@ -22,9 +17,7 @@
|
|||||||
.toggle-label { background-color: #e2e8f0; transition: all 0.3s ease; cursor: pointer; }
|
.toggle-label { background-color: #e2e8f0; transition: all 0.3s ease; cursor: pointer; }
|
||||||
.keyword-tag { animation: popIn 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
|
.keyword-tag { animation: popIn 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
|
||||||
@keyframes popIn { from { transform: scale(0.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
|
@keyframes popIn { from { transform: scale(0.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
|
||||||
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
|
.var-btn { @apply px-2 py-1 bg-white border border-gray-200 rounded text-xs font-mono font-medium text-gray-600 hover:border-blue-400 hover:text-blue-600 transition shadow-sm; }
|
||||||
.var-btn { padding: 0.25rem 0.5rem; background-color: white; border: 1px solid #e2e8f0; border-radius: 0.25rem; font-family: monospace; font-size: 0.75rem; font-weight: 500; color: #4b5563; transition: all 0.2s; }
|
|
||||||
.var-btn:hover { border-color: #2563eb; color: #2563eb; }
|
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body class="bg-gray-50 text-gray-800 font-sans h-screen overflow-hidden flex">
|
<body class="bg-gray-50 text-gray-800 font-sans h-screen overflow-hidden flex">
|
||||||
@@ -431,7 +424,6 @@
|
|||||||
<input type="text" id="color-primary-hex" class="flex-1 bg-transparent text-sm font-mono font-bold outline-none uppercase" placeholder="#2563EB">
|
<input type="text" id="color-primary-hex" class="flex-1 bg-transparent text-sm font-mono font-bold outline-none uppercase" placeholder="#2563EB">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label class="block text-xs font-black text-slate-500 uppercase tracking-widest mb-3">Color Secundario (Acentos y Badges)</label>
|
<label class="block text-xs font-black text-slate-500 uppercase tracking-widest mb-3">Color Secundario (Acentos y Badges)</label>
|
||||||
<div class="flex items-center gap-4 bg-slate-50 p-3 rounded-xl border border-slate-200">
|
<div class="flex items-center gap-4 bg-slate-50 p-3 rounded-xl border border-slate-200">
|
||||||
@@ -439,7 +431,6 @@
|
|||||||
<input type="text" id="color-secondary-hex" class="flex-1 bg-transparent text-sm font-mono font-bold outline-none uppercase" placeholder="#F59E0B">
|
<input type="text" id="color-secondary-hex" class="flex-1 bg-transparent text-sm font-mono font-bold outline-none uppercase" placeholder="#F59E0B">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label class="block text-xs font-black text-slate-500 uppercase tracking-widest mb-3">Fondo de Pantalla (App)</label>
|
<label class="block text-xs font-black text-slate-500 uppercase tracking-widest mb-3">Fondo de Pantalla (App)</label>
|
||||||
<div class="flex items-center gap-4 bg-slate-50 p-3 rounded-xl border border-slate-200">
|
<div class="flex items-center gap-4 bg-slate-50 p-3 rounded-xl border border-slate-200">
|
||||||
@@ -451,27 +442,27 @@
|
|||||||
|
|
||||||
<div class="flex flex-col items-center">
|
<div class="flex flex-col items-center">
|
||||||
<p class="text-[10px] font-black text-slate-400 uppercase tracking-widest mb-4">Vista Previa en Vivo</p>
|
<p class="text-[10px] font-black text-slate-400 uppercase tracking-widest mb-4">Vista Previa en Vivo</p>
|
||||||
<div id="app-preview" class="w-64 h-[400px] border-[6px] border-slate-800 rounded-[2.5rem] shadow-2xl overflow-hidden relative bg-gray-100 scale-90 origin-top">
|
<div id="app-preview" class="w-64 h-[400px] border-[6px] border-slate-800 rounded-[2.5rem] shadow-2xl overflow-hidden relative scale-90 origin-top">
|
||||||
<div id="prev-header" class="h-20 w-full p-4 text-white" style="background-color: #2563eb;">
|
<div id="prev-header" class="h-20 w-full p-4 text-white">
|
||||||
<div class="w-8 h-2 bg-white/30 rounded mb-2"></div>
|
<div class="w-8 h-2 bg-white/30 rounded mb-2"></div>
|
||||||
<div class="w-20 h-4 bg-white rounded"></div>
|
<div class="w-20 h-4 bg-white rounded"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="p-4 grid grid-cols-2 gap-2">
|
<div class="p-4 grid grid-cols-2 gap-2">
|
||||||
<div class="h-16 bg-white rounded-xl border border-slate-200 shadow-sm flex items-center justify-center">
|
<div class="h-16 bg-white rounded-xl border border-slate-200 shadow-sm flex items-center justify-center">
|
||||||
<div id="prev-icon" class="w-6 h-6 rounded-lg" style="background-color: #f59e0b;"></div>
|
<div id="prev-icon" class="w-6 h-6 rounded-lg"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="h-16 bg-white rounded-xl border border-slate-200 shadow-sm"></div>
|
<div class="h-16 bg-white rounded-xl border border-slate-200 shadow-sm"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="absolute bottom-6 left-4 right-4">
|
<div class="absolute bottom-6 left-4 right-4">
|
||||||
<div id="prev-btn" class="h-10 w-full rounded-xl shadow-md" style="background-color: #2563eb;"></div>
|
<div id="prev-btn" class="h-10 w-full rounded-xl shadow-md"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="pt-6 flex justify-end">
|
<div class="pt-6 flex justify-end">
|
||||||
<button onclick="saveAppConfig()" id="btnSaveApp" class="bg-blue-600 hover:bg-blue-700 text-white font-black py-4 px-10 rounded-2xl shadow-xl shadow-blue-500/30 transition-all uppercase tracking-widest text-xs flex items-center gap-2 active:scale-95">
|
<button onclick="saveAppConfig()" id="btnSaveApp" class="bg-blue-600 hover:bg-blue-700 text-white font-black py-4 px-10 rounded-2xl shadow-xl transition-all uppercase tracking-widest text-xs flex items-center gap-2 active:scale-95">
|
||||||
<i data-lucide="save" class="w-5 h-5"></i> Aplicar a todos los dispositivos
|
<i data-lucide="save" class="w-5 h-5"></i> Aplicar a la App
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -506,7 +497,6 @@
|
|||||||
<div class="p-6">
|
<div class="p-6">
|
||||||
<input type="hidden" id="iaModalGuildId">
|
<input type="hidden" id="iaModalGuildId">
|
||||||
<label class="block text-sm font-bold text-gray-700 mb-2">Palabras Clave</label>
|
<label class="block text-sm font-bold text-gray-700 mb-2">Palabras Clave</label>
|
||||||
<p class="text-xs text-gray-500 mb-3">Escribe palabras clave separadas por comas. Si el robot detecta alguna de ellas en la descripción del servicio, lo asignará a este gremio automáticamente.</p>
|
|
||||||
<textarea id="iaModalKeywords" rows="5" class="w-full border border-gray-300 rounded-xl p-3 text-sm focus:ring-2 focus:ring-purple-500 outline-none" placeholder="Ej: fuga de agua, tubería rota, grifo, desatasco..."></textarea>
|
<textarea id="iaModalKeywords" rows="5" class="w-full border border-gray-300 rounded-xl p-3 text-sm focus:ring-2 focus:ring-purple-500 outline-none" placeholder="Ej: fuga de agua, tubería rota, grifo, desatasco..."></textarea>
|
||||||
</div>
|
</div>
|
||||||
<div class="p-4 border-t bg-gray-50 flex justify-end gap-3">
|
<div class="p-4 border-t bg-gray-50 flex justify-end gap-3">
|
||||||
@@ -523,6 +513,7 @@
|
|||||||
let cachedTemplates = {};
|
let cachedTemplates = {};
|
||||||
let currentTemplateType = null;
|
let currentTemplateType = null;
|
||||||
let localGuilds = [];
|
let localGuilds = [];
|
||||||
|
let currentCompanyConfig = {}; // <--- VARIABLE GLOBAL PARA ALMACENAR LA CONFIGURACIÓN
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", () => {
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
if (!localStorage.getItem("token")) window.location.href = "index.html";
|
if (!localStorage.getItem("token")) window.location.href = "index.html";
|
||||||
@@ -531,9 +522,6 @@
|
|||||||
loadWaSettings();
|
loadWaSettings();
|
||||||
});
|
});
|
||||||
|
|
||||||
// ==========================================
|
|
||||||
// LÓGICA DE NAVEGACIÓN Y TABS
|
|
||||||
// ==========================================
|
|
||||||
function showTab(tabId) {
|
function showTab(tabId) {
|
||||||
document.querySelectorAll('.tab-content').forEach(el => el.classList.add('hidden'));
|
document.querySelectorAll('.tab-content').forEach(el => el.classList.add('hidden'));
|
||||||
document.getElementById(`view-${tabId}`).classList.remove('hidden');
|
document.getElementById(`view-${tabId}`).classList.remove('hidden');
|
||||||
@@ -552,11 +540,169 @@
|
|||||||
if(tabId === 'whatsapp') { checkWhatsappStatus(); }
|
if(tabId === 'whatsapp') { checkWhatsappStatus(); }
|
||||||
if(tabId === 'portal') { loadPortalConfig(); }
|
if(tabId === 'portal') { loadPortalConfig(); }
|
||||||
if(tabId === 'app-operario') { loadAppConfig(); }
|
if(tabId === 'app-operario') { loadAppConfig(); }
|
||||||
if(tabId === 'providers') {
|
if(tabId === 'providers') { loadProviderCredentials(); loadIaRules(); }
|
||||||
loadProviderCredentials();
|
}
|
||||||
loadIaRules();
|
|
||||||
|
// ==========================================
|
||||||
|
// LÓGICA PORTAL OPERARIO (COLORES)
|
||||||
|
// ==========================================
|
||||||
|
['primary', 'secondary', 'bg'].forEach(type => {
|
||||||
|
const picker = document.getElementById(`color-${type}`);
|
||||||
|
const text = document.getElementById(`color-${type}-hex`);
|
||||||
|
picker.addEventListener('input', (e) => {
|
||||||
|
text.value = e.target.value.toUpperCase();
|
||||||
|
updateAppPreview();
|
||||||
|
});
|
||||||
|
text.addEventListener('input', (e) => {
|
||||||
|
if(/^#[0-9A-F]{6}$/i.test(e.target.value)) {
|
||||||
|
picker.value = e.target.value;
|
||||||
|
updateAppPreview();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function updateAppPreview() {
|
||||||
|
const p = document.getElementById('color-primary').value;
|
||||||
|
const s = document.getElementById('color-secondary').value;
|
||||||
|
const b = document.getElementById('color-bg').value;
|
||||||
|
document.getElementById('prev-header').style.backgroundColor = p;
|
||||||
|
document.getElementById('prev-icon').style.backgroundColor = s;
|
||||||
|
document.getElementById('prev-btn').style.backgroundColor = p;
|
||||||
|
document.getElementById('app-preview').style.backgroundColor = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadAppConfig() {
|
||||||
|
try {
|
||||||
|
const res = await fetch(`${API_URL}/config/company`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
||||||
|
const data = await res.json();
|
||||||
|
if (data.ok && data.config) {
|
||||||
|
currentCompanyConfig = data.config; // Guardar toda la config
|
||||||
|
|
||||||
|
// Los colores los vamos a guardar dentro de portal_settings para evitar el error 500
|
||||||
|
const s = (data.config.portal_settings && data.config.portal_settings.app_settings) ? data.config.portal_settings.app_settings : {};
|
||||||
|
document.getElementById('color-primary').value = s.primary || "#2563EB";
|
||||||
|
document.getElementById('color-primary-hex').value = s.primary || "#2563EB";
|
||||||
|
document.getElementById('color-secondary').value = s.secondary || "#F59E0B";
|
||||||
|
document.getElementById('color-secondary-hex').value = s.secondary || "#F59E0B";
|
||||||
|
document.getElementById('color-bg').value = s.bg || "#F4F7F9";
|
||||||
|
document.getElementById('color-bg-hex').value = s.bg || "#F4F7F9";
|
||||||
|
updateAppPreview();
|
||||||
|
}
|
||||||
|
} catch (e) { console.error("Error cargando colores"); }
|
||||||
|
}
|
||||||
|
|
||||||
|
async function saveAppConfig() {
|
||||||
|
const btn = document.getElementById('btnSaveApp');
|
||||||
|
const original = btn.innerHTML;
|
||||||
|
btn.innerHTML = '<i data-lucide="loader-2" class="w-4 h-4 animate-spin"></i> Aplicando...';
|
||||||
|
lucide.createIcons();
|
||||||
|
|
||||||
|
const appSettings = {
|
||||||
|
primary: document.getElementById('color-primary').value,
|
||||||
|
secondary: document.getElementById('color-secondary').value,
|
||||||
|
bg: document.getElementById('color-bg').value
|
||||||
|
};
|
||||||
|
|
||||||
|
// TRAMPA ANTI-ERROR 500: Metemos los colores DENTRO de portal_settings
|
||||||
|
const portalSettings = currentCompanyConfig.portal_settings || {};
|
||||||
|
portalSettings.app_settings = appSettings;
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
company_name: currentCompanyConfig.full_name || null,
|
||||||
|
company_logo: currentCompanyConfig.company_logo || null,
|
||||||
|
portal_settings: portalSettings
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await fetch(`${API_URL}/config/company`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
|
||||||
|
body: JSON.stringify(payload)
|
||||||
|
});
|
||||||
|
if (res.ok) {
|
||||||
|
showToast("✅ Colores de la App actualizados");
|
||||||
|
localStorage.setItem('app_theme', JSON.stringify(appSettings));
|
||||||
|
} else {
|
||||||
|
showToast("❌ Error al guardar", true);
|
||||||
|
}
|
||||||
|
} catch (e) { showToast("Error de conexión", true); }
|
||||||
|
finally { btn.innerHTML = original; lucide.createIcons(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==========================================
|
||||||
|
// LÓGICA PORTAL CLIENTE
|
||||||
|
// ==========================================
|
||||||
|
async function loadPortalConfig() {
|
||||||
|
try {
|
||||||
|
const res = await fetch(`${API_URL}/config/company`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
||||||
|
const data = await res.json();
|
||||||
|
if (data.ok && data.config) {
|
||||||
|
currentCompanyConfig = data.config; // Guardar toda la config
|
||||||
|
|
||||||
|
document.getElementById('confCompanyName').value = data.config.full_name || "";
|
||||||
|
if (data.config.company_logo) {
|
||||||
|
document.getElementById('confLogoBase64').value = data.config.company_logo;
|
||||||
|
document.getElementById('logoPreview').innerHTML = `<img src="${data.config.company_logo}" class="w-full h-full object-contain">`;
|
||||||
|
}
|
||||||
|
if (data.config.portal_settings) {
|
||||||
|
const s = data.config.portal_settings;
|
||||||
|
if(s.m_start) document.getElementById('mStart').value = s.m_start;
|
||||||
|
if(s.m_end) document.getElementById('mEnd').value = s.m_end;
|
||||||
|
if(s.a_start) document.getElementById('aStart').value = s.a_start;
|
||||||
|
if(s.a_end) document.getElementById('aEnd').value = s.a_end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (e) { console.error("Error portal"); }
|
||||||
|
}
|
||||||
|
|
||||||
|
function encodeLogo(input) {
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.onload = (e) => {
|
||||||
|
document.getElementById('confLogoBase64').value = e.target.result;
|
||||||
|
document.getElementById('logoPreview').innerHTML = `<img src="${e.target.result}" class="w-full h-full object-contain">`;
|
||||||
|
};
|
||||||
|
reader.readAsDataURL(input.files[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function savePortalConfig() {
|
||||||
|
const btn = document.getElementById('btnSavePortal');
|
||||||
|
const original = btn.innerHTML;
|
||||||
|
btn.innerHTML = '<i data-lucide="loader-2" class="w-4 h-4 animate-spin"></i> Guardando...';
|
||||||
|
lucide.createIcons();
|
||||||
|
|
||||||
|
// Usamos la variable global para no borrar los colores
|
||||||
|
const portalSettings = currentCompanyConfig.portal_settings || {};
|
||||||
|
portalSettings.m_start = document.getElementById('mStart').value;
|
||||||
|
portalSettings.m_end = document.getElementById('mEnd').value;
|
||||||
|
portalSettings.a_start = document.getElementById('aStart').value;
|
||||||
|
portalSettings.a_end = document.getElementById('aEnd').value;
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
company_name: document.getElementById('confCompanyName').value,
|
||||||
|
company_logo: document.getElementById('confLogoBase64').value,
|
||||||
|
portal_settings: portalSettings
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await fetch(`${API_URL}/config/company`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
|
||||||
|
body: JSON.stringify(payload)
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = await res.json();
|
||||||
|
|
||||||
|
if (data.ok) {
|
||||||
|
showToast("✅ Configuración del Portal guardada");
|
||||||
|
const nameEl = document.getElementById("headerUserName");
|
||||||
|
if (nameEl && payload.company_name) nameEl.innerText = payload.company_name;
|
||||||
|
} else {
|
||||||
|
showToast("Error: " + data.error, true);
|
||||||
|
}
|
||||||
|
} catch (e) { showToast("Error de conexión", true); }
|
||||||
|
finally { btn.innerHTML = original; lucide.createIcons(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ==========================================
|
// ==========================================
|
||||||
// LÓGICA DE INTELIGENCIA ARTIFICIAL (GREMIOS)
|
// LÓGICA DE INTELIGENCIA ARTIFICIAL (GREMIOS)
|
||||||
@@ -634,80 +780,6 @@
|
|||||||
} catch (e) { showToast("❌ Error de conexión.", true); }
|
} catch (e) { showToast("❌ Error de conexión.", true); }
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==========================================
|
|
||||||
// LÓGICA PORTAL OPERARIO (COLORES)
|
|
||||||
// ==========================================
|
|
||||||
['primary', 'secondary', 'bg'].forEach(type => {
|
|
||||||
const picker = document.getElementById(`color-${type}`);
|
|
||||||
const text = document.getElementById(`color-${type}-hex`);
|
|
||||||
if(picker && text) {
|
|
||||||
picker.addEventListener('input', (e) => {
|
|
||||||
text.value = e.target.value.toUpperCase();
|
|
||||||
updateAppPreview();
|
|
||||||
});
|
|
||||||
text.addEventListener('input', (e) => {
|
|
||||||
if(/^#[0-9A-F]{6}$/i.test(e.target.value)) {
|
|
||||||
picker.value = e.target.value;
|
|
||||||
updateAppPreview();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
function updateAppPreview() {
|
|
||||||
const p = document.getElementById('color-primary').value;
|
|
||||||
const s = document.getElementById('color-secondary').value;
|
|
||||||
const b = document.getElementById('color-bg').value;
|
|
||||||
document.getElementById('prev-header').style.backgroundColor = p;
|
|
||||||
document.getElementById('prev-icon').style.backgroundColor = s;
|
|
||||||
document.getElementById('prev-btn').style.backgroundColor = p;
|
|
||||||
document.getElementById('app-preview').style.backgroundColor = b;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function loadAppConfig() {
|
|
||||||
try {
|
|
||||||
const res = await fetch(`${API_URL}/config/company`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
|
||||||
const data = await res.json();
|
|
||||||
if (data.ok && data.config && data.config.app_settings) {
|
|
||||||
const s = data.config.app_settings;
|
|
||||||
document.getElementById('color-primary').value = s.primary || "#2563EB";
|
|
||||||
document.getElementById('color-primary-hex').value = s.primary || "#2563EB";
|
|
||||||
document.getElementById('color-secondary').value = s.secondary || "#F59E0B";
|
|
||||||
document.getElementById('color-secondary-hex').value = s.secondary || "#F59E0B";
|
|
||||||
document.getElementById('color-bg').value = s.bg || "#F4F7F9";
|
|
||||||
document.getElementById('color-bg-hex').value = s.bg || "#F4F7F9";
|
|
||||||
updateAppPreview();
|
|
||||||
}
|
|
||||||
} catch (e) { console.error("Error cargando colores"); }
|
|
||||||
}
|
|
||||||
|
|
||||||
async function saveAppConfig() {
|
|
||||||
const btn = document.getElementById('btnSaveApp');
|
|
||||||
const original = btn.innerHTML;
|
|
||||||
btn.innerHTML = '<i data-lucide="loader-2" class="w-4 h-4 animate-spin"></i> Aplicando...';
|
|
||||||
lucide.createIcons();
|
|
||||||
|
|
||||||
const settings = {
|
|
||||||
primary: document.getElementById('color-primary').value,
|
|
||||||
secondary: document.getElementById('color-secondary').value,
|
|
||||||
bg: document.getElementById('color-bg').value
|
|
||||||
};
|
|
||||||
try {
|
|
||||||
const res = await fetch(`${API_URL}/config/company`, {
|
|
||||||
method: 'POST', headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
|
|
||||||
body: JSON.stringify({ app_settings: settings })
|
|
||||||
});
|
|
||||||
if (res.ok) {
|
|
||||||
showToast("✅ Colores de la App actualizados");
|
|
||||||
localStorage.setItem('app_theme', JSON.stringify(settings));
|
|
||||||
}
|
|
||||||
} catch (e) { showToast("Error al guardar", true); }
|
|
||||||
finally { btn.innerHTML = original; lucide.createIcons(); }
|
|
||||||
}
|
|
||||||
|
|
||||||
// ==========================================
|
|
||||||
// LÓGICA WHATSAPP
|
|
||||||
// ==========================================
|
|
||||||
async function loadWaSettings() {
|
async function loadWaSettings() {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${API_URL}/whatsapp/settings`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
const res = await fetch(`${API_URL}/whatsapp/settings`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
||||||
@@ -720,7 +792,7 @@
|
|||||||
document.getElementById('cfg_evt_onway').checked = s.wa_evt_onway || false;
|
document.getElementById('cfg_evt_onway').checked = s.wa_evt_onway || false;
|
||||||
document.getElementById('cfg_evt_finished').checked = s.wa_evt_finished || false;
|
document.getElementById('cfg_evt_finished').checked = s.wa_evt_finished || false;
|
||||||
document.getElementById('cfg_evt_survey').checked = s.wa_evt_survey || false;
|
document.getElementById('cfg_evt_survey').checked = s.wa_evt_survey || false;
|
||||||
} catch(e) { console.error("Error cargando ajustes WA"); }
|
} catch(e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveWaSettings() {
|
async function saveWaSettings() {
|
||||||
@@ -734,238 +806,105 @@
|
|||||||
wa_evt_survey: document.getElementById('cfg_evt_survey').checked
|
wa_evt_survey: document.getElementById('cfg_evt_survey').checked
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${API_URL}/whatsapp/settings`, {
|
const res = await fetch(`${API_URL}/whatsapp/settings`, { method: 'POST', headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` }, body: JSON.stringify(settings) });
|
||||||
method: 'POST', headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
|
if (res.ok) showToast("✅ Ajustes WhatsApp guardados");
|
||||||
body: JSON.stringify(settings)
|
} catch(e) {}
|
||||||
});
|
|
||||||
if (res.ok) showToast("✅ Ajustes de WhatsApp guardados");
|
|
||||||
else showToast("❌ Error al guardar", true);
|
|
||||||
} catch(e) { showToast("❌ Error de conexión", true); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkWhatsappStatus() {
|
async function checkWhatsappStatus() {
|
||||||
const container = document.getElementById('waStatusContainer');
|
const container = document.getElementById('waStatusContainer');
|
||||||
container.innerHTML = `<div class="flex flex-col items-center animate-pulse"><div class="w-10 h-10 border-4 border-blue-200 border-t-blue-600 rounded-full animate-spin mb-4"></div><span class="text-sm font-bold text-slate-400">Verificando instancia...</span></div>`;
|
container.innerHTML = `<div class="animate-spin w-10 h-10 border-4 border-blue-200 border-t-blue-600 rounded-full mx-auto"></div>`;
|
||||||
lucide.createIcons();
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${API_URL}/whatsapp/status`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
const res = await fetch(`${API_URL}/whatsapp/status`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
if (!data.ok) throw new Error(data.error || "Error desconocido");
|
if (data.state === "open") container.innerHTML = `<div class="text-green-600 font-bold"><i data-lucide="check-circle" class="w-12 h-12 mx-auto mb-2"></i> Conectado</div>`;
|
||||||
if (data.state === "open") {
|
else if (data.qr) container.innerHTML = `<img src="${data.qr}" class="w-48 h-48 rounded-lg shadow-sm border">`;
|
||||||
container.innerHTML = `<div class="flex flex-col items-center"><div class="w-16 h-16 bg-green-100 rounded-full flex items-center justify-center mb-4 shadow-sm border border-green-200"><i data-lucide="check" class="w-8 h-8 text-green-600"></i></div><h4 class="text-xl font-bold text-green-700">Conectado</h4><p class="text-xs text-green-600 mt-1 font-medium bg-green-50 px-2 py-1 rounded">Instancia: ${data.instanceName}</p></div>`;
|
else container.innerHTML = `<p class="text-orange-500">Iniciando...</p>`;
|
||||||
} else if (data.qr) {
|
|
||||||
container.innerHTML = `<div class="flex flex-col items-center w-full"><div id="qrcode" class="bg-white p-3 border rounded-xl shadow-sm"></div><p class="text-xs text-orange-500 mt-4 font-bold animate-pulse">Esperando escaneo...</p></div>`;
|
|
||||||
if(data.qr.startsWith('data:image')) { document.getElementById('qrcode').innerHTML = `<img src="${data.qr}" class="w-48 h-48 rounded-lg">`; }
|
|
||||||
else { new QRCode(document.getElementById("qrcode"), { text: data.qr, width: 180, height: 180 }); }
|
|
||||||
} else { container.innerHTML = `<p class="text-orange-500 font-bold">Iniciando... intenta de nuevo en unos segundos.</p>`; }
|
|
||||||
} catch(e) {
|
|
||||||
container.innerHTML = `<div class="text-center text-red-500 p-4"><i data-lucide="alert-triangle" class="w-10 h-10 mx-auto mb-2 opacity-80"></i><p class="font-bold">Error de conexión</p><p class="text-xs mt-1 bg-red-50 p-2 rounded">${e.message}</p></div>`;
|
|
||||||
}
|
|
||||||
lucide.createIcons();
|
lucide.createIcons();
|
||||||
|
} catch(e) { container.innerHTML = `<p class="text-red-500">Error servidor</p>`; }
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==========================================
|
|
||||||
// LÓGICA PLANTILLAS
|
|
||||||
// ==========================================
|
|
||||||
async function loadTemplates() {
|
async function loadTemplates() {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${API_URL}/templates`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
const res = await fetch(`${API_URL}/templates`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
if(data.ok) {
|
if(data.ok) { data.templates.forEach(t => { cachedTemplates[t.type] = t.content; }); if (!currentTemplateType) document.querySelector('.tpl-btn').click(); }
|
||||||
data.templates.forEach(t => { cachedTemplates[t.type] = t.content; });
|
} catch(e) {}
|
||||||
if (!currentTemplateType) { const firstBtn = document.querySelector('.tpl-btn'); if(firstBtn) firstBtn.click(); }
|
|
||||||
}
|
|
||||||
} catch(e) { console.error("Error templates"); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectTemplate(type, btn) {
|
function selectTemplate(type, btn) {
|
||||||
currentTemplateType = type;
|
currentTemplateType = type;
|
||||||
document.querySelectorAll('.tpl-btn').forEach(b => {
|
document.querySelectorAll('.tpl-btn').forEach(b => b.classList.remove('bg-blue-50', 'ring-1', 'ring-blue-200'));
|
||||||
b.classList.remove('bg-blue-50', 'ring-1', 'ring-blue-200');
|
|
||||||
const s = b.querySelector('span');
|
|
||||||
if(s.classList.contains('bg-blue-600')) s.classList.replace('bg-blue-600', 'bg-blue-100'), s.classList.replace('text-white', 'text-blue-600');
|
|
||||||
if(s.classList.contains('bg-orange-600')) s.classList.replace('bg-orange-600', 'bg-orange-100'), s.classList.replace('text-white', 'text-orange-600');
|
|
||||||
});
|
|
||||||
btn.classList.add('bg-blue-50', 'ring-1', 'ring-blue-200');
|
btn.classList.add('bg-blue-50', 'ring-1', 'ring-blue-200');
|
||||||
const span = btn.querySelector('span');
|
|
||||||
if (span.classList.contains('bg-blue-100')) span.classList.replace('bg-blue-100', 'bg-blue-600'), span.classList.replace('text-blue-600', 'text-white');
|
|
||||||
else if (span.classList.contains('bg-orange-100')) span.classList.replace('bg-orange-100', 'bg-orange-600'), span.classList.replace('text-orange-600', 'text-white');
|
|
||||||
document.getElementById('editorTitle').innerText = btn.innerText.trim();
|
document.getElementById('editorTitle').innerText = btn.innerText.trim();
|
||||||
document.getElementById('tplContent').value = cachedTemplates[type] || "";
|
document.getElementById('tplContent').value = cachedTemplates[type] || "";
|
||||||
}
|
}
|
||||||
|
|
||||||
function insertVar(text) {
|
function insertVar(text) {
|
||||||
const textarea = document.getElementById('tplContent');
|
const textarea = document.getElementById('tplContent');
|
||||||
if (!textarea) return;
|
|
||||||
const start = textarea.selectionStart, end = textarea.selectionEnd, val = textarea.value;
|
const start = textarea.selectionStart, end = textarea.selectionEnd, val = textarea.value;
|
||||||
textarea.value = val.substring(0, start) + text + val.substring(end);
|
textarea.value = val.substring(0, start) + text + val.substring(end);
|
||||||
textarea.focus();
|
textarea.focus();
|
||||||
textarea.selectionStart = textarea.selectionEnd = start + text.length;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveTemplate() {
|
async function saveTemplate() {
|
||||||
if(!currentTemplateType) { showToast("Selecciona plantilla", true); return; }
|
|
||||||
const content = document.getElementById('tplContent').value;
|
const content = document.getElementById('tplContent').value;
|
||||||
try {
|
await fetch(`${API_URL}/templates`, { method: 'POST', headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` }, body: JSON.stringify({ type: currentTemplateType, content: content }) });
|
||||||
const res = await fetch(`${API_URL}/templates`, {
|
cachedTemplates[currentTemplateType] = content;
|
||||||
method: 'POST', headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
|
showToast("Guardado");
|
||||||
body: JSON.stringify({ type: currentTemplateType, content: content })
|
|
||||||
});
|
|
||||||
if(res.ok) { cachedTemplates[currentTemplateType] = content; showToast("Guardado"); } else { showToast("Error", true); }
|
|
||||||
} catch(e) { showToast("Error", true); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==========================================
|
|
||||||
// LÓGICA OTROS (COMPAÑÍAS Y ESTADOS)
|
|
||||||
// ==========================================
|
|
||||||
async function loadCompanies() {
|
async function loadCompanies() {
|
||||||
const list = document.getElementById('listCompanies');
|
|
||||||
list.innerHTML = '<p class="text-center text-xs text-gray-400 mt-10">Cargando...</p>';
|
|
||||||
try {
|
|
||||||
const res = await fetch(`${API_URL}/companies`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
const res = await fetch(`${API_URL}/companies`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
list.innerHTML = "";
|
const list = document.getElementById('listCompanies'); list.innerHTML = "";
|
||||||
if(data.companies.length === 0) { list.innerHTML = '<p class="text-center text-xs text-gray-400 mt-4">Sin compañías.</p>'; return; }
|
data.companies.forEach(c => { list.innerHTML += `<div class="p-3 border border-gray-100 rounded-lg bg-gray-50 flex justify-between items-center"><span class="font-bold text-sm">${c.name}</span><button onclick="deleteCompany(${c.id})" class="text-gray-300 hover:text-red-500"><i data-lucide="trash-2" class="w-4 h-4"></i></button></div>`; });
|
||||||
data.companies.forEach(c => {
|
|
||||||
const div = document.createElement('div');
|
|
||||||
div.className = "p-3 border border-gray-100 rounded-lg bg-gray-50 flex justify-between items-center group hover:border-blue-200 transition-colors";
|
|
||||||
div.innerHTML = `<span class="font-bold text-gray-700 text-sm">${c.name}</span><button onclick="deleteCompany(${c.id})" class="text-gray-300 hover:text-red-500"><i data-lucide="trash-2" class="w-4 h-4"></i></button>`;
|
|
||||||
list.appendChild(div);
|
|
||||||
});
|
|
||||||
lucide.createIcons();
|
lucide.createIcons();
|
||||||
} catch(e) { list.innerHTML = '<p class="text-red-500 text-xs text-center">Error</p>'; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addCompany() {
|
async function addCompany() {
|
||||||
const input = document.getElementById('newCompanyInput'), name = input.value.trim();
|
const name = document.getElementById('newCompanyInput').value;
|
||||||
if(!name) return;
|
await fetch(`${API_URL}/companies`, { method: 'POST', headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` }, body: JSON.stringify({ name }) });
|
||||||
try {
|
document.getElementById('newCompanyInput').value = ""; loadCompanies();
|
||||||
const res = await fetch(`${API_URL}/companies`, { method: 'POST', headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` }, body: JSON.stringify({ name: name }) });
|
|
||||||
if(res.ok) { showToast("Añadido"); input.value = ""; loadCompanies(); }
|
|
||||||
} catch(e) { showToast("Error", true); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteCompany(id) {
|
async function deleteCompany(id) { if(confirm("Borrar?")) { await fetch(`${API_URL}/companies/${id}`, { method: 'DELETE', headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } }); loadCompanies(); } }
|
||||||
if(!confirm("¿Borrar?")) return;
|
|
||||||
await fetch(`${API_URL}/companies/${id}`, { method: 'DELETE', headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
|
||||||
loadCompanies();
|
|
||||||
}
|
|
||||||
|
|
||||||
async function loadStatusesConfig() {
|
async function loadStatusesConfig() {
|
||||||
const list = document.getElementById('listStatuses');
|
|
||||||
list.innerHTML = '<p class="text-center text-xs text-gray-400 mt-10">Cargando...</p>';
|
|
||||||
try {
|
|
||||||
const res = await fetch(`${API_URL}/statuses`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
const res = await fetch(`${API_URL}/statuses`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
list.innerHTML = "";
|
const list = document.getElementById('listStatuses'); list.innerHTML = "";
|
||||||
data.statuses.forEach(s => {
|
data.statuses.forEach(s => { list.innerHTML += `<div class="p-3 border border-gray-100 rounded-lg bg-gray-50 flex justify-between items-center"><div class="flex items-center gap-2"><div class="w-3 h-3 rounded-full bg-${s.color}-500"></div><span class="font-bold text-sm">${s.name}</span></div>${s.is_system ? '<i data-lucide="lock" class="w-4 h-4 text-gray-300"></i>' : `<button onclick="deleteStatus(${s.id})" class="text-gray-300 hover:text-red-500"><i data-lucide="trash-2" class="w-4 h-4"></i></button>`}</div>`; });
|
||||||
const div = document.createElement('div');
|
|
||||||
div.className = "p-3 border border-gray-100 rounded-lg bg-gray-50 flex justify-between items-center group hover:border-blue-200 transition-colors";
|
|
||||||
const actionBtn = s.is_system ? `<i data-lucide="lock" class="w-4 h-4 text-slate-300" title="Estado del sistema"></i>` : `<button onclick="deleteStatus(${s.id})" class="text-gray-300 hover:text-red-500"><i data-lucide="trash-2" class="w-4 h-4"></i></button>`;
|
|
||||||
div.innerHTML = `<div class="flex items-center gap-3"><div class="w-3 h-3 rounded-full bg-${s.color}-500"></div><span class="font-bold text-gray-700 text-sm">${s.name}</span></div>${actionBtn}`;
|
|
||||||
list.appendChild(div);
|
|
||||||
});
|
|
||||||
lucide.createIcons();
|
lucide.createIcons();
|
||||||
} catch(e) { list.innerHTML = '<p class="text-red-500 text-xs text-center">Error</p>'; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addStatus() {
|
async function addStatus() {
|
||||||
const input = document.getElementById('newStatusInput'), color = document.getElementById('newStatusColor').value, name = input.value.trim();
|
const name = document.getElementById('newStatusInput').value;
|
||||||
if(!name) return;
|
const color = document.getElementById('newStatusColor').value;
|
||||||
try {
|
await fetch(`${API_URL}/statuses`, { method: 'POST', headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` }, body: JSON.stringify({ name, color }) });
|
||||||
const res = await fetch(`${API_URL}/statuses`, { method: 'POST', headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` }, body: JSON.stringify({ name: name, color: color }) });
|
document.getElementById('newStatusInput').value = ""; loadStatusesConfig();
|
||||||
if(res.ok) { showToast("Añadido"); input.value = ""; loadStatusesConfig(); }
|
|
||||||
} catch(e) { showToast("Error", true); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteStatus(id) {
|
async function deleteStatus(id) { if(confirm("Borrar?")) { await fetch(`${API_URL}/statuses/${id}`, { method: 'DELETE', headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } }); loadStatusesConfig(); } }
|
||||||
if(!confirm("¿Borrar estado?")) return;
|
|
||||||
try {
|
|
||||||
const res = await fetch(`${API_URL}/statuses/${id}`, { method: 'DELETE', headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
|
||||||
if(res.ok) { showToast("Estado eliminado"); loadStatusesConfig(); }
|
|
||||||
else { const j = await res.json(); showToast(j.error || "Error", true); }
|
|
||||||
} catch(e) { showToast("Error de conexión", true); }
|
|
||||||
}
|
|
||||||
|
|
||||||
// ==========================================
|
|
||||||
// LÓGICA PROVEEDORES CREDENCIALES
|
|
||||||
// ==========================================
|
|
||||||
async function loadProviderCredentials() {
|
async function loadProviderCredentials() {
|
||||||
try {
|
|
||||||
const res = await fetch(`${API_URL}/providers/credentials`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
const res = await fetch(`${API_URL}/providers/credentials`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
if(data.ok) {
|
|
||||||
data.credentials.forEach(c => {
|
data.credentials.forEach(c => {
|
||||||
const userInp = document.getElementById(`user_${c.provider.toLowerCase()}`);
|
const inp = document.getElementById(`user_${c.provider.toLowerCase()}`);
|
||||||
if(userInp) userInp.value = c.username;
|
if(inp) inp.value = c.username;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch(e) { console.error("Error creds"); }
|
|
||||||
}
|
|
||||||
|
|
||||||
// ==========================================
|
|
||||||
// LÓGICA PORTAL CLIENTE
|
|
||||||
// ==========================================
|
|
||||||
async function loadPortalConfig() {
|
|
||||||
try {
|
|
||||||
const res = await fetch(`${API_URL}/config/company`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
|
||||||
const data = await res.json();
|
|
||||||
if (data.ok && data.config) {
|
|
||||||
document.getElementById('confCompanyName').value = data.config.full_name || "";
|
|
||||||
if (data.config.company_logo) {
|
|
||||||
document.getElementById('confLogoBase64').value = data.config.company_logo;
|
|
||||||
document.getElementById('logoPreview').innerHTML = `<img src="${data.config.company_logo}" class="w-full h-full object-contain">`;
|
|
||||||
}
|
|
||||||
if (data.config.portal_settings) {
|
|
||||||
const s = data.config.portal_settings;
|
|
||||||
if(s.m_start) document.getElementById('mStart').value = s.m_start;
|
|
||||||
if(s.m_end) document.getElementById('mEnd').value = s.m_end;
|
|
||||||
if(s.a_start) document.getElementById('aStart').value = s.a_start;
|
|
||||||
if(s.a_end) document.getElementById('aEnd').value = s.a_end;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e) { console.error("Error portal"); }
|
|
||||||
}
|
|
||||||
|
|
||||||
function encodeLogo(input) {
|
|
||||||
const file = input.files[0];
|
|
||||||
if (!file || file.size > 1024 * 1024) { alert("Máximo 1MB"); return; }
|
|
||||||
const reader = new FileReader();
|
|
||||||
reader.onload = (e) => {
|
|
||||||
document.getElementById('confLogoBase64').value = e.target.result;
|
|
||||||
document.getElementById('logoPreview').innerHTML = `<img src="${e.target.result}" class="w-full h-full object-contain">`;
|
|
||||||
};
|
|
||||||
reader.readAsDataURL(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function savePortalConfig() {
|
|
||||||
const btn = document.getElementById('btnSavePortal'), original = btn.innerHTML;
|
|
||||||
btn.innerHTML = '<i data-lucide="loader-2" class="w-4 h-4 animate-spin"></i> Guardando...';
|
|
||||||
lucide.createIcons();
|
|
||||||
const payload = {
|
|
||||||
company_name: document.getElementById('confCompanyName').value,
|
|
||||||
company_logo: document.getElementById('confLogoBase64').value,
|
|
||||||
portal_settings: {
|
|
||||||
m_start: document.getElementById('mStart').value, m_end: document.getElementById('mEnd').value,
|
|
||||||
a_start: document.getElementById('aStart').value, a_end: document.getElementById('aEnd').value
|
|
||||||
}
|
|
||||||
};
|
|
||||||
try {
|
|
||||||
const res = await fetch(`${API_URL}/config/company`, {
|
|
||||||
method: 'POST', headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
|
|
||||||
body: JSON.stringify(payload)
|
|
||||||
});
|
|
||||||
if (res.ok) showToast("Configuración del Portal guardada");
|
|
||||||
} catch (e) { showToast("Error conexión", true); }
|
|
||||||
finally { btn.innerHTML = original; lucide.createIcons(); }
|
|
||||||
}
|
|
||||||
|
|
||||||
function showToast(msg, isError = false) {
|
function showToast(msg, isError = false) {
|
||||||
const t = document.getElementById('toast'), m = document.getElementById('toastMsg');
|
const t = document.getElementById('toast'), m = document.getElementById('toastMsg');
|
||||||
t.className = `fixed bottom-5 right-5 px-6 py-3 rounded-lg shadow-xl transition-all duration-300 z-50 flex items-center gap-3 ${isError ? 'bg-red-600' : 'bg-slate-800'} text-white font-medium`;
|
t.className = `fixed bottom-5 right-5 px-6 py-3 rounded-lg shadow-xl transition-all duration-300 z-50 flex items-center gap-3 ${isError ? 'bg-red-600' : 'bg-slate-800'} text-white font-medium opacity-100 translate-y-0`;
|
||||||
m.innerText = msg; t.classList.remove('translate-y-20', 'opacity-0');
|
m.innerText = msg;
|
||||||
setTimeout(() => t.classList.add('translate-y-20', 'opacity-0'), 3000);
|
setTimeout(() => t.className += " opacity-0 translate-y-20", 3000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function logout() { localStorage.clear(); window.location.href = "index.html"; }
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user