Actualizar servicios.html
This commit is contained in:
@@ -999,12 +999,17 @@
|
||||
}
|
||||
|
||||
async function copyClientPortalLink() {
|
||||
const phone = document.getElementById('editPhone').value;
|
||||
const name = document.getElementById('editName').value;
|
||||
const addr = document.getElementById('editAddr').value;
|
||||
// Aseguramos que leemos los datos correctos
|
||||
const phoneInput = document.getElementById('editPhone');
|
||||
const nameInput = document.getElementById('editName');
|
||||
const addrInput = document.getElementById('editAddr');
|
||||
|
||||
if (!phone || phone === "Sin Teléfono") {
|
||||
showToast("No hay un teléfono válido para este cliente.", "warning");
|
||||
const phone = phoneInput ? phoneInput.value : "";
|
||||
const name = nameInput ? nameInput.value : "Cliente";
|
||||
const addr = addrInput ? addrInput.value : "";
|
||||
|
||||
if (!phone || phone.trim() === "" || phone === "Sin Teléfono") {
|
||||
showToast("⚠️ Falta el teléfono para generar el portal", "warning");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1015,25 +1020,36 @@
|
||||
lucide.createIcons();
|
||||
|
||||
try {
|
||||
// Limpiamos el teléfono antes de enviarlo
|
||||
const cleanPhone = phone.replace(/\D/g, "");
|
||||
|
||||
const res = await fetch(`${API_URL}/clients/ensure`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": `Bearer ${localStorage.getItem("token")}`
|
||||
},
|
||||
body: JSON.stringify({ phone: phone, name: name, address: addr })
|
||||
body: JSON.stringify({ phone: cleanPhone, name: name, address: addr })
|
||||
});
|
||||
|
||||
const data = await res.json();
|
||||
|
||||
if (data.ok && data.client && data.client.portal_token) {
|
||||
const portalLink = `https://portal.integrarepara.es/?token=${data.client.portal_token}`;
|
||||
await navigator.clipboard.writeText(portalLink);
|
||||
|
||||
// Copiar al portapapeles
|
||||
try {
|
||||
await navigator.clipboard.writeText(portalLink);
|
||||
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('bg-blue-50', 'bg-emerald-50');
|
||||
btn.classList.replace('border-blue-100', 'border-emerald-200');
|
||||
showToast("Enlace copiado. ¡Listo para pegar en WhatsApp!");
|
||||
showToast("✅ Enlace copiado al portapapeles");
|
||||
} catch (clipErr) {
|
||||
// Plan B si el navegador bloquea el portapapeles automático
|
||||
prompt("Copia este enlace manualmente:", portalLink);
|
||||
btn.innerHTML = '<i data-lucide="check-circle" class="w-3 h-3"></i> Generado';
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
btn.innerHTML = originalHtml;
|
||||
@@ -1041,13 +1057,13 @@
|
||||
lucide.createIcons();
|
||||
}, 3000);
|
||||
} else {
|
||||
showToast("No se pudo generar el token. Revisa la consola.", "warning");
|
||||
showToast("❌ Error al generar el token", "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 conexión", "warning");
|
||||
btn.innerHTML = originalHtml;
|
||||
lucide.createIcons();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user