Refactor useOAuthGrantsQuery to use infinite list

This commit is contained in:
Gildas Garcia committed 2026-10-01 14:10:12 +02:00
1 parent 75d90717a9
commit 7844b22f95
1 file changed
+13 -5
@@ -1,9 +1,9 @@
import { useQuery } from '@tanstack/react-query'
import { InfiniteData, useInfiniteQuery } from '@tanstack/react-query'
import { oauthAppsKeys } from './keys'
import { getMockOAuthOwnGrants, USE_MOCKS } from './mocks'
import type { ListOwnGrantsResponse } from './types'
import type { ResponseError, UseCustomQueryOptions } from '@/types'
import type { ResponseError, UseCustomInfiniteQueryOptions } from '@/types'
export type OAuthGrantsVariables = {
cursor?: string
@@ -27,11 +27,19 @@ export const useOAuthGrantsQuery = <TData = OAuthGrantsData>(
{
enabled = true,
...options
}: UseCustomQueryOptions<OAuthGrantsData, OAuthGrantsError, TData> = {}
}: UseCustomInfiniteQueryOptions<
OAuthGrantsData,
OAuthGrantsError,
InfiniteData<TData>,
readonly unknown[],
string | undefined
> = {}
) =>
useQuery<OAuthGrantsData, OAuthGrantsError, TData>({
useInfiniteQuery({
queryKey: oauthAppsKeys.grants(cursor),
queryFn: () => getOAuthGrants({ cursor }),
queryFn: ({ pageParam }) => getOAuthGrants({ cursor: pageParam }),
initialPageParam: cursor,
getNextPageParam: (lastPage) => lastPage.pagination.next_cursor,
enabled: enabled && USE_MOCKS,
...options,
})