diff --git a/apps/meteor/client/views/admin/users/AdminUsersPage.tsx b/apps/meteor/client/views/admin/users/AdminUsersPage.tsx index f0f6fa6b4b24..59fd4c349638 100644 --- a/apps/meteor/client/views/admin/users/AdminUsersPage.tsx +++ b/apps/meteor/client/views/admin/users/AdminUsersPage.tsx @@ -1,7 +1,7 @@ import { Button, ButtonGroup, Tabs } from '@rocket.chat/fuselage'; import { usePermission, useRouteParameter, useTranslation, useRouter } from '@rocket.chat/ui-contexts'; import type { ReactElement } from 'react'; -import React, { useCallback, useEffect, useRef, useState } from 'react'; +import React, { useEffect, useRef, useState } from 'react'; import UserPageHeaderContentWithSeatsCap from '../../../../ee/client/views/admin/users/UserPageHeaderContentWithSeatsCap'; import { useSeatsCap } from '../../../../ee/client/views/admin/users/useSeatsCap'; @@ -12,7 +12,6 @@ import AdminUserForm from './AdminUserForm'; import AdminUserFormWithData from './AdminUserFormWithData'; import AdminUserInfoWithData from './AdminUserInfoWithData'; import UsersTable from './UsersTable'; -import { usePendingUsersStats } from './usePendingUsersStats'; const UsersPage = async (): Promise => { const t = useTranslation(); @@ -28,6 +27,8 @@ const UsersPage = async (): Promise => { const [tab, setTab] = useState<'all' | 'invited' | 'pending' | 'active' | 'deactivated'>('all'); + const [pendingActionsCount, setPendingActionsCount] = useState(0); + useEffect(() => { if (!context || !seatsCap) { return; @@ -43,19 +44,6 @@ const UsersPage = async (): Promise => { reload.current(); }; - const [pendingActionsCount, setPendingActionsCount] = useState(0); - - useCallback(() => { - const usePending = async () => { - const users = await usePendingUsersStats(); - return users?.length; - }; - }, []); - - useEffect(() => { - setPendingActionsCount(pending); - }, [pending]); - return ( @@ -95,7 +83,7 @@ const UsersPage = async (): Promise => { {t('Invited')} - + {context && ( diff --git a/apps/meteor/client/views/admin/users/UsersTable/UsersTable.tsx b/apps/meteor/client/views/admin/users/UsersTable/UsersTable.tsx index 0f1db25aef79..75b39b04896b 100644 --- a/apps/meteor/client/views/admin/users/UsersTable/UsersTable.tsx +++ b/apps/meteor/client/views/admin/users/UsersTable/UsersTable.tsx @@ -24,9 +24,10 @@ type UsersTableProps = { reload: MutableRefObject<() => void>; tab: string; onReload: () => void; + setPendingActionsCount: React.Dispatch>; }; -const UsersTable = ({ reload, tab, onReload }: UsersTableProps): ReactElement | null => { +const UsersTable = ({ reload, tab, onReload, setPendingActionsCount }: UsersTableProps): ReactElement | null => { const t = useTranslation(); const router = useRouter(); const mediaQuery = useMediaQuery('(min-width: 1024px)'); @@ -47,11 +48,13 @@ const UsersTable = ({ reload, tab, onReload }: UsersTableProps): ReactElement | sortDirection, itemsPerPage, current, + setPendingActionsCount, ); const useAllUsers = () => (tab === 'all' && isSuccess ? data?.users : []); - const filteredUsers = [...useAllUsers(), ...useFilterActiveUsers(data?.users, tab), ...useFilterPendingUsers(data?.users, tab)]; + // TODO: fix types + const filteredUsers = [...useAllUsers(), ...useFilterActiveUsers(data?.users, tab), ...useFilterPendingUsers(data?.users as any, tab)]; useEffect(() => { reload.current = refetch; diff --git a/apps/meteor/client/views/admin/users/hooks/useFilterActiveUsers.ts b/apps/meteor/client/views/admin/users/hooks/useFilterActiveUsers.ts index 762042638353..a8dd6acfa3b7 100644 --- a/apps/meteor/client/views/admin/users/hooks/useFilterActiveUsers.ts +++ b/apps/meteor/client/views/admin/users/hooks/useFilterActiveUsers.ts @@ -1,7 +1,7 @@ import type { IUser } from '@rocket.chat/core-typings'; export const useFilterActiveUsers = ( - users: Pick[] | undefined, + users: Pick[] | undefined, tab: string, ) => { if (!users || tab !== 'active') return []; diff --git a/apps/meteor/client/views/admin/users/hooks/useListUsers.ts b/apps/meteor/client/views/admin/users/hooks/useListUsers.ts index 57b263f2f360..4be9009f2adf 100644 --- a/apps/meteor/client/views/admin/users/hooks/useListUsers.ts +++ b/apps/meteor/client/views/admin/users/hooks/useListUsers.ts @@ -16,6 +16,7 @@ export const useListUsers = ( sortDirection: ReturnType['sortDirection'], itemsPerPage: ReturnType['itemsPerPage'], current: ReturnType['current'], + setPendingActionsCount: React.Dispatch>, ) => { const query = useDebouncedValue( useMemo(() => { @@ -65,5 +66,9 @@ export const useListUsers = ( }, ); + if (usersListQueryResult.isSuccess) { + setPendingActionsCount(usersListQueryResult.data.users.filter((user) => !user.active).length); + } + return usersListQueryResult; }; diff --git a/apps/meteor/client/views/admin/users/usePendingUsersStats.ts b/apps/meteor/client/views/admin/users/usePendingUsersStats.ts deleted file mode 100644 index f3f7a537f8bb..000000000000 --- a/apps/meteor/client/views/admin/users/usePendingUsersStats.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { useEndpoint, useToastMessageDispatch } from '@rocket.chat/ui-contexts'; - -export const usePendingUsersStats = async () => { - const getUsers = useEndpoint('GET', '/v1/users.list'); - const dispatchToastMessage = useToastMessageDispatch(); - - const fields = JSON.stringify({ - name: 1, - username: 1, - status: 1, - active: 1, - lastLogin: 1, - }); - - try { - const data = await getUsers({ fields }); - - // TODO: fix currentUser type! - return data.users.filter((currentUser: any) => currentUser.active === false || !currentUser.lastLogin); - } catch (error) { - dispatchToastMessage({ type: 'error', message: error }); - } -}; diff --git a/packages/rest-typings/src/v1/users.ts b/packages/rest-typings/src/v1/users.ts index e01c5880ad23..c47f4be6404d 100644 --- a/packages/rest-typings/src/v1/users.ts +++ b/packages/rest-typings/src/v1/users.ts @@ -147,7 +147,7 @@ export type UsersEndpoints = { '/v1/users.list': { GET: (params: PaginatedRequest<{ fields: string }>) => PaginatedResult<{ - users: Pick[]; + users: Pick[]; }>; };