mirror of
https://github.com/supabase/supabase.git
synced 2026-10-10 03:45:06 +03:00
## Summary Replaces the header upgrade CTA (PR #44494, which design team wanted to iterate on) with a placement experiment that tests three non-chrome surfaces for the free-plan "Upgrade to Pro" CTA. PostHog flag `upgradeCtaPlacement` (free-plan users only) with four arms: | Variant | Surface | | --- | --- | | `control` | No CTA (baseline cohort, still tracked) | | `user_dropdown` | Full-width button pinned in the account dropdown | | `org_projects_list` | Project-card-shaped usage tile, first card in the org project grid | ## Details ### `user_dropdown` - Full-width `Upgrade to Pro` button in `UserDropdown`, gated to org-scoped routes only (`/project/*`, `/org/*`) so the org-billing CTA never shows on `/account`, `/organizations`, etc. — addresses the scope concern raised in review. - Dropdown uses controlled `open` state so it closes before navigation (it lives in the global layout, so a route change alone wouldn't dismiss the overlay). ### `org_projects_list` - `PlanUsageCard` renders as the first `<li>` in the project grid (via `ProjectList`'s `prependCard`), matching `ProjectCard` shape so it reads like another project tile. Also renders during the project-list loading state to avoid pop-in. <img width="3804" height="1494" alt="Arc 2026-06-08 20 02 54" src="https://github.com/user-attachments/assets/09c2218c-43d1-49ce-bae7-5075c9750d72" /> ### Shared card styling - Metric rows (Egress, Database size, Monthly active users, File storage) show `current / limit` with a progress ring; ring/value turn warning at ≥80% and over at ≥100%. - Rows are clickable deep-links to `/org/[slug]/usage#<anchor>` with a hover chevron and dashed separators; the same row component is used by both the embedded and project-card variants. - Skeleton placeholder renders from first paint so the card reserves layout while `useOrgUsageQuery` resolves. - Exposure is fired optimistically while the org query loads (skeleton shows immediately), but the experiment exposure event only fires once free-plan is confirmed. ### Telemetry - `upgrade_cta_clicked` with `placement: user_dropdown | home_usage_card | org_projects_list`. - `upgrade_cta_placement_experiment_exposed` with `variant` — the custom exposure event (snake_case experiment id `upgrade_cta_placement`; the flag key stays camelCase `upgradeCtaPlacement`). ### Header CTA sunset - `HeaderUpgradeButton` and its wiring in `LayoutHeader` / `MobileNavigationBar` removed (master's #46144 already removed the button; this branch drops the remaining `header_upgrade_cta_clicked` event). ## Before merging - [x] Create the `upgradeCtaPlacement` flag + experiment in PostHog (4 variants, free-plan targeting, custom exposure event `upgrade_cta_placement_experiment_exposed`). - [x] Archive the now-orphaned `headerUpgradeCta` flag. ## Test plan - [x] Override the flag per variant via the dev toolbar on staging; confirm each surface renders and `upgrade_cta_clicked` fires with the right `placement`. - [x] `control` shows no CTA but still emits the exposure event. - [x] Paid-plan org and self-hosted (`IS_PLATFORM=false`) show nothing. - [x] Clicking a metric row deep-links to the matching usage section; clicking Upgrade routes to billing. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Experimentally surface an “Upgrade to Pro” CTA in the user dropdown and on the projects page for eligible free-plan orgs. * Added a Plan Usage card showing free-plan metrics and upgrade prompts on the organization projects page; hides when irrelevant or errored. * Project list and its loading view support inserting a custom/prepend card in card mode. * **Telemetry** * Added tracking for CTA clicks and experiment exposure; placement is persisted per org. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: kemal <hello@kemal.earth>
207 lines
7.3 KiB
TypeScript
207 lines
7.3 KiB
TypeScript
import { useFlag } from 'common'
|
|
import { FlaskConical, Loader2, ScrollText, Settings } from 'lucide-react'
|
|
import { useTheme } from 'next-themes'
|
|
import Link from 'next/link'
|
|
import { useRouter } from 'next/router'
|
|
import { useState } from 'react'
|
|
import {
|
|
cn,
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuGroup,
|
|
DropdownMenuItem,
|
|
DropdownMenuLabel,
|
|
DropdownMenuRadioGroup,
|
|
DropdownMenuRadioItem,
|
|
DropdownMenuSeparator,
|
|
DropdownMenuTrigger,
|
|
singleThemes,
|
|
Theme,
|
|
} from 'ui'
|
|
|
|
import { ButtonTooltip } from '../ui/ButtonTooltip'
|
|
import { useFeaturePreviewModal } from './App/FeaturePreview/FeaturePreviewContext'
|
|
import { TimezoneDropdown } from './UserDropdown/TimezoneDropdown'
|
|
import { ProfileImage } from '@/components/ui/ProfileImage'
|
|
import { UpgradePlanButton } from '@/components/ui/UpgradePlanButton'
|
|
import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
|
|
import { useUpgradeCtaExperiment } from '@/hooks/misc/useUpgradeCtaExperiment'
|
|
import { IS_PLATFORM } from '@/lib/constants'
|
|
import { useProfileNameAndPicture } from '@/lib/profile'
|
|
import { useTrack } from '@/lib/telemetry/track'
|
|
import { useAppStateSnapshot } from '@/state/app-state'
|
|
|
|
export function UserDropdown({
|
|
triggerClassName,
|
|
contentClassName,
|
|
}: {
|
|
triggerClassName?: string
|
|
contentClassName?: string
|
|
}) {
|
|
const router = useRouter()
|
|
const { theme, setTheme } = useTheme()
|
|
const appStateSnapshot = useAppStateSnapshot()
|
|
const profileShowEmailEnabled = useIsFeatureEnabled('profile:show_email')
|
|
const timezonePickerEnabled = useFlag('timezonePicker')
|
|
const { username, avatarUrl, primaryEmail, isLoading } = useProfileNameAndPicture()
|
|
|
|
const { toggleFeaturePreviewModal } = useFeaturePreviewModal()
|
|
const track = useTrack()
|
|
|
|
const { variant: upgradeCtaVariant } = useUpgradeCtaExperiment()
|
|
// Per Slack feedback (Jonny): the upgrade CTA is org-scoped, so only show it on routes
|
|
// where an org is in scope. Excludes /account/*, /organizations, /new, marketing routes, etc.
|
|
const isOrgScopedRoute =
|
|
router.pathname.startsWith('/project/') || router.pathname.startsWith('/org/')
|
|
const showUpgradeCta = upgradeCtaVariant === 'user_dropdown' && isOrgScopedRoute
|
|
|
|
const [isOpen, setIsOpen] = useState(false)
|
|
|
|
return (
|
|
<DropdownMenu
|
|
open={isOpen}
|
|
onOpenChange={(open) => {
|
|
setIsOpen(open)
|
|
if (open) track('header_user_dropdown_opened')
|
|
}}
|
|
>
|
|
<DropdownMenuTrigger asChild className={cn('border shrink-0 px-3', triggerClassName)}>
|
|
<ButtonTooltip
|
|
type="default"
|
|
className="[&>span]:flex px-0 py-0 rounded-full overflow-hidden h-8 w-8"
|
|
tooltip={{ content: { text: 'Account settings' } }}
|
|
>
|
|
{isLoading ? (
|
|
<div className="w-full h-full flex items-center justify-center">
|
|
<Loader2 className="animate-spin text-foreground-lighter" size={16} />
|
|
</div>
|
|
) : (
|
|
<ProfileImage alt={username} src={avatarUrl} className="w-8 h-8 rounded-md" />
|
|
)}
|
|
</ButtonTooltip>
|
|
</DropdownMenuTrigger>
|
|
|
|
<DropdownMenuContent side="bottom" align="end" className={contentClassName}>
|
|
{IS_PLATFORM && (
|
|
<>
|
|
<div className="px-2 py-1 flex flex-col gap-0 text-sm">
|
|
{!!username ? (
|
|
<>
|
|
<span title={username} className="w-full text-left text-foreground truncate">
|
|
{username}
|
|
</span>
|
|
{primaryEmail !== username && profileShowEmailEnabled && (
|
|
<span
|
|
title={primaryEmail}
|
|
className="w-full text-left text-foreground-light text-xs truncate"
|
|
>
|
|
{primaryEmail}
|
|
</span>
|
|
)}
|
|
</>
|
|
) : (
|
|
<span title={primaryEmail} className="w-full text-left text-foreground truncate">
|
|
{primaryEmail}
|
|
</span>
|
|
)}
|
|
</div>
|
|
<DropdownMenuSeparator />
|
|
<DropdownMenuGroup>
|
|
<DropdownMenuItem className="flex gap-2 cursor-pointer" asChild>
|
|
<Link
|
|
href="/account/me"
|
|
onClick={() => {
|
|
if (router.pathname !== '/account/me') {
|
|
appStateSnapshot.setLastRouteBeforeVisitingAccountPage(router.asPath)
|
|
}
|
|
}}
|
|
>
|
|
<Settings size={14} strokeWidth={1.5} className="text-foreground-lighter" />
|
|
Account preferences
|
|
</Link>
|
|
</DropdownMenuItem>
|
|
<DropdownMenuItem
|
|
className="flex gap-2 cursor-pointer"
|
|
onClick={() => toggleFeaturePreviewModal(true)}
|
|
// onSelect={() => toggleFeaturePreviewModal(true)}
|
|
>
|
|
<FlaskConical size={14} strokeWidth={1.5} className="text-foreground-lighter" />
|
|
Feature previews
|
|
</DropdownMenuItem>
|
|
<DropdownMenuItem className="flex gap-2 cursor-pointer" asChild>
|
|
<Link
|
|
href="https://supabase.com/changelog"
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
>
|
|
<ScrollText size={14} strokeWidth={1.5} className="text-foreground-lighter" />
|
|
Changelog
|
|
</Link>
|
|
</DropdownMenuItem>
|
|
<DropdownMenuSeparator />
|
|
</DropdownMenuGroup>
|
|
</>
|
|
)}
|
|
<DropdownMenuGroup>
|
|
<DropdownMenuLabel>Theme</DropdownMenuLabel>
|
|
<DropdownMenuRadioGroup
|
|
value={theme}
|
|
onValueChange={(value) => {
|
|
setTheme(value)
|
|
}}
|
|
>
|
|
{singleThemes.map((theme: Theme) => (
|
|
<DropdownMenuRadioItem
|
|
key={theme.value}
|
|
value={theme.value}
|
|
className="cursor-pointer"
|
|
>
|
|
{theme.name}
|
|
</DropdownMenuRadioItem>
|
|
))}
|
|
</DropdownMenuRadioGroup>
|
|
</DropdownMenuGroup>
|
|
{timezonePickerEnabled && (
|
|
<>
|
|
<DropdownMenuSeparator />
|
|
<DropdownMenuGroup>
|
|
<TimezoneDropdown />
|
|
</DropdownMenuGroup>
|
|
</>
|
|
)}
|
|
{showUpgradeCta && (
|
|
<>
|
|
<DropdownMenuSeparator />
|
|
<div className="p-1">
|
|
<UpgradePlanButton
|
|
source="user_dropdown"
|
|
plan="Pro"
|
|
className="w-full justify-center"
|
|
onClick={() => {
|
|
track('upgrade_cta_clicked', { placement: 'user_dropdown' })
|
|
setIsOpen(false)
|
|
}}
|
|
/>
|
|
</div>
|
|
</>
|
|
)}
|
|
{IS_PLATFORM && (
|
|
<>
|
|
<DropdownMenuSeparator />
|
|
<DropdownMenuGroup>
|
|
<DropdownMenuItem
|
|
className="cursor-pointer"
|
|
onSelect={() => {
|
|
router.push('/logout')
|
|
}}
|
|
>
|
|
Log out
|
|
</DropdownMenuItem>
|
|
</DropdownMenuGroup>
|
|
</>
|
|
)}
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
)
|
|
}
|