feat: add upgrade banners for teams and organizations (#27650)

This commit is contained in:
Eunjae Lee authored and GitHub committed 2026-03-05 18:19:01 +09:00
1 parent c197de147a
commit b7340f7151
74 files changed
+1834 -500

No files matched your search

@@ -0,0 +1,318 @@
"use client";
import { useFillRemainingHeight } from "@calcom/lib/hooks/useFillRemainingHeight";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import useMediaQuery from "@calcom/lib/hooks/useMediaQuery";
import { Icon } from "@calcom/ui/components/icon";
import { OrgBadge, TeamBadge } from "@calcom/web/modules/billing/components/PlanBadge";
import { UpgradePlanDialog } from "@calcom/web/modules/billing/components/UpgradePlanDialog";
import { Badge } from "@coss/ui/components/badge";
import { Button } from "@coss/ui/components/button";
import {
Dialog,
DialogDescription,
DialogFooter,
DialogHeader,
DialogPopup,
DialogTitle,
} from "@coss/ui/components/dialog";
import Image from "next/image";
import Link from "next/link";
import posthog from "posthog-js";
import { useState } from "react";
import type { UpgradeTarget } from "./types";
export type { UpgradeTarget };
export type FullScreenUpgradeBannerProps = {
tracking: string;
name: string;
title: string;
subtitle: string;
features?: string[];
target: UpgradeTarget;
learnMoreButton?: {
text: string;
href?: string;
onClick?: () => void;
};
extraOffset?:
| number
| {
mobile?: number;
tablet?: number;
desktop?: number;
};
image: {
src: string;
width: number;
height: number;
};
youtubeId?: string;
};
function useResponsiveOffset(
extraOffset?:
| number
| {
mobile?: number;
tablet?: number;
desktop?: number;
}
) {
const isMobile = useMediaQuery("(max-width: 639px)");
const isTablet = useMediaQuery("(max-width: 767px)");
if (isMobile) {
return typeof extraOffset === "number" ? extraOffset : (extraOffset?.mobile ?? 74);
} else if (isTablet) {
return typeof extraOffset === "number" ? extraOffset : (extraOffset?.tablet ?? 85);
} else {
return typeof extraOffset === "number" ? extraOffset : (extraOffset?.desktop ?? 24);
}
}
function BannerImage({
image,
name,
youtubeId,
tracking,
target,
onPlayVideo,
}: {
image: { src: string; width: number; height: number };
name: string;
youtubeId?: string;
tracking: string;
target: UpgradeTarget;
onPlayVideo: () => void;
}): JSX.Element {
const { t } = useLocale();
return (
<>
<Image
src={image.src}
alt={name}
width={image.width}
height={image.height}
className="h-full w-full object-cover object-top"
/>
{youtubeId && (
<button
type="button"
className="absolute inset-0 flex items-center justify-center cursor-pointer"
onClick={() => {
posthog.capture("fullscreen_upgrade_banner_video_played", { source: tracking, target });
onPlayVideo();
}}>
<Image src="/play_button.svg" alt={t("play_video")} width={48} height={48} />
</button>
)}
</>
);
}
export function FullScreenUpgradeBanner({
tracking,
name,
title,
subtitle,
features,
target,
learnMoreButton,
extraOffset,
image,
youtubeId,
}: FullScreenUpgradeBannerProps): JSX.Element {
const [videoOpen, setVideoOpen] = useState(false);
const [showFeatures, setShowFeatures] = useState(false);
const deviceSpecificOffset = useResponsiveOffset(extraOffset);
const { t } = useLocale();
const ref = useFillRemainingHeight(deviceSpecificOffset);
const bannerImageProps = {
image,
name,
youtubeId,
tracking,
target,
onPlayVideo: () => setVideoOpen(true),
};
return (
<div ref={ref} className="flex w-full shrink-0 items-center justify-center rounded-xl bg-subtle p-8">
<div className="flex w-full h-full md:h-auto max-w-3xl gap-2 overflow-hidden rounded-3xl bg-default p-5 md:py-8 md:pl-8 md:pr-0 shadow-sm">
{/* Left Content */}
<div className="flex flex-1 flex-col justify-between overflow-hidden">
<div className={`${showFeatures ? "overflow-y-auto" : ""} md:overflow-visible`}>
<div>
<Badge
variant="outline"
className="text-sm text-default font-medium bg-subtle px-2 py-1 h-fit! border-0">
{name}
</Badge>
</div>
<h2 className="mt-3 font-cal font-semibold text-emphasis text-xl leading-none">{title}</h2>
<p className="mt-2 text-subtle text-sm">{subtitle}</p>
{/* Features List */}
{features && (
<>
<ul className="mt-4 space-y-2 hidden md:block">
{features.map((feature) => (
<li key={feature} className="flex items-center gap-2 text-sm text-subtle">
<span className="text-subtle">•</span>
{feature}
</li>
))}
</ul>
<div className="md:hidden mt-4">
{showFeatures ? (
<>
<ul className="space-y-2">
{features.map((feature) => (
<li key={feature} className="flex items-center gap-2 text-sm text-subtle">
<span className="text-subtle">•</span>
{feature}
</li>
))}
</ul>
<button
type="button"
className="mt-2 text-sm text-emphasis font-medium cursor-pointer underline"
onClick={() => setShowFeatures(false)}>
{t("hide")}
</button>
</>
) : (
<button
type="button"
className="text-sm text-emphasis font-medium cursor-pointer underline"
onClick={() => setShowFeatures(true)}>
{t("show_more")}
</button>
)}
</div>
</>
)}
</div>
{/* Image - mobile only, hidden when features are expanded */}
<div className={`${showFeatures ? "hidden" : ""} md:hidden my-4 flex items-center justify-center rounded-xl bg-subtle aspect-[3/4] overflow-hidden relative`}>
<BannerImage {...bannerImageProps} />
</div>
<div>
<div className="hidden md:flex items-center gap-2 mt-4">
<p className="text-sm font-medium text-subtle">{t("available_on")}</p>
{target === "team" && <TeamBadge />}
{(target === "team" || target === "organization") && <OrgBadge />}
</div>
<div className="mt-4 h-px w-full border border-t-subtle border-dashed" />
{/* Buttons */}
<div className="mt-6 flex items-center justify-between md:justify-start gap-2">
<UpgradePlanDialog
tracking={tracking}
info={{
title,
description: subtitle,
}}
target={target}>
<Button
onClick={() =>
posthog.capture("fullscreen_upgrade_banner_cta_clicked", { source: tracking, target })
}>
{t("try_for_free")}
<Icon name="arrow-right" />
</Button>
</UpgradePlanDialog>
{learnMoreButton &&
(learnMoreButton.href ? (
<Button
variant="ghost"
className="text-subtle"
onClick={() =>
posthog.capture("fullscreen_upgrade_banner_learn_more_clicked", {
source: tracking,
target,
})
}
render={<Link href={learnMoreButton.href} target="_blank" rel="noopener noreferrer" />}>
{learnMoreButton.text}
</Button>
) : (
<Button
variant="ghost"
className="text-subtle"
onClick={() => {
posthog.capture("fullscreen_upgrade_banner_learn_more_clicked", {
source: tracking,
target,
});
learnMoreButton.onClick?.();
}}>
{learnMoreButton.text}
</Button>
))}
</div>
</div>
</div>
{/* Right Content - Image */}
<div className="-my-2 hidden md:flex flex-1 items-center justify-center rounded-l-xl bg-subtle aspect-[3/4] overflow-hidden border border-muted border-r-0 relative">
<BannerImage {...bannerImageProps} />
</div>
</div>
{youtubeId && (
<Dialog open={videoOpen} onOpenChange={setVideoOpen}>
<DialogPopup className="max-w-3xl overflow-hidden">
<DialogHeader>
<DialogTitle>{name}</DialogTitle>
<DialogDescription>
{t("available_on_plan", { plan: target === "organization" ? t("organization") : t("team") })}
</DialogDescription>
</DialogHeader>
<div className="aspect-video w-full px-6 pb-6">
<iframe
src={`https://www.youtube.com/embed/${youtubeId}`}
title={title}
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowFullScreen
className="h-full w-full rounded-lg border border-muted"
/>
</div>
<DialogFooter>
<Button
variant="outline"
onClick={() => {
posthog.capture("fullscreen_upgrade_banner_video_dismissed", { source: tracking, target });
setVideoOpen(false);
}}>
{t("dismiss")}
</Button>
<UpgradePlanDialog
tracking={tracking}
info={{
title,
description: subtitle,
}}
target={target}>
<Button
onClick={() =>
posthog.capture("fullscreen_upgrade_banner_video_cta_clicked", {
source: tracking,
target,
})
}>
{t("get_started")}
<Icon name="arrow-right" />
</Button>
</UpgradePlanDialog>
</DialogFooter>
</DialogPopup>
</Dialog>
)}
</div>
);
}
@@ -0,0 +1,16 @@
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { Badge } from "@coss/ui/components/badge";
export function TeamBadge() {
const { t } = useLocale();
return <Badge variant="warning" className="bg-orange-200! text-orange-900">{t("teams")}</Badge>;
}
export function OrgBadge() {
const { t } = useLocale();
return (
<Badge variant="warning" className="bg-purple-200! text-purple-900">
{t("orgs")}
</Badge>
);
}
@@ -0,0 +1,303 @@
"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 (
<Card className="flex-1 gap-0 rounded-xl border-subtle p-4 py-0">
<CardPanel className="px-0">
<div className="flex items-center gap-2">
<h3 className="font-medium text-sm text-emphasis">{name}</h3>
{badge && (
<Badge variant="outline" className="rounded-lg py-0.5 px-2 h-fit!">
{badge}
</Badge>
)}
</div>
<p className="font-cal mt-2 leading-none font-semibold text-2xl text-emphasis">{price}</p>
<p className="mt-2 leading-none font-medium text-sm text-subtle h-4">{priceSubtext}</p>
<Button
className="mt-4 w-full"
variant={primaryButton ? "default" : "outline"}
onClick={onCtaClick}
render={
<Link
href={buttonHref}
target={buttonTarget}
rel={buttonTarget === "_blank" ? "noopener noreferrer" : undefined}
/>
}>
<Icon name="circle-arrow-up" />
<span>{buttonText}</span>
</Button>
<p className="mt-4 text-sm text-subtle">{description}</p>
<ul className="mt-3 space-y-2">
{features.map((feature) => (
<li key={feature.text} className="flex items-start gap-2 text-sm">
<Icon name="dot" className="relative top-0.5 h-4 w-4 shrink-0 text-default" />
<span className="text-default">{feature.text}</span>
</li>
))}
</ul>
</CardPanel>
</Card>
);
}
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 (
<Dialog>
<DialogTrigger render={children as React.ReactElement} />
<DialogPopup className="max-w-3xl" showCloseButton={false} bottomStickOnMobile={false}>
<DialogHeader>
<div className="flex flex-wrap items-center justify-between gap-2">
<DialogTitle>{t("upgrade_dialog_title")}</DialogTitle>
<div className="flex items-center gap-1 max-sm:order-last">
<ToggleGroup
value={[billingPeriod]}
onValueChange={(value): void => {
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">
<Toggle
value="annual"
className="gap-1 rounded-md data-pressed:bg-default data-pressed:shadow-sm">
{t("upgrade_billing_annual")}
<Badge variant="info" size="sm">
{t("discount_25")}
</Badge>
</Toggle>
<Toggle
value="monthly"
className="ml-1 rounded-md data-pressed:bg-default data-pressed:shadow-sm">
{t("monthly")}
</Toggle>
</ToggleGroup>
<DialogClose render={<Button size="icon" variant="ghost" />}>
<Icon name="x" />
</DialogClose>
</div>
{info && (
<Alert variant="info" className="w-full">
<AlertTitle>{info.title}</AlertTitle>
<AlertDescription>{info.description}</AlertDescription>
</Alert>
)}
</div>
</DialogHeader>
<DialogPanel>
<div className="mt-3 overflow-x-auto">
<div className="flex gap-2 sm:gap-4 max-sm:grid max-sm:grid-flow-col max-sm:auto-cols-fr max-sm:w-max">
{target === "team" && (
<PlanColumn
name={t("team")}
badge={t("upgrade_badge_free_trial")}
price={teamPrice}
priceSubtext={t("upgrade_price_per_month_user")}
description={t("upgrade_plan_team_tagline")}
features={teamFeatures}
buttonText={t("upgrade_cta_teams")}
buttonHref={teamHref}
primaryButton={target === "team"}
onCtaClick={() =>
posthog.capture("upgrade_plan_dialog_cta_clicked", {
source: tracking,
plan: "team",
target,
billingPeriod,
})
}
/>
)}
<PlanColumn
name={t("organization")}
badge={t("upgrade_badge_free_trial")}
price={orgPrice}
priceSubtext={t("upgrade_price_per_month_user")}
description={t("upgrade_plan_org_tagline")}
features={orgFeatures}
buttonText={t("upgrade_cta_orgs")}
buttonHref={organizationHref}
primaryButton={target === "organization"}
onCtaClick={() =>
posthog.capture("upgrade_plan_dialog_cta_clicked", {
source: tracking,
plan: "organization",
target,
billingPeriod,
})
}
/>
<PlanColumn
name={t("enterprise")}
price={t("custom")}
priceSubtext=""
description={t("upgrade_plan_enterprise_tagline")}
features={enterpriseFeatures}
buttonText={t("upgrade_cta_enterprise")}
buttonHref="https://cal.com/sales"
buttonTarget="_blank"
onCtaClick={() =>
posthog.capture("upgrade_plan_dialog_cta_clicked", {
source: tracking,
plan: "enterprise",
target,
billingPeriod,
})
}
/>
</div>
</div>
<Card className="bg-muted mt-4 py-3 px-4 flex-row justify-between items-center">
{target === "team" && (
<div>
<p className="font-medium text-sm text-emphasis">{t("individual")}</p>
<p className="font-cal mt-1 font-semibold text-emphasis text-2xl leading-none">{t("free")}</p>
</div>
)}
{target === "organization" && (
<div>
<p className="font-medium text-sm text-emphasis">{t("team")}</p>
<p className="mt-1">
<span className="font-cal font-semibold text-emphasis text-2xl leading-none">
{currentTeamPrice}
</span>
<span className="ml-1 leading-none font-medium text-sm text-subtle">
{t("upgrade_price_per_month_user")}
</span>
</p>
</div>
)}
<Badge variant="outline" size="lg" className="rounded-lg py-1.5 px-2.5 h-fit!">
<span className="text-emphasis opacity-50 leading-none">{t("upgrade_badge_current_plan")}</span>
</Badge>
</Card>
</DialogPanel>
</DialogPopup>
</Dialog>
);
}
@@ -0,0 +1,149 @@
"use client";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { localStorage } from "@calcom/lib/webstorage";
import { Icon } from "@calcom/ui/components/icon";
import { OrgBadge, TeamBadge } from "@calcom/web/modules/billing/components/PlanBadge";
import { Button } from "@coss/ui/components/button";
import Image from "next/image";
import Link from "next/link";
import posthog from "posthog-js";
import { useClientOnly } from "@calcom/lib/hooks/useClientOnly";
import { useState } from "react";
import type { UpgradeTarget } from "./types";
const STORAGE_KEY = "dismissed-large-upgrade-banners";
function isDismissed(tracking: string): boolean {
const raw = localStorage.getItem(STORAGE_KEY);
if (!raw) return false;
try {
const dismissed = JSON.parse(raw) as Record<string, boolean>;
return dismissed[tracking] === true;
} catch {
return false;
}
}
function dismiss(tracking: string): void {
const raw = localStorage.getItem(STORAGE_KEY);
let dismissed: Record<string, boolean> = {};
if (raw) {
try {
dismissed = JSON.parse(raw) as Record<string, boolean>;
} catch {
// corrupted data, start fresh
}
}
dismissed[tracking] = true;
localStorage.setItem(STORAGE_KEY, JSON.stringify(dismissed));
}
export type WideUpgradeBannerProps = {
tracking: string;
title: string;
subtitle: string;
target: UpgradeTarget;
size?: "md" | "sm";
image: {
src: string;
width: number;
height: number;
};
learnMoreButton?: {
text: string;
href?: string;
onClick?: () => void;
};
children: React.ReactNode;
};
export function WideUpgradeBanner({
tracking,
title,
subtitle,
target,
size = "md",
image,
learnMoreButton,
children,
}: WideUpgradeBannerProps) {
const { t } = useLocale();
const [visible, setVisible] = useState(false);
useClientOnly(() => {
setVisible(!isDismissed(tracking));
});
if (!visible) return null;
return (
<div className="relative flex w-full overflow-hidden rounded-xl bg-muted border-muted border">
<Button
variant="ghost"
className="absolute right-2 top-2 z-10"
onClick={() => {
dismiss(tracking);
setVisible(false);
posthog.capture("large_upgrade_banner_dismissed", { source: tracking, target });
}}>
{/* This button goes on top of the image, so it's better to force this color */}
<Icon name="x" className="h-4 w-4 text-gray-700" />
</Button>
{/* Left Content */}
<div className="flex flex-1 flex-col p-6">
{size === "sm" ? (
<div className="flex items-start gap-1.5">
<h2 className="font-cal text-base font-semibold leading-none text-default">{title}</h2>
<div className="relative -top-1">
{target === "team" ? <TeamBadge /> : <OrgBadge />}
</div>
</div>
) : (
<div>
{target === "team" ? <TeamBadge /> : <OrgBadge />}
<h2 className="mt-1 font-cal text-lg font-semibold leading-none text-default">{title}</h2>
</div>
)}
<p className="mt-2 text-sm font-normal text-subtle">{subtitle}</p>
{/* Buttons */}
<div className={`${size === "sm" ? "mt-4" : "mt-9"} flex items-center gap-2`}>
{children}
{learnMoreButton &&
(learnMoreButton.href ? (
<Button
variant="ghost"
className="text-subtle"
onClick={() =>
posthog.capture("large_upgrade_banner_learn_more_clicked", { source: tracking, target })
}
render={<Link href={learnMoreButton.href} target="_blank" rel="noopener noreferrer" />}>
{learnMoreButton.text}
</Button>
) : (
<Button
variant="ghost"
className="text-subtle"
onClick={() => {
posthog.capture("large_upgrade_banner_learn_more_clicked", { source: tracking, target });
learnMoreButton.onClick?.();
}}>
{learnMoreButton.text}
</Button>
))}
</div>
</div>
{/* Right Content - Image */}
<div
className={`relative hidden w-1/2 overflow-hidden md:block${size === "sm" ? " max-w-64" : " max-w-[520px]"}`}>
<Image
src={image.src}
alt={title}
fill
className="object-cover object-left"
/>
</div>
</div>
);
}
@@ -0,0 +1 @@
export type UpgradeTarget = "team" | "organization";