Skip to content

#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere

843 B
Raw Blame
import { useQuery } from "@tanstack/react-query";
import { qk } from "@processor/queries/keys";
import { toAsyncState } from "@processor/queries/adapters";
import type { AsyncState } from "@processor/hooks/useAsync";
import { usersBackend } from "@editor/portal/usersBackend";
import type { UsersResponse } from "@processor/api/users";
import type { Tier } from "@processor/contexts/TierContext";

/**
 * Base query: the org roster (flavor-resolved via usersBackend). Keyed the same
 * as the Users view's roster query (qk.usersRoster), so callers share one cache
 * entry — the roster is fetched once across all of them.
 */
export function useUsersRoster(tier: Tier): AsyncState<UsersResponse> {
  return toAsyncState(
    useQuery({
      queryKey: qk.usersRoster(tier),
      queryFn: () => usersBackend.fetchUsers(tier),
    }),
  );
}