Actualizar servicios.html
This commit is contained in:
@@ -1003,51 +1003,42 @@
|
|||||||
if(data.ok) sel.innerHTML = '<option value="">Seleccionar operario...</option>' + data.operators.map(o => `<option value="${o.id}">${o.full_name}</option>`).join('');
|
if(data.ok) sel.innerHTML = '<option value="">Seleccionar operario...</option>' + data.operators.map(o => `<option value="${o.id}">${o.full_name}</option>`).join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- SOLUCIÓN PARA COPIAR PORTAL ANTI-BLOQUEO HTTP ---
|
|
||||||
async function copyClientPortalLink() {
|
async function copyClientPortalLink() {
|
||||||
const phoneEl = document.getElementById('editPhone');
|
const phone = document.getElementById('detPhone').innerText;
|
||||||
const nameEl = document.getElementById('editName');
|
const name = document.getElementById('detName').innerText;
|
||||||
const addrEl = document.getElementById('editAddr');
|
const addr = document.getElementById('detAddrText').innerText;
|
||||||
|
|
||||||
const phone = phoneEl ? phoneEl.value : "";
|
// ¡ESTA ES LA LÍNEA CLAVE QUE FALTABA! Capturamos el ID del servicio
|
||||||
const name = nameEl ? nameEl.value : "";
|
|
||||||
const addr = addrEl ? addrEl.value : "";
|
|
||||||
const serviceId = document.getElementById('detId').value;
|
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");
|
showToast("No hay un teléfono válido para este cliente.", "warning");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const btn = document.getElementById('btnPortalLink');
|
const btn = document.getElementById('btnPortalLink');
|
||||||
const originalHtml = btn.innerHTML;
|
const originalHtml = btn.innerHTML;
|
||||||
|
|
||||||
btn.innerHTML = '<i data-lucide="loader-2" class="w-3 h-3 animate-spin"></i> Generando...';
|
btn.innerHTML = '<i data-lucide="loader-2" class="w-3 h-3 animate-spin"></i> Generando...';
|
||||||
lucide.createIcons();
|
lucide.createIcons();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${API_URL}/clients/ensure`, {
|
const res = await fetch(`${API_URL}/clients/ensure`, {
|
||||||
method: 'POST',
|
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 })
|
body: JSON.stringify({ phone: phone, name: name, address: addr })
|
||||||
});
|
});
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
|
|
||||||
if (data.ok && data.client && data.client.portal_token) {
|
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}`;
|
const portalLink = `https://portal.integrarepara.es/?token=${data.client.portal_token}&service=${serviceId}`;
|
||||||
|
|
||||||
if (navigator.clipboard && window.isSecureContext) {
|
|
||||||
await navigator.clipboard.writeText(portalLink);
|
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
btn.innerHTML = '<i data-lucide="check-circle" class="w-3 h-3"></i> ¡Copiado!';
|
btn.innerHTML = '<i data-lucide="check-circle" class="w-3 h-3"></i> ¡Copiado!';
|
||||||
btn.classList.replace('text-blue-600', 'text-emerald-600');
|
btn.classList.replace('text-blue-600', 'text-emerald-600');
|
||||||
@@ -1061,13 +1052,12 @@
|
|||||||
lucide.createIcons();
|
lucide.createIcons();
|
||||||
}, 3000);
|
}, 3000);
|
||||||
} else {
|
} else {
|
||||||
showToast("No se pudo generar el token. Revisa la consola.", "warning");
|
showToast("Error al generar el enlace.", "warning");
|
||||||
btn.innerHTML = originalHtml;
|
btn.innerHTML = originalHtml;
|
||||||
lucide.createIcons();
|
lucide.createIcons();
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error obteniendo token:", error);
|
showToast("Error de red al conectar con el servidor", "warning");
|
||||||
showToast("Error al conectar con el servidor", "warning");
|
|
||||||
btn.innerHTML = originalHtml;
|
btn.innerHTML = originalHtml;
|
||||||
lucide.createIcons();
|
lucide.createIcons();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user