This commit is contained in:
Lizandro Guarnizo
2026-01-21 22:11:12 -05:00
parent 2b92e47624
commit 31dbc8aa86
9 changed files with 158 additions and 4 deletions
+52
View File
@@ -357,6 +357,10 @@ if (empty($user_id)) {
</div>
</div>
<div class="d-flex align-items-center">
<button id="attendBtn" class="btn btn-outline-light btn-sm me-2" onclick="toggleAttend()" title="Atender/Finalizar">
<i class="fas fa-user-check"></i> Atender
</button>
<small id="attendStatus" class="text-white me-3" style="font-size:0.9rem;"></small>
<button class="btn btn-outline-light btn-sm me-2" onclick="refreshChat()">
<i class="fas fa-sync-alt"></i>
</button>
@@ -563,6 +567,9 @@ if (empty($user_id)) {
document.getElementById('userAvatar').innerHTML =
`<span>${(currentUser.name || 'U').charAt(0).toUpperCase()}</span>`;
// Estado de atención
renderAttendControls();
// Cargar mensajes
displayconversations(response.conversations);
@@ -1060,6 +1067,51 @@ if (empty($user_id)) {
wrapper.style.display = (wrapper.style.display === 'block') ? 'none' : 'block';
}
}
// ===== Controles de atención (Atender / Finalizar) =====
function renderAttendControls() {
const btn = document.getElementById('attendBtn');
const status = document.getElementById('attendStatus');
if (!btn || !status || !currentUser) return;
if (currentUser.in_service) {
btn.innerHTML = '<i class="fas fa-user-times"></i> Finalizar';
btn.classList.remove('btn-outline-light');
btn.classList.add('btn-light','text-dark');
status.innerHTML = `Atendido por ${currentUser.in_service_by_name || 'un asesor'}`;
} else {
btn.innerHTML = '<i class="fas fa-user-check"></i> Atender';
btn.classList.remove('btn-light','text-dark');
btn.classList.add('btn-outline-light');
status.innerHTML = '';
}
}
async function toggleAttend() {
if (!currentUser) return;
try {
if (currentUser.in_service) {
const resp = await whatsappManager.apiCall('finish_attend.php', { body: { user_id: userId } });
if (resp && resp.success) {
showAlert('Finalizada la atención', 'success');
await loadUserData();
} else {
throw new Error(resp.error || 'Error finalizando');
}
} else {
const resp = await whatsappManager.apiCall('attend.php', { body: { user_id: userId } });
if (resp && resp.success) {
showAlert('Atención iniciada', 'success');
await loadUserData();
} else {
throw new Error(resp.error || 'Error iniciando atención');
}
}
} catch (err) {
console.error('Error toggling attend:', err);
showAlert('Error al cambiar estado de atención: ' + err.message, 'danger');
}
}
function showError(message) {
showAlert(message, 'danger');