Actualizar index.html

This commit is contained in:
2026-03-04 15:18:11 +00:00
parent 1c9b9efe14
commit 5c801e6a1f

View File

@@ -77,10 +77,11 @@
let urlToken = ""; let urlToken = "";
let etasToInit = []; let etasToInit = [];
document.addEventListener("DOMContentLoaded", async () => { document.addEventListener("DOMContentLoaded", async () => {
lucide.createIcons(); lucide.createIcons();
const urlParams = new URLSearchParams(window.location.search); const urlParams = new URLSearchParams(window.location.search);
urlToken = urlParams.get('token'); urlToken = urlParams.get('token');
const serviceParam = urlParams.get('service'); // Por si viene el ID del servicio
if (!urlToken) { if (!urlToken) {
showError(); showError();
@@ -88,11 +89,23 @@
} }
try { try {
const res = await fetch(`${API_URL}/public/portal/${urlToken}`); // Le pasamos el token y opcionalmente el ID del servicio si viene en la URL
let fetchUrl = `${API_URL}/public/portal/${urlToken}`;
if (serviceParam) {
fetchUrl += `?service=${serviceParam}`;
}
const res = await fetch(fetchUrl);
const data = await res.json(); const data = await res.json();
if (!data.ok) throw new Error("Token inválido"); if (!data.ok) throw new Error("Token inválido");
renderPortal(data.client, data.company, data.services);
// Si no hay servicios, no mostramos error, mostramos el portal vacío
const servicesList = data.services || [];
renderPortal(data.client, data.company, servicesList);
} catch (e) { } catch (e) {
console.error("Error cargando portal:", e);
showError(); showError();
} }
}); });