From a1811712a1d01d19d5d86afaa53f73123467807f Mon Sep 17 00:00:00 2001 From: Rafael Lopes Date: Tue, 2 Jun 2026 09:26:11 -0300 Subject: [PATCH] =?UTF-8?q?Fix:=20Ajustadado=20getAcessUsers=20que=20estav?= =?UTF-8?q?a=20buscando=20para=20qualquer=20usu=C3=A1rio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/chat/hooks/useChat.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/modules/chat/hooks/useChat.js b/src/modules/chat/hooks/useChat.js index 575a6c0..6bd3a9f 100644 --- a/src/modules/chat/hooks/useChat.js +++ b/src/modules/chat/hooks/useChat.js @@ -235,6 +235,8 @@ export function useChat() { const currentUserId = getUserId(currentUser); const currentUserAreas = getUserAreas(currentUser); const isAdminUser = currentUserProfile === 'admin'; + const canListPresence = ['admin', 'supervisor'].includes(currentUserProfile); + const canListAccessUsers = currentUserProfile === 'admin'; const { status: whatsappStatus, incomingMessage, clearIncomingMessage } = useWhatsappSocket(); const [contacts, setContacts] = useState([]); const [activeContactId, setActiveContactId] = useState(''); @@ -327,8 +329,8 @@ export function useChat() { try { const [options, users, presences, currentPresence] = await Promise.all([ getAccessOptions(), - getAccessUsers(), - listAgentPresence(), + canListAccessUsers ? getAccessUsers() : Promise.resolve([]), + canListPresence ? listAgentPresence() : Promise.resolve([]), currentUserId ? getAgentPresence(currentUserId) : Promise.resolve(null), ]); if (!isMounted) return; @@ -350,7 +352,7 @@ export function useChat() { return () => { isMounted = false; }; - }, [currentUserId]); + }, [canListAccessUsers, canListPresence, currentUserId]); useEffect(() => { if (!currentUserId) return undefined; @@ -359,7 +361,7 @@ export function useChat() { async function refreshPresence() { try { const [presences, currentPresence] = await Promise.all([ - listAgentPresence(), + canListPresence ? listAgentPresence() : Promise.resolve([]), getAgentPresence(currentUserId), ]); if (!isMounted) return; @@ -376,7 +378,7 @@ export function useChat() { isMounted = false; window.clearInterval(intervalId); }; - }, [currentUserId]); + }, [canListPresence, currentUserId]); useEffect(() => { if (!isPaused) return undefined; @@ -723,7 +725,7 @@ export function useChat() { setPauseSeconds(0); setApiError(null); await loadChats({ showLoading: true, ignorePause: true }); - const presences = await listAgentPresence(); + const presences = canListPresence ? await listAgentPresence() : []; setPresenceList(Array.isArray(presences) ? presences : []); } catch (error) { setApiError(error.message);