Skip to content

Commit

Permalink
feat: only check mac limits when omnichannel is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandernsilva committed Oct 10, 2023
1 parent de213a8 commit 61c3f9a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 4 additions & 1 deletion apps/meteor/client/hooks/omnichannel/useIsOverMacLimit.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { useEndpoint } from '@rocket.chat/ui-contexts';
import { useQuery } from '@tanstack/react-query';

import { useOmnichannelEnabled } from './useOmnichannelEnabled';

export const useIsOverMacLimit = (): boolean => {
const isOmnichannelEnabled = useOmnichannelEnabled();
const getMacLimit = useEndpoint('GET', '/v1/omnichannel/mac/check');
const { data: { onLimit = true } = {} } = useQuery(['/v1/omnichannel/mac/check'], () => getMacLimit());
const { data: { onLimit = true } = {} } = useQuery(['/v1/omnichannel/mac/check'], () => getMacLimit(), { enabled: isOmnichannelEnabled });

return onLimit;
};
8 changes: 6 additions & 2 deletions apps/meteor/client/providers/OmnichannelProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const OmnichannelProvider: FC = ({ children }) => {
const subscribe = useStream('notify-logged');
const queryClient = useQueryClient();
const isPrioritiesEnabled = isEnterprise && accessible;
const enabled = accessible && !!user && !!routeConfig;

const {
data: { priorities = [] } = {},
Expand All @@ -84,10 +85,14 @@ const OmnichannelProvider: FC = ({ children }) => {
}, [isPrioritiesEnabled, queryClient, subscribe]);

useEffect(() => {
if (!enabled) {
return;
}

return subscribe(`mac.limit`, ({ limitReached }) => {
limitReached && queryClient.invalidateQueries(['/v1/omnichannel/mac/check']);
});
}, [subscribe, queryClient]);
}, [subscribe, queryClient, enabled]);

useEffect(() => {
if (!accessible) {
Expand All @@ -108,7 +113,6 @@ const OmnichannelProvider: FC = ({ children }) => {
}
}, [accessible, getRoutingConfig, iceServersSetting, omnichannelRouting, setRouteConfig, voipCallAvailable]);

const enabled = accessible && !!user && !!routeConfig;
const manuallySelected =
enabled && canViewOmnichannelQueue && !!routeConfig && routeConfig.showQueue && !routeConfig.autoAssignAgent && agentAvailable;

Expand Down

0 comments on commit 61c3f9a

Please sign in to comment.