11import type { IRole , IUser , Serialized } from '@rocket.chat/core-typings' ;
22import { Pagination } from '@rocket.chat/fuselage' ;
33import { useEffectEvent , useBreakpoints } from '@rocket.chat/fuselage-hooks' ;
4- import type { PaginatedResult , DefaultUserInfo } from '@rocket.chat/rest-typings' ;
4+ import type { DefaultUserInfo } from '@rocket.chat/rest-typings' ;
55import type { TranslationKey } from '@rocket.chat/ui-contexts' ;
66import { useRouter } from '@rocket.chat/ui-contexts' ;
7- import type { UseQueryResult } from '@tanstack/react-query' ;
87import type { ReactElement , Dispatch , SetStateAction , MouseEvent , KeyboardEvent } from 'react' ;
98import { useMemo } from 'react' ;
109import { useTranslation } from 'react-i18next' ;
@@ -27,16 +26,24 @@ import { useVoipExtensionPermission } from '../voip/hooks/useVoipExtensionPermis
2726type UsersTableProps = {
2827 tab : AdminUsersTab ;
2928 roleData : { roles : IRole [ ] } | undefined ;
29+ users : Serialized < DefaultUserInfo > [ ] ;
30+ total : number ;
31+ isLoading : boolean ;
32+ isError : boolean ;
33+ isSuccess : boolean ;
3034 onReload : ( ) => void ;
3135 setUserFilters : Dispatch < SetStateAction < UsersFilters > > ;
32- filteredUsersQueryResult : UseQueryResult < PaginatedResult < { users : Serialized < DefaultUserInfo > [ ] } > > ;
3336 paginationData : ReturnType < typeof usePagination > ;
3437 sortData : ReturnType < typeof useSort < UsersTableSortingOption > > ;
3538 isSeatsCapExceeded : boolean ;
3639} ;
3740
3841const UsersTable = ( {
39- filteredUsersQueryResult,
42+ users,
43+ total,
44+ isLoading,
45+ isError,
46+ isSuccess,
4047 setUserFilters,
4148 roleData,
4249 tab,
@@ -52,11 +59,6 @@ const UsersTable = ({
5259 const isMobile = ! breakpoints . includes ( 'xl' ) ;
5360 const isLaptop = ! breakpoints . includes ( 'xxl' ) ;
5461
55- const { data, isLoading, isError, isSuccess } = filteredUsersQueryResult ;
56-
57- const { current, itemsPerPage, setItemsPerPage, setCurrent, ...paginationProps } = paginationData ;
58- const { sortBy, sortDirection, setSort } = sortData ;
59-
6062 const canManageVoipExtension = useVoipExtensionPermission ( ) ;
6163
6264 const isKeyboardEvent = ( event : MouseEvent < HTMLElement > | KeyboardEvent < HTMLElement > ) : event is KeyboardEvent < HTMLElement > => {
@@ -83,49 +85,75 @@ const UsersTable = ({
8385
8486 const headers = useMemo (
8587 ( ) => [
86- < GenericTableHeaderCell key = 'name' direction = { sortDirection } active = { sortBy === 'name' } onClick = { setSort } sort = 'name' >
88+ < GenericTableHeaderCell
89+ key = 'name'
90+ direction = { sortData ?. sortDirection }
91+ active = { sortData ?. sortBy === 'name' }
92+ onClick = { sortData ?. setSort }
93+ sort = 'name'
94+ >
8795 { t ( 'Name' ) }
8896 </ GenericTableHeaderCell > ,
89- < GenericTableHeaderCell key = 'username' direction = { sortDirection } active = { sortBy === 'username' } onClick = { setSort } sort = 'username' >
97+ < GenericTableHeaderCell
98+ key = 'username'
99+ direction = { sortData ?. sortDirection }
100+ active = { sortData ?. sortBy === 'username' }
101+ onClick = { sortData ?. setSort }
102+ sort = 'username'
103+ >
90104 { t ( 'Username' ) }
91105 </ GenericTableHeaderCell > ,
92106 ! isLaptop && (
93107 < GenericTableHeaderCell
94108 key = 'email'
95- direction = { sortDirection }
96- active = { sortBy === 'emails.address' }
97- onClick = { setSort }
109+ direction = { sortData ?. sortDirection }
110+ active = { sortData ?. sortBy === 'emails.address' }
111+ onClick = { sortData ?. setSort }
98112 sort = 'emails.address'
99113 >
100114 { t ( 'Email' ) }
101115 </ GenericTableHeaderCell >
102116 ) ,
103117 ! isLaptop && < GenericTableHeaderCell key = 'roles' > { t ( 'Roles' ) } </ GenericTableHeaderCell > ,
104118 tab === 'all' && ! isMobile && (
105- < GenericTableHeaderCell key = 'status' direction = { sortDirection } active = { sortBy === 'status' } onClick = { setSort } sort = 'status' >
119+ < GenericTableHeaderCell
120+ key = 'status'
121+ direction = { sortData ?. sortDirection }
122+ active = { sortData ?. sortBy === 'status' }
123+ onClick = { sortData ?. setSort }
124+ sort = 'status'
125+ >
106126 { t ( 'Registration_status' ) }
107127 </ GenericTableHeaderCell >
108128 ) ,
109129 tab === 'pending' && ! isMobile && (
110- < GenericTableHeaderCell key = 'action' direction = { sortDirection } active = { sortBy === 'active' } onClick = { setSort } sort = 'active' >
130+ < GenericTableHeaderCell
131+ key = 'action'
132+ direction = { sortData ?. sortDirection }
133+ active = { sortData ?. sortBy === 'active' }
134+ onClick = { sortData ?. setSort }
135+ sort = 'active'
136+ >
111137 { t ( 'Pending_action' ) }
112138 </ GenericTableHeaderCell >
113139 ) ,
114140 tab === 'all' && canManageVoipExtension && (
115141 < GenericTableHeaderCell
116142 w = 'x180'
117143 key = 'freeSwitchExtension'
118- direction = { sortDirection }
119- active = { sortBy === 'freeSwitchExtension' }
120- onClick = { setSort }
144+ direction = { sortData ?. sortDirection }
145+ active = { sortData ?. sortBy === 'freeSwitchExtension' }
146+ onClick = { sortData ?. setSort }
121147 sort = 'freeSwitchExtension'
122148 >
123149 { t ( 'Voice_call_extension' ) }
124150 </ GenericTableHeaderCell >
125151 ) ,
126- < GenericTableHeaderCell key = 'actions' w = { tab === 'pending' ? 'x204' : 'x50' } /> ,
152+ < GenericTableHeaderCell key = 'actions' w = { tab === 'pending' ? 'x204' : 'x50' } >
153+ { t ( 'Actions' ) }
154+ </ GenericTableHeaderCell > ,
127155 ] ,
128- [ isLaptop , isMobile , setSort , sortBy , sortDirection , t , tab , canManageVoipExtension ] ,
156+ [ sortData , t , isLaptop , tab , isMobile , canManageVoipExtension ] ,
129157 ) ;
130158
131159 return (
@@ -145,7 +173,7 @@ const UsersTable = ({
145173 < GenericNoResults icon = 'warning' title = { t ( 'Something_went_wrong' ) } buttonTitle = { t ( 'Reload_page' ) } buttonAction = { onReload } />
146174 ) }
147175
148- { isSuccess && data . users . length === 0 && (
176+ { isSuccess && users . length === 0 && (
149177 < GenericNoResults
150178 icon = 'user'
151179 title = { t ( 'Users_Table_Generic_No_users' , {
@@ -156,12 +184,12 @@ const UsersTable = ({
156184 />
157185 ) }
158186
159- { isSuccess && ! ! data ?. users && (
187+ { isSuccess && ! ! users && (
160188 < >
161189 < GenericTable >
162190 < GenericTableHeader > { headers } </ GenericTableHeader >
163191 < GenericTableBody >
164- { data . users . map ( ( user ) => (
192+ { users . map ( ( user ) => (
165193 < UsersTableRow
166194 key = { user . _id }
167195 tab = { tab }
@@ -178,12 +206,10 @@ const UsersTable = ({
178206 </ GenericTable >
179207 < Pagination
180208 divider
181- current = { current }
182- itemsPerPage = { itemsPerPage }
183- count = { data . total || 0 }
184- onSetItemsPerPage = { setItemsPerPage }
185- onSetCurrent = { setCurrent }
186- { ...paginationProps }
209+ count = { total }
210+ onSetItemsPerPage = { paginationData ?. setItemsPerPage }
211+ onSetCurrent = { paginationData ?. setCurrent }
212+ { ...paginationData }
187213 />
188214 </ >
189215 ) }
0 commit comments