Skip to content

Commit

Permalink
chore: added mac endpoints and stream
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandernsilva committed Oct 5, 2023
1 parent a4a6fd3 commit d8d53d0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
21 changes: 15 additions & 6 deletions apps/meteor/client/hooks/omnichannel/useIsOverMacLimit.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
// @ts-nocheck
// import { useEndpoint } from '@rocket.chat/ui-contexts';
import { useQuery } from '@tanstack/react-query';
import { useEndpoint, useStream } from '@rocket.chat/ui-contexts';
import { useQuery, useQueryClient } from '@tanstack/react-query';
import { useEffect } from 'react';

export const useIsOverMacLimit = (): boolean => {
const getMacLimit = () => Promise.resolve(true); // useEndpoint('GET', '/v1/livechat/mac'); // TODO: add the correct endpoint
const { data: isOverMacLimit } = useQuery(['omnichannel', '/v1/livechat/mac'], () => getMacLimit());
return isOverMacLimit;
const queryClient = useQueryClient();
const notifyLogged = useStream('notify-logged');
const getMacLimit = useEndpoint('GET', '/v1/omnichannel/mac/check');
const { data: isOverMacLimit } = useQuery(['/v1/omnichannel/mac/check'], () => getMacLimit());

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

return !!isOverMacLimit;
};
13 changes: 7 additions & 6 deletions apps/meteor/client/hooks/omnichannel/useIsRoomActive.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import type { IOmnichannelRoom } from '@rocket.chat/core-typings';
import type { IOmnichannelGenericRoom } from '@rocket.chat/core-typings';
import { useMemo } from 'react';

export const useIsRoomActive = (room: IOmnichannelRoom) => {
// @ts-ignore
const { activity = [] } = room.v; // TODO: add activity to IOmnichannelRoom['v']
const getPeriod = (date: Date) => `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}`;

export const useIsRoomActive = (room: IOmnichannelGenericRoom) => {
const { activity = [] } = room.v;

const isContactActive = useMemo(() => {
const date = new Date();
const currentPeriod = `${date.getFullYear()}-${date.getMonth() + 1}`;
const currentPeriod = getPeriod(new Date());
return activity.includes(currentPeriod);
}, [activity]);

Expand Down

0 comments on commit d8d53d0

Please sign in to comment.