From 5b741499874cedf58747f3b503cb3fb52754a879 Mon Sep 17 00:00:00 2001 From: rique223 Date: Fri, 22 Mar 2024 18:42:25 -0300 Subject: [PATCH] Typecheck --- .../views/admin/users/AdminUsersPage.tsx | 2 ++ .../admin/users/hooks/useFilteredUsers.ts | 31 +++++++++++++------ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/apps/meteor/client/views/admin/users/AdminUsersPage.tsx b/apps/meteor/client/views/admin/users/AdminUsersPage.tsx index 9fb1dac73408..98aed050cd81 100644 --- a/apps/meteor/client/views/admin/users/AdminUsersPage.tsx +++ b/apps/meteor/client/views/admin/users/AdminUsersPage.tsx @@ -30,6 +30,8 @@ export type UsersFilters = { text: string; }; +export type UsersTableSortingOptions = 'name' | 'username' | 'emails.address' | 'status' | 'active'; + const AdminUsersPage = (): ReactElement => { const t = useTranslation(); diff --git a/apps/meteor/client/views/admin/users/hooks/useFilteredUsers.ts b/apps/meteor/client/views/admin/users/hooks/useFilteredUsers.ts index a4ccf2f38f20..f8ea02a34d82 100644 --- a/apps/meteor/client/views/admin/users/hooks/useFilteredUsers.ts +++ b/apps/meteor/client/views/admin/users/hooks/useFilteredUsers.ts @@ -1,4 +1,5 @@ import type { IAdminUserTabs } from '@rocket.chat/core-typings'; +import type { UsersListStatusParamsGET } from '@rocket.chat/rest-typings'; import { useEndpoint, useToastMessageDispatch } from '@rocket.chat/ui-contexts'; import { useQuery } from '@tanstack/react-query'; import type { MutableRefObject } from 'react'; @@ -6,16 +7,17 @@ import { useMemo } from 'react'; import type { usePagination } from '../../../../components/GenericTable/hooks/usePagination'; import type { useSort } from '../../../../components/GenericTable/hooks/useSort'; +import type { UsersTableSortingOptions } from '../AdminUsersPage'; -type useFilteredUsersOptions = { +type UseFilteredUsersOptions = { searchTerm: string; prevSearchTerm: MutableRefObject; tab: IAdminUserTabs; paginationData: ReturnType; - sortData: ReturnType>; + sortData: ReturnType>; }; -const useFilteredUsers = ({ searchTerm, prevSearchTerm, sortData, paginationData, tab }: useFilteredUsersOptions) => { +const useFilteredUsers = ({ searchTerm, prevSearchTerm, sortData, paginationData, tab }: UseFilteredUsersOptions) => { const { setCurrent, itemsPerPage, current } = paginationData; const { sortBy, sortDirection } = sortData; @@ -24,26 +26,37 @@ const useFilteredUsers = ({ searchTerm, prevSearchTerm, sortData, paginationData setCurrent(0); } + const listUsersPayload: Partial> = { + all: {}, + pending: { + hasLoggedIn: false, + type: 'user', + }, + active: { + hasLoggedIn: true, + status: 'active', + }, + deactivated: { + hasLoggedIn: true, + status: 'deactivated', + }, + }; + return { - status: tab, + ...listUsersPayload[tab], searchTerm, sort: `{ "${sortBy}": ${sortDirection === 'asc' ? 1 : -1} }`, count: itemsPerPage, offset: searchTerm === prevSearchTerm.current ? current : 0, }; }, [current, itemsPerPage, prevSearchTerm, searchTerm, setCurrent, sortBy, sortDirection, tab]); - const getUsers = useEndpoint('GET', '/v1/users.listByStatus'); - const dispatchToastMessage = useToastMessageDispatch(); - const usersListQueryResult = useQuery(['users.list', payload, tab], async () => getUsers(payload), { onError: (error) => { dispatchToastMessage({ type: 'error', message: error }); }, }); - return usersListQueryResult; }; - export default useFilteredUsers;