* refactor: allow non unique PlatformBilling customerId * feat: add PlatformBilling managed organizations fields * feat: ManagedOrganization table * refactor: bill overdue based on teamId * refactor: restructure organizations module * wip: organizations endpoints * Revert "wip: organizations endpoints" This reverts commit 0e9e66fc74f31da436f12930c1b6597c650ed621. * refactor: unique index for managed organizations * wip: organizations endpoints * wip: create managed organization * remove unecessary membership check because we have guard * feat: create managed org * feat: get managed org and orgs * feat: update and delete managed orgs * wip: api key logic * feat: allow variable api key length * feat: refresh managed org api key * feat: create managed org OAuth clients using api key * finish merge main * chore: bump platform libraries * tests: fix and add more tests to api-auth.strategy.e2e * refactor: dont request managed org slug and handle metadata as object * revert: billing service and repository update overdue based on sub and customer ids * refactor: v2 OAuth client permissions (#19501) * refactor: v2 permissions as string array * refactor: frontend work with permissions as string * tests: test '*' permissions * fix:managed org creator have profile & test can fetch oauth client * fix: tests * fix: OAuthClientCard on frontend * fix: tests
84 lines
2.0 KiB
TypeScript
84 lines
2.0 KiB
TypeScript
import { useQuery } from "@tanstack/react-query";
|
|
|
|
import type { ApiSuccessResponse, PlatformOAuthClientDto } from "@calcom/platform-types";
|
|
|
|
export type ManagedUser = {
|
|
id: number;
|
|
email: string;
|
|
username: string | null;
|
|
timeZone: string;
|
|
weekStart: string;
|
|
createdDate: Date;
|
|
timeFormat: number | null;
|
|
defaultScheduleId: number | null;
|
|
};
|
|
|
|
export const useOAuthClients = () => {
|
|
const query = useQuery<ApiSuccessResponse<PlatformOAuthClientDto[]>>({
|
|
queryKey: ["oauth-clients"],
|
|
queryFn: () => {
|
|
return fetch("/api/v2/oauth-clients", {
|
|
method: "get",
|
|
headers: { "Content-type": "application/json" },
|
|
}).then((res) => res.json());
|
|
},
|
|
});
|
|
|
|
return { ...query, data: query.data?.data ?? [] };
|
|
};
|
|
|
|
export const useOAuthClient = (clientId?: string) => {
|
|
const {
|
|
isLoading,
|
|
error,
|
|
data: response,
|
|
isFetched,
|
|
isError,
|
|
isFetching,
|
|
isSuccess,
|
|
isFetchedAfterMount,
|
|
refetch,
|
|
} = useQuery<ApiSuccessResponse<PlatformOAuthClientDto>>({
|
|
queryKey: ["oauth-client", clientId],
|
|
queryFn: () => {
|
|
return fetch(`/api/v2/oauth-clients/${clientId}`, {
|
|
method: "get",
|
|
headers: { "Content-type": "application/json" },
|
|
}).then((res) => res.json());
|
|
},
|
|
enabled: Boolean(clientId),
|
|
staleTime: Infinity,
|
|
});
|
|
|
|
return {
|
|
isLoading,
|
|
error,
|
|
data: response?.data,
|
|
isFetched,
|
|
isError,
|
|
isFetching,
|
|
isSuccess,
|
|
isFetchedAfterMount,
|
|
refetch,
|
|
};
|
|
};
|
|
export const useGetOAuthClientManagedUsers = (clientId: string) => {
|
|
const {
|
|
isLoading,
|
|
error,
|
|
data: response,
|
|
refetch,
|
|
} = useQuery<ApiSuccessResponse<ManagedUser[]>>({
|
|
queryKey: ["oauth-client-managed-users", clientId],
|
|
queryFn: () => {
|
|
return fetch(`/api/v2/oauth-clients/${clientId}/managed-users`, {
|
|
method: "get",
|
|
headers: { "Content-type": "application/json" },
|
|
}).then((res) => res.json());
|
|
},
|
|
enabled: Boolean(clientId),
|
|
});
|
|
|
|
return { isLoading, error, data: response?.data, refetch };
|
|
};
|