diff --git a/servicios.html b/servicios.html
index fcc5bbe..8ae5252 100644
--- a/servicios.html
+++ b/servicios.html
@@ -1003,51 +1003,42 @@
if(data.ok) sel.innerHTML = '' + data.operators.map(o => ``).join('');
}
- // --- SOLUCIÓN PARA COPIAR PORTAL ANTI-BLOQUEO HTTP ---
- async function copyClientPortalLink() {
- const phoneEl = document.getElementById('editPhone');
- const nameEl = document.getElementById('editName');
- const addrEl = document.getElementById('editAddr');
+ async function copyClientPortalLink() {
+ const phone = document.getElementById('detPhone').innerText;
+ const name = document.getElementById('detName').innerText;
+ const addr = document.getElementById('detAddrText').innerText;
- const phone = phoneEl ? phoneEl.value : "";
- const name = nameEl ? nameEl.value : "";
- const addr = addrEl ? addrEl.value : "";
+ // ¡ESTA ES LA LÍNEA CLAVE QUE FALTABA! Capturamos el ID del servicio
const serviceId = document.getElementById('detId').value;
- if (!phone || phone.length < 9) {
+ if (!phone || phone === "Sin Teléfono") {
showToast("No hay un teléfono válido para este cliente.", "warning");
return;
}
const btn = document.getElementById('btnPortalLink');
const originalHtml = btn.innerHTML;
+
btn.innerHTML = ' Generando...';
lucide.createIcons();
try {
const res = await fetch(`${API_URL}/clients/ensure`, {
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({ phone: phone, name: name, address: addr })
});
const data = await res.json();
if (data.ok && data.client && data.client.portal_token) {
+
+ // ¡AQUÍ ESTÁ LA MAGIA! Le pegamos el &service= al enlace
const portalLink = `https://portal.integrarepara.es/?token=${data.client.portal_token}&service=${serviceId}`;
- if (navigator.clipboard && window.isSecureContext) {
- await navigator.clipboard.writeText(portalLink);
- } else {
- const textArea = document.createElement("textarea");
- textArea.value = portalLink;
- textArea.style.position = "fixed";
- textArea.style.left = "-999999px";
- document.body.appendChild(textArea);
- textArea.focus();
- textArea.select();
- document.execCommand('copy');
- textArea.remove();
- }
+ await navigator.clipboard.writeText(portalLink);
btn.innerHTML = ' ¡Copiado!';
btn.classList.replace('text-blue-600', 'text-emerald-600');
@@ -1061,13 +1052,12 @@
lucide.createIcons();
}, 3000);
} else {
- showToast("No se pudo generar el token. Revisa la consola.", "warning");
+ showToast("Error al generar el enlace.", "warning");
btn.innerHTML = originalHtml;
lucide.createIcons();
}
} catch (error) {
- console.error("Error obteniendo token:", error);
- showToast("Error al conectar con el servidor", "warning");
+ showToast("Error de red al conectar con el servidor", "warning");
btn.innerHTML = originalHtml;
lucide.createIcons();
}