File size: 1,090 Bytes
9b906ea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { useQuery } from "@tanstack/react-query";
import { getCloudOrganizationMember } from "#/api/cloud/organization-service.api";
import { useActiveBackend } from "#/contexts/active-backend-context";

/**
 * Resolve a single org member by `userId` on the active cloud backend via
 * `GET /api/organizations/{orgId}/members/{userId}` (currently read for the
 * member's email). Disabled on local backends, where there is no org to look
 * the user up in, and until both the active org and the user id are known.
 */
export function useCloudOrgMember(userId: string | undefined) {
  const { backend, orgId } = useActiveBackend();
  const enabled = backend.kind === "cloud" && !!orgId && !!userId;

  // eslint-disable-next-line @tanstack/query/exhaustive-deps
  return useQuery({
    queryKey: [
      "cloud-org-member",
      backend.id,
      orgId,
      userId,
      backend.connectionRevision ?? 0,
    ],
    queryFn: () => getCloudOrganizationMember(orgId!, userId!, backend),
    enabled,
    staleTime: 1000 * 60 * 5,
    retry: false,
    meta: { disableToast: true },
  });
}