Files
supabase/apps/studio/components/ui/UpgradePlanButton.tsx
Mert YEREKAPAN b9e83b25e1 feat(studio): adding upgrade button to header experiment (#44494)
## I have read the
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
file.

YES

## What kind of change does this PR introduce?

- Add an always-visible "Upgrade to Pro" button in the dashboard header
for free-plan users (GROWTH-615)
- Button is gated behind a PostHog experiment (`headerUpgradeCta`) with
`control` and `test` variants
- Experiment exposure is tracked for both variants; click events are
tracked when the button is clicked
- Button reuses existing `UpgradePlanButton` component for routing,
permissions, and billing logic

## What is the current behavior?

<img width="3840" height="2160" alt="Arc 2026-04-02 16 36 22"
src="https://github.com/user-attachments/assets/8a94db0c-06c8-4237-8ba5-6ac1fe111a56"
/>

## What is the new behavior?

<img width="3840" height="2160" alt="Arc 2026-04-02 16 36 12"
src="https://github.com/user-attachments/assets/0e60d834-028b-49fd-845e-ce1b4cbcc960"
/>


## Additional context

Add any other context or screenshots.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added an upgrade call-to-action in the header and mobile navigation
(visible on medium+ screens in platform builds) shown to free-plan users
as part of a controlled experiment.
* The CTA records experiment exposures and sends analytics for
impressions and clicks, including the user's current plan, to measure
engagement and upgrade interest.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-04-03 20:51:54 +02:00

130 lines
4.1 KiB
TypeScript

import { PermissionAction } from '@supabase/shared-types/out/constants'
import { useFlag, useParams } from 'common'
import Link from 'next/link'
import { PropsWithChildren } from 'react'
import { Button } from 'ui'
import { ButtonTooltip } from './ButtonTooltip'
import { RequestUpgradeToBillingOwners } from './RequestUpgradeToBillingOwners'
import { SupportLink } from '@/components/interfaces/Support/SupportLink'
import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'
import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
export const PLAN_REQUEST_EMPTY_PLACEHOLDER =
'<Specify which plan to upgrade to: Pro | Team | Enterprise>'
interface UpgradePlanButtonProps {
/** Stick to camel case for consistency */
source: string
variant?: 'default' | 'primary'
plan?: 'Pro' | 'Team' | 'Enterprise'
addon?: 'pitr' | 'customDomain' | 'ipv4' | 'spendCap' | 'computeSize'
/** Used in the default message template for request upgrade dialog, e.g: "Upgrade to ..." */
featureProposition?: string
disabled?: boolean
className?: string
slug?: string
onClick?: () => void
}
/**
* If `billingAll` is enabled, links to upgrade paths (e.g organization settings, addons).
*
* Otherwise, links to support form instead
*/
export const UpgradePlanButton = ({
source,
variant = 'primary',
plan = 'Pro',
addon,
featureProposition,
disabled,
children,
className,
slug: slugParam,
onClick,
}: PropsWithChildren<UpgradePlanButtonProps>) => {
const { ref } = useParams()
const { data: organization } = useSelectedOrganizationQuery()
const isFreePlan = organization?.plan?.id === 'free'
const slug = slugParam ?? organization?.slug ?? '_'
const projectUpdateDisabled = useFlag('disableProjectCreationAndUpdate')
const { billingAll } = useIsFeatureEnabled(['billing:all'])
const { can: canUpdateSubscription } = useAsyncCheckPermissions(
PermissionAction.BILLING_WRITE,
'stripe.subscriptions',
undefined,
{ organizationSlug: slug }
)
const subject = `Enquiry to upgrade ${!!plan ? `to ${plan} ` : ''}plan for organization`
const message = `Name: ${organization?.name}\nSlug: ${slug}\nRequested plan: ${plan ?? PLAN_REQUEST_EMPTY_PLACEHOLDER}`
const isRequestingToDisableSpendCap = addon === 'spendCap'
const isOnPaidPlanAndRequestingToPurchaseAddon = !isFreePlan && !!addon
// [Joshen] URL for button based on the "upgrade request" and the org's plan. Falls back to URL for opening subscription plan
const href = isRequestingToDisableSpendCap
? `/org/${slug ?? '_'}/billing?panel=costControl&source=${source}`
: isOnPaidPlanAndRequestingToPurchaseAddon
? addon === 'computeSize'
? `/project/${ref ?? '_'}/settings/compute-and-disk`
: `/project/${ref ?? '_'}/settings/addons?panel=${addon}&source=${source}`
: `/org/${slug ?? '_'}/billing?panel=subscriptionPlan&source=${source}`
const linkChildren =
children ||
(isOnPaidPlanAndRequestingToPurchaseAddon
? addon === 'computeSize'
? 'Change compute size'
: 'Enable add-on'
: `Upgrade to ${plan}`)
const link = billingAll ? (
<Link href={href}>{linkChildren}</Link>
) : (
<SupportLink queryParams={{ orgSlug: slug, category: 'Plan_upgrade', subject, message }}>
{linkChildren}
</SupportLink>
)
if (!canUpdateSubscription) {
return (
<RequestUpgradeToBillingOwners
plan={plan}
addon={addon}
featureProposition={featureProposition}
className={className}
>
{children}
</RequestUpgradeToBillingOwners>
)
}
if (projectUpdateDisabled) {
return (
<ButtonTooltip
disabled
type={variant}
className={className}
tooltip={{
content: {
side: 'bottom',
text: 'Plan changes are currently disabled, our engineers are working on a fix',
},
}}
>
{linkChildren}
</ButtonTooltip>
)
}
return (
<Button asChild type={variant} disabled={disabled} className={className} onClick={onClick}>
{link}
</Button>
)
}