Fix: Ajustadado getAcessUsers que estava buscando para qualquer usuário
This commit is contained in:
parent
9ba7d0fb84
commit
a1811712a1
@ -235,6 +235,8 @@ export function useChat() {
|
|||||||
const currentUserId = getUserId(currentUser);
|
const currentUserId = getUserId(currentUser);
|
||||||
const currentUserAreas = getUserAreas(currentUser);
|
const currentUserAreas = getUserAreas(currentUser);
|
||||||
const isAdminUser = currentUserProfile === 'admin';
|
const isAdminUser = currentUserProfile === 'admin';
|
||||||
|
const canListPresence = ['admin', 'supervisor'].includes(currentUserProfile);
|
||||||
|
const canListAccessUsers = currentUserProfile === 'admin';
|
||||||
const { status: whatsappStatus, incomingMessage, clearIncomingMessage } = useWhatsappSocket();
|
const { status: whatsappStatus, incomingMessage, clearIncomingMessage } = useWhatsappSocket();
|
||||||
const [contacts, setContacts] = useState([]);
|
const [contacts, setContacts] = useState([]);
|
||||||
const [activeContactId, setActiveContactId] = useState('');
|
const [activeContactId, setActiveContactId] = useState('');
|
||||||
@ -327,8 +329,8 @@ export function useChat() {
|
|||||||
try {
|
try {
|
||||||
const [options, users, presences, currentPresence] = await Promise.all([
|
const [options, users, presences, currentPresence] = await Promise.all([
|
||||||
getAccessOptions(),
|
getAccessOptions(),
|
||||||
getAccessUsers(),
|
canListAccessUsers ? getAccessUsers() : Promise.resolve([]),
|
||||||
listAgentPresence(),
|
canListPresence ? listAgentPresence() : Promise.resolve([]),
|
||||||
currentUserId ? getAgentPresence(currentUserId) : Promise.resolve(null),
|
currentUserId ? getAgentPresence(currentUserId) : Promise.resolve(null),
|
||||||
]);
|
]);
|
||||||
if (!isMounted) return;
|
if (!isMounted) return;
|
||||||
@ -350,7 +352,7 @@ export function useChat() {
|
|||||||
return () => {
|
return () => {
|
||||||
isMounted = false;
|
isMounted = false;
|
||||||
};
|
};
|
||||||
}, [currentUserId]);
|
}, [canListAccessUsers, canListPresence, currentUserId]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!currentUserId) return undefined;
|
if (!currentUserId) return undefined;
|
||||||
@ -359,7 +361,7 @@ export function useChat() {
|
|||||||
async function refreshPresence() {
|
async function refreshPresence() {
|
||||||
try {
|
try {
|
||||||
const [presences, currentPresence] = await Promise.all([
|
const [presences, currentPresence] = await Promise.all([
|
||||||
listAgentPresence(),
|
canListPresence ? listAgentPresence() : Promise.resolve([]),
|
||||||
getAgentPresence(currentUserId),
|
getAgentPresence(currentUserId),
|
||||||
]);
|
]);
|
||||||
if (!isMounted) return;
|
if (!isMounted) return;
|
||||||
@ -376,7 +378,7 @@ export function useChat() {
|
|||||||
isMounted = false;
|
isMounted = false;
|
||||||
window.clearInterval(intervalId);
|
window.clearInterval(intervalId);
|
||||||
};
|
};
|
||||||
}, [currentUserId]);
|
}, [canListPresence, currentUserId]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isPaused) return undefined;
|
if (!isPaused) return undefined;
|
||||||
@ -723,7 +725,7 @@ export function useChat() {
|
|||||||
setPauseSeconds(0);
|
setPauseSeconds(0);
|
||||||
setApiError(null);
|
setApiError(null);
|
||||||
await loadChats({ showLoading: true, ignorePause: true });
|
await loadChats({ showLoading: true, ignorePause: true });
|
||||||
const presences = await listAgentPresence();
|
const presences = canListPresence ? await listAgentPresence() : [];
|
||||||
setPresenceList(Array.isArray(presences) ? presences : []);
|
setPresenceList(Array.isArray(presences) ? presences : []);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setApiError(error.message);
|
setApiError(error.message);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user