Update conversations.php

This commit is contained in:
Lizandro Guarnizo
2026-01-23 23:02:09 -05:00
parent 49f4faf45b
commit f8e3ae73c1
+19 -29
View File
@@ -553,7 +553,7 @@
<i class="fas fa-user"></i>
</div>
<div class="chat-header-info">
<h6 id="chat-name">Usuario <button class="btn btn-sm btn-link" id="edit-user-btn" title="Editar usuario"><i class="fas fa-user-edit"></i></button>
<h6 id="chat-name"><span id="chat-name-text">Usuario</span> <button class="btn btn-sm btn-link" id="edit-user-btn" title="Editar usuario"><i class="fas fa-user-edit"></i></button>
<span id="hold-indicator" style="display:none; margin-left:8px; color:#b85; font-weight:600">EN ESPERA</span>
</h6>
<small id="chat-phone">+1234567890</small>
@@ -1099,7 +1099,8 @@
document.getElementById('chat-area').style.display = 'flex';
// Actualizar header
document.getElementById('chat-name').textContent = userName;
const nameEl = document.getElementById('chat-name-text') || document.getElementById('chat-name');
nameEl.textContent = userName;
document.getElementById('chat-phone').textContent = phoneNumber;
document.getElementById('chat-avatar').textContent = this.getInitials(userName);
@@ -1658,6 +1659,14 @@
}
}
async sendQuickReply(text) {
if (!text) return;
const input = document.getElementById('message-input');
if (!input) return;
input.value = text;
await this.sendMessage();
}
scrollToBottom() {
const container = document.getElementById('chat-conversations');
container.scrollTop = container.scrollHeight;
@@ -1732,31 +1741,12 @@
}
}
async loadQuickReplies() {
try {
const resp = await fetch('api/get_templates.php?approved_only=1&limit=10');
const json = await resp.json();
const container = document.getElementById('quick-replies');
if (!container) return;
container.innerHTML = '';
if (json && json.success && Array.isArray(json.data)) {
const templates = json.data.slice(0,5);
templates.forEach(t => {
const text = (t.body_text || t.name || t.template_name || '').replace(/\n/g,' ');
const btn = document.createElement('button');
btn.className = 'btn btn-sm btn-outline-secondary';
btn.dataset.qr = text;
btn.textContent = text.length > 30 ? text.substring(0,30) + '...' : text;
container.appendChild(btn);
});
}
} catch (err) {
console.error('loadQuickReplies error', err);
}
}
// loadQuickReplies is implemented earlier (combined autoresponses & templates)
// kept here as a no-op to avoid accidentally overriding the real implementation.
async promptEditUser() {
const currentName = document.getElementById('chat-name').textContent || '';
const nameEl = document.getElementById('chat-name-text') || document.getElementById('chat-name');
const currentName = nameEl ? nameEl.textContent.trim() : '';
const newName = prompt('Nombre del usuario:', currentName);
if (!newName) return;
@@ -1768,15 +1758,15 @@
});
const json = await resp.json();
if (json && json.success) {
document.getElementById('chat-name').textContent = newName;
this.showSuccess('Usuario actualizado');
if (nameEl) nameEl.textContent = newName;
this.showSuccess && this.showSuccess('Usuario actualizado');
this.loadConversations();
} else {
this.showError('No se pudo actualizar usuario');
this.showError && this.showError('No se pudo actualizar usuario');
}
} catch (err) {
console.error(err);
this.showError('Error actualizando usuario');
this.showError && this.showError('Error actualizando usuario');
}
}