"use client"; import { BILLING_PLANS, BILLING_PRICING } from "@calcom/features/ee/billing/constants"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { trpc } from "@calcom/trpc/react"; import { Icon } from "@calcom/ui/components/icon"; import { Alert, AlertDescription, AlertTitle } from "@coss/ui/components/alert"; import { Badge } from "@coss/ui/components/badge"; import { Button } from "@coss/ui/components/button"; import { Card, CardPanel } from "@coss/ui/components/card"; import { Dialog, DialogClose, DialogHeader, DialogPanel, DialogPopup, DialogTitle, DialogTrigger, } from "@coss/ui/components/dialog"; import { Toggle, ToggleGroup } from "@coss/ui/components/toggle-group"; import Link from "next/link"; import posthog from "posthog-js"; import { useState } from "react"; type BillingPeriodToggle = "annual" | "monthly"; interface PlanFeature { text: string; } interface PlanColumnProps { name: string; badge?: string; price: string; priceSubtext: string; description: string; features: PlanFeature[]; buttonText: string; buttonHref: string; buttonTarget?: string; primaryButton?: boolean; onCtaClick?: () => void; } function PlanColumn({ name, badge, price, priceSubtext, description, features, buttonText, buttonHref, buttonTarget, primaryButton, onCtaClick, }: PlanColumnProps): JSX.Element { return (

{name}

{badge && ( {badge} )}

{price}

{priceSubtext}

{description}

); } export type UpgradePlanDialogProps = { tracking: string; target: "team" | "organization"; info?: { title: string; description: string; }; children: React.ReactNode; }; export function UpgradePlanDialog({ tracking, target, info, children }: UpgradePlanDialogProps): JSX.Element { const { t } = useLocale(); const [billingPeriod, setBillingPeriod] = useState<"annual" | "monthly">("annual"); const { data: activeTeamPlan } = trpc.viewer.teams.hasActiveTeamPlan.useQuery(); const formatCents = (cents: number) => { const dollars = cents / 100; return `$${cents % 100 === 0 ? dollars : dollars.toFixed(2)}`; }; const teamPrice = formatCents(BILLING_PRICING[BILLING_PLANS.TEAMS][billingPeriod]); const orgPrice = formatCents(BILLING_PRICING[BILLING_PLANS.ORGANIZATIONS][billingPeriod]); const currentPlanPricingKey = activeTeamPlan?.billingPeriod === "ANNUALLY" ? "annual" : "monthly"; const currentTeamPrice = formatCents(BILLING_PRICING[BILLING_PLANS.TEAMS][currentPlanPricingKey]); const bpParam = billingPeriod === "annual" ? "a" : "m"; const teamHref = `/settings/teams/new?bp=${bpParam}`; const organizationHref = `/onboarding/organization/details?migrate=true&bp=${bpParam}`; const teamFeatures: PlanFeature[] = [ { text: t("upgrade_feature_round_robin") }, { text: t("upgrade_feature_collective_events") }, { text: t("routing_forms") }, { text: t("upgrade_feature_workflows") }, { text: t("upgrade_feature_insights") }, { text: t("upgrade_feature_remove_branding") }, ]; const orgFeatures: PlanFeature[] = [ { text: t("upgrade_feature_everything_in_team") }, { text: t("unlimited_teams") }, { text: t("upgrade_feature_verified_domain") }, { text: t("upgrade_feature_directory_sync") }, { text: t("upgrade_feature_sso") }, { text: t("upgrade_feature_admin_panel") }, ]; const enterpriseFeatures: PlanFeature[] = [ { text: t("upgrade_feature_everything_in_org") }, { text: t("upgrade_feature_dedicated_support") }, { text: t("upgrade_feature_custom_sla") }, { text: t("upgrade_feature_custom_integrations") }, { text: t("upgrade_feature_compliance") }, ]; return (
{t("upgrade_dialog_title")}
{ if (value.length > 0) { const newPeriod = value[0] as BillingPeriodToggle; setBillingPeriod(newPeriod); posthog.capture("upgrade_plan_dialog_billing_period_changed", { source: tracking, target, billingPeriod: newPeriod, }); } }} className="rounded-lg bg-muted p-1" size="sm"> {t("upgrade_billing_annual")} {t("discount_25")} {t("monthly")} }>
{info && ( {info.title} {info.description} )}
{target === "team" && ( posthog.capture("upgrade_plan_dialog_cta_clicked", { source: tracking, plan: "team", target, billingPeriod, }) } /> )} posthog.capture("upgrade_plan_dialog_cta_clicked", { source: tracking, plan: "organization", target, billingPeriod, }) } /> posthog.capture("upgrade_plan_dialog_cta_clicked", { source: tracking, plan: "enterprise", target, billingPeriod, }) } />
{target === "team" && (

{t("individual")}

{t("free")}

)} {target === "organization" && (

{t("team")}

{currentTeamPrice} {t("upgrade_price_per_month_user")}

)} {t("upgrade_badge_current_plan")}
); }