cal/packages/lib/hooks/useHasPaidPlan.ts
Carina Wollendorfer cc2c04e52b
fix is premium check (#9101)
Co-authored-by: CarinaWolli <wollencarina@gmail.com>
2023-05-24 18:24:12 +00:00

36 lines
1.1 KiB
TypeScript

import { trpc } from "@calcom/trpc/react";
import { IS_SELF_HOSTED } from "../constants";
import hasKeyInMetadata from "../hasKeyInMetadata";
export function useHasPaidPlan() {
if (IS_SELF_HOSTED) return { isLoading: false, hasPaidPlan: true };
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 && hasKeyInMetadata(user, "isPremium") ? !!user.metadata.isPremium : false;
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 };
}
export function useHasTeamPlan() {
const { data: hasTeamPlan, isLoading } = trpc.viewer.teams.hasTeamPlan.useQuery();
return { isLoading, hasTeamPlan: hasTeamPlan?.hasTeamPlan };
}
export default useHasPaidPlan;