4
4
useQueryClient ,
5
5
} from '@tanstack/react-query'
6
6
import {
7
- useQueryClient as useQueryClientV5 ,
8
7
useSuspenseQuery as useSuspenseQueryV5 ,
8
+ useInfiniteQuery as useInfiniteQueryV5 ,
9
+ useQueryClient as useQueryClientV5 ,
9
10
} from '@tanstack/react-queryV5'
10
11
import {
11
12
createColumnHelper ,
@@ -19,9 +20,13 @@ import { useInView } from 'react-intersection-observer'
19
20
import { useParams } from 'react-router'
20
21
21
22
import { useLocationParams } from 'services/navigation'
22
- import { UserListOwner , useSelfHostedUserList } from 'services/selfHosted'
23
23
import { SelfHostedSettingsQueryOpts } from 'services/selfHosted/SelfHostedSettingsQueryOpts'
24
+ import {
25
+ SelfHostedUserListQueryOpts ,
26
+ UserListOwner ,
27
+ } from 'services/selfHosted/SelfHostedUserListQueryOpts'
24
28
import Api from 'shared/api'
29
+ import { Provider } from 'shared/api/helpers'
25
30
import Spinner from 'ui/Spinner'
26
31
import Toggle from 'ui/Toggle'
27
32
@@ -59,11 +64,6 @@ const columns = [
59
64
} ) ,
60
65
]
61
66
62
- interface MutationArgs {
63
- activated : boolean
64
- ownerid : number
65
- }
66
-
67
67
interface CreateTableArgs {
68
68
tableData : UserListOwner [ ]
69
69
seatData : SelfHostedSettings
@@ -96,6 +96,35 @@ const createTable = ({ tableData, seatData, mutate }: CreateTableArgs) => {
96
96
)
97
97
}
98
98
99
+ interface Params {
100
+ activated ?: boolean
101
+ search ?: string
102
+ isAdmin ?: boolean
103
+ }
104
+
105
+ const useQueryMembersList = ( params : Params ) => {
106
+ const {
107
+ data : queryData ,
108
+ isFetchingNextPage,
109
+ hasNextPage,
110
+ fetchNextPage,
111
+ isLoading,
112
+ } = useInfiniteQueryV5 ( SelfHostedUserListQueryOpts ( params ) )
113
+
114
+ const flatUsersList = useMemo (
115
+ ( ) => queryData ?. pages ?. flatMap ( ( page ) => page . results ) ?? [ ] ,
116
+ [ queryData ?. pages ]
117
+ )
118
+
119
+ return {
120
+ data : flatUsersList ,
121
+ isFetchingNextPage,
122
+ hasNextPage,
123
+ fetchNextPage,
124
+ isLoading,
125
+ }
126
+ }
127
+
99
128
const Loader = ( ) => (
100
129
< div className = "mb-4 flex justify-center pt-4" >
101
130
< Spinner />
@@ -118,7 +147,12 @@ function LoadMoreTrigger({
118
147
}
119
148
120
149
interface URLParams {
121
- provider : string
150
+ provider : Provider
151
+ }
152
+
153
+ interface MutationArgs {
154
+ activated : boolean
155
+ ownerid : number
122
156
}
123
157
124
158
function MemberTable ( ) {
@@ -136,7 +170,7 @@ function MemberTable() {
136
170
} )
137
171
138
172
const { data, isFetchingNextPage, hasNextPage, fetchNextPage, isLoading } =
139
- useSelfHostedUserList ( params )
173
+ useQueryMembersList ( params )
140
174
141
175
const { mutate } = useMutation ( {
142
176
mutationFn : ( { activated, ownerid } : MutationArgs ) =>
@@ -147,7 +181,9 @@ function MemberTable() {
147
181
queryKey : SelfHostedSettingsQueryOpts ( { provider } ) . queryKey ,
148
182
} )
149
183
queryClient . invalidateQueries ( [ 'Seats' ] )
150
- queryClient . invalidateQueries ( [ 'SelfHostedUserList' ] )
184
+ queryClientV5 . invalidateQueries ( {
185
+ queryKey : SelfHostedUserListQueryOpts ( params ) . queryKey ,
186
+ } )
151
187
} ,
152
188
} )
153
189
0 commit comments