-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: incomplete validation on useIsRoomActive
- Loading branch information
1 parent
983a8e4
commit a56f12a
Showing
3 changed files
with
13 additions
and
13 deletions.
There are no files selected for viewing
13 changes: 2 additions & 11 deletions
13
apps/meteor/client/hooks/omnichannel/useIsOverMacLimit.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,9 @@ | ||
import { useEndpoint, useStream } from '@rocket.chat/ui-contexts'; | ||
import { useQuery, useQueryClient } from '@tanstack/react-query'; | ||
import { useEffect } from 'react'; | ||
import { useEndpoint } from '@rocket.chat/ui-contexts'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
export const useIsOverMacLimit = (): boolean => { | ||
const queryClient = useQueryClient(); | ||
const notifyLogged = useStream('notify-logged'); | ||
const getMacLimit = useEndpoint('GET', '/v1/omnichannel/mac/check'); | ||
const { data: { onLimit: isOverMacLimit = false } = {} } = useQuery(['/v1/omnichannel/mac/check'], () => getMacLimit()); | ||
|
||
useEffect(() => { | ||
return notifyLogged(`mac.limit`, ({ limitReached }) => { | ||
limitReached && queryClient.invalidateQueries(['/v1/omnichannel/mac/check']); | ||
}); | ||
}, [notifyLogged, queryClient]); | ||
|
||
return !!isOverMacLimit; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
import type { IOmnichannelGenericRoom } from '@rocket.chat/core-typings'; | ||
import { useMemo } from 'react'; | ||
|
||
import { useIsOverMacLimit } from './useIsOverMacLimit'; | ||
|
||
const getPeriod = (date: Date) => `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}`; | ||
|
||
export const useIsRoomActive = (room: IOmnichannelGenericRoom) => { | ||
const isOverMacLimit = useIsOverMacLimit(); | ||
const { activity = [] } = room.v; | ||
|
||
const isContactActive = useMemo(() => { | ||
const currentPeriod = getPeriod(new Date()); | ||
return activity.includes(currentPeriod); | ||
}, [activity]); | ||
return !isOverMacLimit || activity.includes(currentPeriod); | ||
}, [activity, isOverMacLimit]); | ||
|
||
return isContactActive; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters