Actualizar servicios.html

This commit is contained in:
2026-03-04 15:13:55 +00:00
parent 7e5e82980f
commit a3cbf0c74a

View File

@@ -1004,14 +1004,14 @@
}
async function copyClientPortalLink() {
const phone = document.getElementById('detPhone').innerText;
const name = document.getElementById('detName').innerText;
const addr = document.getElementById('detAddrText').innerText;
// CORRECCIÓN: Leemos los datos desde los inputs usando .value
const phone = document.getElementById('editPhone').value;
const name = document.getElementById('editName').value;
const addr = document.getElementById('editAddr').value;
// ¡ESTA ES LA LÍNEA CLAVE QUE FALTABA! Capturamos el ID del servicio
const serviceId = document.getElementById('detId').value;
if (!phone || phone === "Sin Teléfono") {
if (!phone || phone === "Sin Teléfono" || phone.trim() === "") {
showToast("No hay un teléfono válido para este cliente.", "warning");
return;
}
@@ -1023,28 +1023,36 @@
lucide.createIcons();
try {
// Limpiamos el teléfono de espacios para evitar fallos
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, service_id: serviceId })
});
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}`;
// Doble seguro para copiar (el navegador a veces bloquea navigator.clipboard si no hay HTTPS o permiso explícito)
try {
await navigator.clipboard.writeText(portalLink);
showToast("✅ Enlace copiado al portapapeles.");
} catch (err) {
prompt("Tu navegador bloqueó el copiado automático. Cópialo desde aquí:", portalLink);
showToast("Enlace generado con éxito.");
}
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!");
setTimeout(() => {
btn.innerHTML = originalHtml;