2023-01-31 19:10:21 +00:00
|
|
|
import { trpc } from "@calcom/trpc/react";
|
|
|
|
|
2023-02-17 23:00:19 +00:00
|
|
|
import { IS_SELF_HOSTED } from "../constants";
|
2023-01-31 19:10:21 +00:00
|
|
|
import hasKeyInMetadata from "../hasKeyInMetadata";
|
|
|
|
|
|
|
|
export function useHasPaidPlan() {
|
2023-02-17 23:00:19 +00:00
|
|
|
if (IS_SELF_HOSTED) return { isLoading: false, hasPaidPlan: true };
|
|
|
|
|
2023-01-31 19:10:21 +00:00
|
|
|
const { data: hasTeamPlan, isLoading: isLoadingTeamQuery } = trpc.viewer.teams.hasTeamPlan.useQuery();
|
|
|
|
|
|
|
|
const { data: user, isLoading: isLoadingUserQuery } = trpc.viewer.me.useQuery();
|
|
|
|
|
|
|
|
const isLoading = isLoadingTeamQuery || isLoadingUserQuery;
|
|
|
|
|
|
|
|
const isCurrentUsernamePremium = user && user.metadata && hasKeyInMetadata(user, "isPremium");
|
|
|
|
|
|
|
|
const hasPaidPlan = hasTeamPlan?.hasTeamPlan || isCurrentUsernamePremium;
|
|
|
|
|
|
|
|
return { isLoading, hasPaidPlan };
|
|
|
|
}
|
|
|
|
|
|
|
|
export function useTeamInvites() {
|
|
|
|
const listInvites = trpc.viewer.teams.listInvites.useQuery();
|
|
|
|
|
|
|
|
return { isLoading: listInvites.isLoading, listInvites: listInvites.data };
|
|
|
|
}
|
|
|
|
|
2023-02-17 23:00:19 +00:00
|
|
|
export function useHasTeamPlan() {
|
|
|
|
const { data: hasTeamPlan, isLoading } = trpc.viewer.teams.hasTeamPlan.useQuery();
|
|
|
|
|
|
|
|
return { isLoading, hasTeamPlan: hasTeamPlan?.hasTeamPlan };
|
|
|
|
}
|
|
|
|
|
2023-01-31 19:10:21 +00:00
|
|
|
export default useHasPaidPlan;
|