Files
calendar/packages/lib/hooks/useHasPaidPlan.ts
T
+1 30ba168fc3 chore: bump @trpc/* and @tanstack/react-query (#13335)
Co-authored-by: Peer Richelsen <peeroke@gmail.com>
Co-authored-by: Omar López <zomars@me.com>
Co-authored-by: CarinaWolli <wollencarina@gmail.com>
Co-authored-by: Alex van Andel <me@alexvanandel.com>
Co-authored-by: zomars <zomars@me.com>
Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
Co-authored-by: Benny Joo <sldisek783@gmail.com>
Co-authored-by: Carina Wollendorfer <30310907+CarinaWolli@users.noreply.github.com>
Co-authored-by: Gergő Móricz <mo.geryy@gmail.com>
Co-authored-by: Keith Williams <keithwillcode@gmail.com>
2024-01-23 16:42:29 -07:00

43 lines
1.4 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 { isPending: false, hasPaidPlan: true };
const { data: hasTeamPlan, isPending: isPendingTeamQuery } = trpc.viewer.teams.hasTeamPlan.useQuery();
const { data: user, isPending: isPendingUserQuery } = trpc.viewer.me.useQuery();
const isPending = isPendingTeamQuery || isPendingUserQuery;
const isCurrentUsernamePremium =
user && hasKeyInMetadata(user, "isPremium") ? !!user.metadata.isPremium : false;
const hasPaidPlan = hasTeamPlan?.hasTeamPlan || isCurrentUsernamePremium;
return { isPending, hasPaidPlan };
}
export function useTeamInvites() {
const listInvites = trpc.viewer.teams.listInvites.useQuery();
return { isPending: listInvites.isPending, listInvites: listInvites.data };
}
export function useHasTeamPlan() {
const { data: hasTeamPlan, isPending } = trpc.viewer.teams.hasTeamPlan.useQuery();
return { isPending, hasTeamPlan: hasTeamPlan?.hasTeamPlan };
}
export function useHasEnterprisePlan() {
// TODO: figure out how to get "has Enterprise / has Org" from the backend
const { data: hasTeamPlan, isPending } = trpc.viewer.teams.hasTeamPlan.useQuery();
return { isPending, hasTeamPlan: hasTeamPlan?.hasTeamPlan };
}
export default useHasPaidPlan;