fix(ui): add useInfiniteTeams hook needed by team_multi_select

Cherry-pick of team_multi_select.tsx imported useInfiniteTeams which
didn't yet exist on this stable patch branch. Ported the hook from main
(aea8e32048).
This commit is contained in:
Ryan Crabbe 2026-04-04 17:44:40 -07:00
parent 8a3dabb09f
commit cb099ee75c
No known key found for this signature in database

View file

@ -1,4 +1,4 @@
import { keepPreviousData, useQuery, useQueryClient, UseQueryResult } from "@tanstack/react-query";
import { keepPreviousData, useInfiniteQuery, useQuery, useQueryClient, UseQueryResult } from "@tanstack/react-query";
import { Team } from "@/components/key_team_helpers/key_list";
import useAuthorized from "@/app/(dashboard)/hooks/useAuthorized";
import { fetchTeams } from "@/app/(dashboard)/networking";
@ -124,6 +124,43 @@ export const useTeam = (teamId?: string) => {
});
};
const infiniteTeamKeys = createQueryKeys("infiniteTeams");
export const useInfiniteTeams = (
pageSize: number = 50,
search?: string,
organizationId?: string | null,
) => {
const { accessToken, userId, userRole } = useAuthorized();
const isAdmin = userRole === "Admin" || userRole === "Admin Viewer";
return useInfiniteQuery<TeamsResponse>({
queryKey: infiniteTeamKeys.list({
filters: {
pageSize,
...(search && { search }),
...(organizationId && { organizationId }),
...(userId && { userId }),
},
}),
queryFn: async ({ pageParam }) => {
return await teamListCall(accessToken!, pageParam as number, pageSize, {
team_alias: search || undefined,
organizationID: organizationId,
userID: !isAdmin ? userId : undefined,
});
},
initialPageParam: 1,
getNextPageParam: (lastPage) => {
if (lastPage.page < lastPage.total_pages) {
return lastPage.page + 1;
}
return undefined;
},
enabled: Boolean(accessToken),
});
};
const deletedTeamListCall = async (
accessToken: string,
page: number,