Actualizar configuracion.html

This commit is contained in:
2026-03-08 21:25:31 +00:00
parent fe595aea66
commit 3c7f5075fa

View File

@@ -754,6 +754,7 @@
if(tabId === 'providers') {
loadProviderCredentials();
loadIaRules();
loadRobotConfig(); // 👇 ¡AQUÍ ESTABA EL FALLO! Faltaba llamar a esta función
}
}
@@ -1243,11 +1244,15 @@
}
async function saveRobotConfig() {
const resGet = await fetch(`${API_URL}/whatsapp/settings`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
const dataGet = await resGet.json();
const currentSettings = dataGet.settings || {};
// Ponemos el botón en modo "Cargando..."
const btn = document.querySelector('button[onclick="saveRobotConfig()"]');
const originalHtml = btn.innerHTML;
btn.innerHTML = '<i data-lucide="loader-2" class="w-4 h-4 animate-spin"></i> Guardando...';
lucide.createIcons();
currentSettings.robot_homeserve = {
// Construimos SOLO el objeto del robot (el servidor ya se encarga de no borrar el de WhatsApp)
const payload = {
robot_homeserve: {
assign: {
enabled: document.getElementById('hs_cfg_assign_enabled').checked,
status: document.getElementById('hs_cfg_assign_status').value,
@@ -1269,52 +1274,6 @@
check_inform: document.getElementById('hs_cfg_notfound_inform').checked,
obs: document.getElementById('hs_cfg_notfound_obs').value
}
};
try {
const res = await fetch(`${API_URL}/whatsapp/settings`, {
method: 'POST',
headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
body: JSON.stringify(currentSettings)
});
if (res.ok) {
showToast("✅ Reglas del Robot guardadas");
} else {
showToast("❌ Error al guardar", true);
}
} catch(e) {
showToast("❌ Error de conexión", true);
}
}
async function saveRobotConfig() {
// Obtenemos todos los settings actuales para no sobreescribir lo de WhatsApp
const resGet = await fetch(`${API_URL}/whatsapp/settings`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
const dataGet = await resGet.json();
const currentSettings = dataGet.settings || {};
// Construimos el nuevo objeto del robot
currentSettings.robot_homeserve = {
assign: {
enabled: document.getElementById('hs_cfg_assign_enabled').checked,
status: document.getElementById('hs_cfg_assign_status').value,
days_next: parseInt(document.getElementById('hs_cfg_assign_days').value) || 0,
check_inform: document.getElementById('hs_cfg_assign_inform').checked,
obs: document.getElementById('hs_cfg_assign_obs').value
},
date: {
enabled: document.getElementById('hs_cfg_date_enabled').checked,
status: document.getElementById('hs_cfg_date_status').value,
days_next: parseInt(document.getElementById('hs_cfg_date_days').value) || 0,
check_inform: document.getElementById('hs_cfg_date_inform').checked,
obs: document.getElementById('hs_cfg_date_obs').value
},
notfound: {
enabled: document.getElementById('hs_cfg_notfound_enabled').checked,
status: document.getElementById('hs_cfg_notfound_status').value,
days_next: parseInt(document.getElementById('hs_cfg_notfound_days').value) || 0,
check_inform: document.getElementById('hs_cfg_notfound_inform').checked,
obs: document.getElementById('hs_cfg_notfound_obs').value
}
};
@@ -1322,8 +1281,9 @@
const res = await fetch(`${API_URL}/whatsapp/settings`, {
method: 'POST',
headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
body: JSON.stringify(currentSettings)
body: JSON.stringify(payload)
});
if (res.ok) {
showToast("✅ Reglas del Robot guardadas");
} else {
@@ -1331,6 +1291,10 @@
}
} catch(e) {
showToast("❌ Error de conexión", true);
} finally {
// Restauramos el botón
btn.innerHTML = originalHtml;
lucide.createIcons();
}
}