Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(billing): share paywall cards and unify account state previews (#7725)
Peter Chinmanfe39970b99e5
diff --git a/apps/web/src/features/paywall/Paywall.tsx b/apps/web/src/features/paywall/Paywall.tsxindex 3441fc13ff..5b1c193e28 100644--- a/apps/web/src/features/paywall/Paywall.tsx+++ b/apps/web/src/features/paywall/Paywall.tsx@@ -1,8 +1,8 @@import { globalSplitManager } from '@app/signal/splitLayout';import { usePaywallState } from '@core/constant/PaywallState';import { useHotkeyDOMScope } from '@core/hotkey/hotkeys';-import { Dialog, Surface } from '@ui';import { onMount } from 'solid-js';+import { PaywallDialog } from './components/paywall-dialog';import PaywallComponent from './PaywallComponent';export function Paywall() {@@ -55,23 +55,14 @@ export function Paywall() {});return (- <Dialog+ <PaywallDialogopen={paywallOpen()}- onOpenChange={(open) => !open && hidePaywall()}- position="center"- class="w-225"+ onClose={hidePaywall}+ contentRef={(element) => {+ paywallContentEl = element;+ }}>- <Surface depth={2} class="rounded-xl">- <div- class="*:max-h-[85vh] font-sans"- ref={paywallContentEl}- tabIndex={-1}- >- <div class="overflow-y-auto">- <PaywallComponent cb={hidePaywall} errorKey={paywallKey()} />- </div>- </div>- </Surface>- </Dialog>+ <PaywallComponent cb={hidePaywall} errorKey={paywallKey()} />+ </PaywallDialog>);}diff --git a/apps/web/src/features/paywall/PaywallComponent.tsx b/apps/web/src/features/paywall/PaywallComponent.tsxindex de07a134c7..78ac6d5459 100644--- a/apps/web/src/features/paywall/PaywallComponent.tsx+++ b/apps/web/src/features/paywall/PaywallComponent.tsx@@ -1,204 +1,70 @@-import { useAnalytics } from '@app/lib/analytics/analytics-context';+import { useFeatureFlag } from '@app/lib/analytics/posthog';import { useHasPaidAccess } from '@core/auth';+import { enableAiUsageBilling } from '@core/constant/featureFlags';import { type PaywallKey, PaywallMessages } from '@core/constant/PaywallState';+import { useSettingsState } from '@core/constant/SettingsState';import { useUserId } from '@core/context/user';-import { plural } from '@core/util/string';-import ArrowSquareOutIcon from '@phosphor/arrow-square-out.svg';-import CheckIcon from '@phosphor/check.svg';-import { queryReadyGate } from '@queries/gate';+import { useAiBillingSummaryQuery } from '@queries/auth';import { useCurrentTeamQuery } from '@queries/team/teams';-import { stripeServiceClient } from '@service-stripe/client';-import { Button, Tooltip } from '@ui';-import { createMemo, For, Show } from 'solid-js';-import { PLAN_BY_TIER } from './plans';+import { getBillingState } from '../settings/core/billing-state';+import { PaywallView } from './components/paywall-view';export interface PaywallProps {cb: () => Promise<void> | void;- handleGuest?: () => void;- isOnboarding?: boolean;errorKey?: PaywallKey | null;- customType?: string;- hideCloseButton?: boolean;}-const PAYWALL_PREMIUM_FEATURES = [- 'All agents',- 'All models',- 'No watermark',- 'AI projections',- 'Multiple email inboxes',- 'Calls',- 'Teams',- '100 GB storage',-];--const PremiumFeatures = () => (- <ul class="grid grid-cols-1 gap-x-4 gap-y-3 text-sm text-ink-muted sm:grid-cols-3">- <For each={PAYWALL_PREMIUM_FEATURES}>- {(label) => (- <li class="flex items-center gap-2">- <CheckIcon class="size-3 text-success" />- <span class="text-ink-muted text-xs">{label}</span>- </li>- )}- </For>- </ul>-);-+/** App wiring for the upgrade modal; cards and account policy are shared with Billing. */const PaywallComponent = (props: PaywallProps) => {- const analytics = useAnalytics();+ const { openSettings } = useSettingsState();const hasPaid = useHasPaidAccess();const userId = useUserId();-+ const aiUsageBilling = useFeatureFlag(enableAiUsageBilling);const team = useCurrentTeamQuery();-- const teamRole = createMemo(() => {- const uid = userId();- const currentTeam = queryReadyGate(team) ? team.data : undefined;-- if (!currentTeam) return;-- return currentTeam.team.owner_id === uid ? 'owner' : 'member';- });-- const upgradeDisabled = createMemo(() => teamRole() === 'member');-- const handleCheckout = async () => {- try {- await props.cb();- const url = await stripeServiceClient.createCheckoutSessionV2({- type: props.customType- ? props.customType- : (props.errorKey ?? undefined),- });- analytics.track('subscription_start', {- type: 'premium',- customType: props.customType,- errorKey: props.errorKey,- });- window.location.href = url;- } catch (error) {- console.error(error);- }+ const summary = useAiBillingSummaryQuery();+ const availability = () =>+ team.isPending || summary.isPending+ ? 'loading'+ : team.isSuccess && summary.isSuccess+ ? 'ready'+ : 'error';+ const state = () => {+ const currentTeam = team.isSuccess ? team.data : undefined;+ const currentSummary = summary.isSuccess ? summary.data : undefined;+ return getBillingState({+ hasPaid: currentSummary ? currentSummary.tier !== 'free' : hasPaid(),+ canManageSubscription: team.isSuccess,+ teamRole: currentTeam+ ? currentTeam.team.owner_id === userId()+ ? 'owner'+ : 'member'+ : undefined,+ summary: currentSummary+ ? {+ tier: currentSummary.tier,+ canManageBilling: currentSummary.can_manage_billing,+ }+ : undefined,+ aiUsageEnabled: aiUsageBilling().enabled,+ pending: false,+ });};- const manageSubscription = async () => {- try {- const url = await stripeServiceClient.createPortalSession();- window.location.href = url;- } catch (error) {- console.error(error);- }- };-- const handleContinue = () => {- if (upgradeDisabled()) return;-- if (hasPaid()) {- manageSubscription();- return;- }- handleCheckout();- };-- const ctaLabel = () => (hasPaid() ? 'Manage Subscription' : 'Upgrade now');- const paywallMetadata = () =>- props.errorKey ? PaywallMessages[props.errorKey] : undefined;-return (- <section class="relative flex w-full flex-col gap-6">- <div class="grid grid-cols-1 gap-6 sm:grid-cols-[minmax(0,1fr)_minmax(0,1.2fr)] p-6 sm:px-8 sm:pt-8 sm:pb-4">- <section class="flex flex-col gap-4">- <div class="flex flex-col gap-2">- <h2 class="text-2xl text-ink font-semibold">Unlock Pro features</h2>- <p class="text-sm text-ink-extra-muted">- {paywallMetadata()?.description ??- 'Upgrade your workspace with more AI power, team collaboration, and room to grow.'}- </p>- <Show when={paywallMetadata()?.learnMoreUrl}>- {(learnMoreUrl) => (- <a- class="mt-16 inline-flex items-center gap-1 self-start text-xs text-link hover:text-link-hover visited:text-link-visited"- href={learnMoreUrl()}- target="_blank"- rel="noopener"- >- Learn more about{' '}- {paywallMetadata()!.learnMoreSubject ?? 'Pro'}- <ArrowSquareOutIcon class="size-4" />- </a>- )}- </Show>- </div>- </section>-- <section class="h-full flex flex-col gap-3">- <div class="flex flex-1 flex-col gap-4 rounded-lg bg-active p-4">- <div class="flex flex-col">- <h3 class="text-sm text-ink">Pro features</h3>- </div>- <PremiumFeatures />- </div>- </section>- </div>-- <div class="border-t border-t-edge px-8 py-4 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">- <div class="flex items-baseline gap-1.5 text-xs text-ink/60">- <span class="text-ink font-semibold text-xl leading-6">- ${PLAN_BY_TIER.premium.price}- </span>- <span>per seat / per month</span>-- <Show- when={teamRole() === 'owner' && queryReadyGate(team) && team.data}- >- {(team) => (- <span class="text-ink-extra-muted text-xs">- • {team().members.length}{' '}- {plural('user', team().members.length)}- </span>- )}- </Show>- </div>- <div class="flex flex-col justify-end gap-2 sm:flex-row">- <Button- variant="ghost"- depth={3}- class="sm:w-auto px-3 py-1.5"- onClick={props.cb}- >- Dismiss- </Button>- <Show- when={upgradeDisabled()}- fallback={- <Button- variant={hasPaid() ? 'outline' : 'cta'}- class="sm:w-auto px-3 py-1.5"- onClick={handleContinue}- >- {ctaLabel()}- </Button>- }- >- <Tooltip- label="Your subscription is managed by your team owner. Contact them to make changes."- placement="top"- >- <span>- <Button- variant={hasPaid() ? 'outline' : 'cta'}- class="sm:w-auto px-3 py-1.5"- disabled- >- {ctaLabel()}- </Button>- </span>- </Tooltip>- </Show>- </div>- </div>- </section>+ <PaywallView+ state={state()}+ availability={availability()}+ metadata={props.errorKey ? PaywallMessages[props.errorKey] : undefined}+ onDismiss={props.cb}+ onManagePlan={async () => {+ await props.cb();+ openSettings('Billing');+ }}+ onRetry={() => {+ void team.refetch();+ void summary.refetch();+ }}+ />);};diff --git a/apps/web/src/features/paywall/components/paywall-dialog.tsx b/apps/web/src/features/paywall/components/paywall-dialog.tsxnew file mode 100644index 0000000000..266fbf3695--- /dev/null+++ b/apps/web/src/features/paywall/components/paywall-dialog.tsx@@ -0,0 +1,29 @@+import { Dialog, Surface } from '@ui';+import type { JSX } from 'solid-js';++/** Shared modal shell for the real paywall and local state preview. */+export function PaywallDialog(props: {+ open: boolean;+ onClose: () => void;+ contentRef?: (element: HTMLDivElement) => void;+ children: JSX.Element;+}) {+ return (+ <Dialog+ open={props.open}+ onOpenChange={(open) => !open && props.onClose()}+ position="center"+ class="w-225"+ >+ <Surface depth={2} class="rounded-xl">+ <div+ class="*:max-h-[85vh] font-sans"+ ref={props.contentRef}+ tabIndex={-1}+ >+ <div class="overflow-y-auto">{props.children}</div>+ </div>+ </Surface>+ </Dialog>+ );+}diff --git a/apps/web/src/features/paywall/components/paywall-view.tsx b/apps/web/src/features/paywall/components/paywall-view.tsxnew file mode 100644index 0000000000..8e1712cfa2--- /dev/null+++ b/apps/web/src/features/paywall/components/paywall-view.tsx@@ -0,0 +1,102 @@+import type { PaywallMessageMetadata } from '@core/constant/PaywallState';+import ArrowSquareOutIcon from '@phosphor/arrow-square-out.svg';+import { Button } from '@ui';+import { For, Match, Show, Switch } from 'solid-js';+import { BillingPlanCard } from '../../settings/components/billing-plan-card';+import type { BillingState } from '../../settings/core/billing-state';+import { getUpgradePlans } from '../plans';++export function PaywallView(props: {+ state: BillingState;+ availability: 'loading' | 'error' | 'ready';+ metadata?: PaywallMessageMetadata;+ onDismiss: () => void | Promise<void>;+ onManagePlan: () => void | Promise<void>;+ onRetry: () => void;+}) {+ return (+ <section class="flex w-full flex-col gap-6 p-6 sm:p-8">+ <header class="flex flex-col gap-2">+ <h2 class="text-2xl font-semibold text-ink">+ {props.state.tier === 'max'+ ? 'Manage your plan'+ : props.state.tier === 'premium'+ ? 'Upgrade to Max'+ : 'Upgrade your plan'}+ </h2>+ <p class="text-sm text-ink-extra-muted">+ {props.metadata?.description ?? 'Get more AI power and room to grow.'}+ </p>+ <Show when={props.metadata?.learnMoreUrl}>+ {(url) => (+ <a+ class="inline-flex items-center gap-1 self-start text-xs text-link hover:text-link-hover visited:text-link-visited"+ href={url()}+ target="_blank"+ rel="noopener"+ >+ Learn more about {props.metadata?.learnMoreSubject ?? 'plans'}+ <ArrowSquareOutIcon class="size-4 shrink-0" />+ </a>+ )}+ </Show>+ </header>+ <Switch>+ <Match when={props.availability === 'loading'}>+ <p role="status" class="text-sm text-ink-muted">+ Loading your plans…+ </p>+ </Match>+ <Match when={props.availability === 'error'}>+ <div class="flex flex-col items-start gap-3">+ <p role="alert" class="text-sm text-ink-muted">+ Couldn't load your available plans. Please try again.+ </p>+ <Button size="sm" variant="outline" onClick={props.onRetry}>+ Try again+ </Button>+ </div>+ </Match>+ <Match when={!props.state.canChangePlan}>+ <p class="text-sm text-ink-muted">+ {props.state.teamRole === 'member'+ ? 'Your plan is managed by your team. Contact your team owner to make changes.'+ : 'This account can’t make billing changes.'}+ </p>+ </Match>+ <Match when={props.state.tier === 'max'}>+ <p class="text-sm text-ink-muted">+ You're already on Max, our highest plan.+ </p>+ </Match>+ <Match when={props.availability === 'ready'}>+ <div class="@container/plan-options">+ <div+ class="grid grid-cols-1 gap-6"+ classList={{+ '@2xl/plan-options:grid-cols-2': props.state.tier === 'free',+ }}+ >+ <For each={getUpgradePlans(props.state.tier)}>+ {(plan) => <BillingPlanCard plan={plan} state={props.state} />}+ </For>+ </div>+ </div>+ </Match>+ </Switch>+ <footer class="flex flex-wrap justify-end gap-2 border-t border-edge-muted pt-4">+ <Button+ size="sm"+ variant="ghost"+ disabled={props.state.pending}+ onClick={props.onDismiss}+ >+ Dismiss+ </Button>+ <Button size="sm" variant="cta" onClick={props.onManagePlan}>+ Manage plan+ </Button>+ </footer>+ </section>+ );+}diff --git a/apps/web/src/features/paywall/plans.test.ts b/apps/web/src/features/paywall/plans.test.tsindex 9b60956ac1..50605a5656 100644--- a/apps/web/src/features/paywall/plans.test.ts+++ b/apps/web/src/features/paywall/plans.test.ts@@ -1,7 +1,13 @@import { describe, expect, it } from 'vitest';-import { PLAN_BY_TIER, PLANS, planFeatures } from './plans';+import { getUpgradePlans, PLAN_BY_TIER, PLANS, planFeatures } from './plans';describe('plan catalogs', () => {+ it('offers both paid plans to Free accounts, only Max to Pro, and no downgrade to Max', () => {+ expect(getUpgradePlans('free')).toEqual(['premium', 'max']);+ expect(getUpgradePlans('premium')).toEqual(['max']);+ expect(getUpgradePlans('max')).toEqual([]);+ });+it('lists Free, Pro and Max, cheapest first', () => {expect(PLANS.map((plan) => plan.tier)).toEqual(['free', 'premium', 'max']);expect(PLAN_BY_TIER.free.name).toBe('Free');diff --git a/apps/web/src/features/paywall/plans.ts b/apps/web/src/features/paywall/plans.tsindex fd700cb750..590325f905 100644--- a/apps/web/src/features/paywall/plans.ts+++ b/apps/web/src/features/paywall/plans.ts@@ -29,6 +29,17 @@ export function formatPlanPrice(cents: number | undefined): string | undefined {/** Tiers that correspond to real Stripe products. Excludes 'free'. */export type PaidPlanTier = Exclude<PlanTier, 'free'>;+const UPGRADE_PLANS: Record<PlanTier, readonly PaidPlanTier[]> = {+ free: ['premium', 'max'],+ premium: ['max'],+ max: [],+};++/** The paywall offers only tiers above the current plan. */+export function getUpgradePlans(tier: PlanTier): readonly PaidPlanTier[] {+ return UPGRADE_PLANS[tier];+}+const FREE_PLAN = {tier: 'free',name: 'Free',@@ -81,6 +92,41 @@ export const PLAN_USAGE_LABELS: Record<PlanTier, string> = {max: '10× usage',};+const PLAN_BENEFITS: Record<PlanTier, (usage: string | undefined) => string[]> =+ {+ free: (usage) => [+ 'Access to Haiku',+ ...(usage ? [usage] : []),+ 'MCP access',+ '2 connected email accounts',+ '5 GB storage',+ ],+ premium: (usage) => [+ 'All agents',+ 'All models',+ ...(usage ? [usage] : []),+ 'No email watermark',+ 'Unlimited connected email accounts',+ '100 GB storage',+ ],+ max: () => [+ 'Everything in Pro',+ '10x more AI usage than Pro',+ '1 TB storage',+ 'Priority support',+ ],+ };++/** Shared Billing/paywall bullets; only Free and Pro usage labels require the flag. */+export function planBenefits(+ tier: PlanTier,+ aiUsageBilling: boolean+): string[] {+ return PLAN_BENEFITS[tier](+ aiUsageBilling ? PLAN_USAGE_LABELS[tier] : undefined+ );+}+const PLAN_FEATURE_ROWS: PlanFeature[] = [{label: 'AI Agent',diff --git a/apps/web/src/features/settings/Billing.tsx b/apps/web/src/features/settings/Billing.tsxindex faab1c4887..4814660891 100644--- a/apps/web/src/features/settings/Billing.tsx+++ b/apps/web/src/features/settings/Billing.tsx@@ -21,12 +21,13 @@ import {getFreePlanCheckoutRequest,} from './core/billing-state';+const BillingPreview =+ import.meta.env.DEV && LOCAL_ONLY+ ? lazyNamed(() => import('./views/billing-preview'), 'BillingPreview')+ : undefined;+export function Billing() {- if (import.meta.env.DEV && LOCAL_ONLY) {- const BillingPreview = lazyNamed(- () => import('./views/billing-preview'),- 'BillingPreview'- );+ if (BillingPreview) {return (<Suspense fallback={<p role="status">Loading billing…</p>}><BillingPreview@@ -48,6 +49,8 @@ function LiveBilling(props: { controls?: JSX.Element }) {const aiUsageBilling = useFeatureFlag(enableAiUsageBilling);const changePlan = useChangePlanMutation();const checkout = useCreateCheckoutSessionMutation();+ const effectiveHasPaid = () =>+ hasPaid() || (summary.isSuccess && summary.data.tier !== 'free');const canManageSubscription = createMemo(() => {return permissions()?.includes(PERMISSION_IDS.WRITE_STRIPE_SUBSCRIPTION);@@ -72,7 +75,7 @@ function LiveBilling(props: { controls?: JSX.Element }) {const state = () =>getBillingState({- hasPaid: hasPaid(),+ hasPaid: effectiveHasPaid(),canManageSubscription: team.isSuccess && canManageSubscription() === true,teamRole: teamRole(),teamPlans: team.isSuccess@@ -139,7 +142,9 @@ function LiveBilling(props: { controls?: JSX.Element }) {controls={props.controls}onManage={() => void handleManage()}onSelectPlan={(plan) =>- void (hasPaid() ? handleChangePlan(plan) : handleCheckout(plan))+ void (effectiveHasPaid()+ ? handleChangePlan(plan)+ : handleCheckout(plan))}/>);diff --git a/apps/web/src/features/settings/components/billing-plan-card.tsx b/apps/web/src/features/settings/components/billing-plan-card.tsxnew file mode 100644index 0000000000..423afa5f2f--- /dev/null+++ b/apps/web/src/features/settings/components/billing-plan-card.tsx@@ -0,0 +1,126 @@+import {+ type PaidPlanTier,+ PLAN_BY_TIER,+ type PlanTier,+ planBenefits,+} from '@app/features/paywall/plans';+import CheckIcon from '@phosphor-fill/check-fat-fill.svg';+import { Button } from '@ui';+import { For, Show } from 'solid-js';+import type { BillingState } from '../core/billing-state';+import { SettingsCard } from '../primitives';++export const PlanFeatures = (props: {+ tier: PlanTier;+ aiUsageEnabled: boolean;+}) => {+ return (+ <For each={planBenefits(props.tier, props.aiUsageEnabled)}>+ {(label) => (+ <li class="flex items-center gap-2">+ <CheckIcon class="size-3 shrink-0 text-success" />+ <span class="text-ink-muted text-xs">{label}</span>+ </li>+ )}+ </For>+ );+};++const PlanPrice = (props: {+ tier: PaidPlanTier;+ perSeat: boolean;+ aiUsageEnabled: boolean;+}) => {+ return (+ <p class="text-ink-extra-muted text-xs">+ ${PLAN_BY_TIER[props.tier].price}{' '}+ {props.perSeat ? 'per seat / month' : '/ month'}+ <Show when={props.aiUsageEnabled}>+ <Show when={props.tier === 'max'}> · 10× usage</Show>+ </Show>+ </p>+ );+};++/** Plan cards shared by Billing settings and the upgrade paywall. */+export function BillingPlanCard(props: {+ plan: PaidPlanTier;+ state: Pick<+ BillingState,+ 'hasPaid' | 'teamRole' | 'aiUsageEnabled' | 'pending'+ >;+ onSelectPlan?: (plan: PaidPlanTier) => void;+}) {+ return (+ <SettingsCard class="@container/plan-card h-full">+ <section class="flex h-full flex-col gap-4 p-5">+ <header+ class="grid grid-cols-1 items-center gap-4"+ classList={{+ '@sm/plan-card:grid-cols-[minmax(0,1fr)_auto]':+ !!props.onSelectPlan,+ }}+ >+ <div class="flex min-w-0 flex-col gap-1">+ <div class="flex flex-wrap items-center gap-2">+ <h3 class="text-lg font-medium text-ink">+ {PLAN_BY_TIER[props.plan].name}+ </h3>+ <Show when={!props.state.hasPaid && props.plan === 'premium'}>+ <span class="text-sm font-medium text-accent">+ Free for one month!+ </span>+ </Show>+ </div>+ <PlanPrice+ tier={props.plan}+ perSeat={!!props.state.teamRole}+ aiUsageEnabled={props.state.aiUsageEnabled}+ />+ </div>+ <Show when={props.onSelectPlan}>+ <Button+ class="w-full py-1.5 px-3 @sm/plan-card:w-auto @sm/plan-card:justify-self-end"+ depth={2}+ variant="cta"+ disabled={props.state.pending}+ onClick={() => props.onSelectPlan?.(props.plan)}+ >+ {props.state.hasPaid+ ? props.plan === 'premium'+ ? 'Switch to Pro'+ : 'Upgrade to Max'+ : props.plan === 'premium'+ ? 'Get Pro'+ : 'Get Max'}+ </Button>+ </Show>+ </header>+ <ul class="border-t border-t-edge-muted pt-4 flex flex-col gap-3 text-sm text-ink-muted">+ <PlanFeatures+ tier={props.plan}+ aiUsageEnabled={props.state.aiUsageEnabled}+ />+ </ul>+ <Show+ when={+ props.state.hasPaid &&+ props.onSelectPlan &&+ (props.plan === 'max' || props.state.teamRole === 'owner')+ }+ >+ <p class="text-xs text-ink-extra-muted">+ <Show when={props.plan === 'max'}>+ Prorated for the rest of this period.+ </Show>+ <Show when={props.state.teamRole === 'owner'}>+ {' '}+ This moves only your seat; teammates' plans are set per seat in+ Team settings.+ </Show>+ </p>+ </Show>+ </section>+ </SettingsCard>+ );+}diff --git a/apps/web/src/features/settings/components/billing-settings-view.tsx b/apps/web/src/features/settings/components/billing-settings-view.tsxindex a2963a8176..07781a6dab 100644--- a/apps/web/src/features/settings/components/billing-settings-view.tsx+++ b/apps/web/src/features/settings/components/billing-settings-view.tsx@@ -1,84 +1,11 @@-import {- type PaidPlanTier,- PLAN_BY_TIER,- PLAN_USAGE_LABELS,- type PlanTier,-} from '@app/features/paywall/plans';+import { type PaidPlanTier, PLAN_BY_TIER } from '@app/features/paywall/plans';import { plural } from '@core/util/string';-import CheckIcon from '@phosphor/check.svg';import EnvelopeIcon from '@phosphor/envelope.svg';import { Button, Layer } from '@ui';import { For, type JSX, Match, Show, Switch } from 'solid-js';import { type BillingState, describeSeatPlans } from '../core/billing-state';import { SettingsCard, SettingsPage } from '../primitives';--/**- * Plan bullet points. Free and Pro allowance labels require AI usage billing;- * Max always explains its larger allowance relative to Pro.- */-const BILLING_PLAN_FEATURES: Record<- PlanTier,- (usage: string | undefined) => string[]-> = {- free: (usage) => [- 'Access to Haiku',- ...(usage ? [usage] : []),- 'MCP access',- '2 connected email accounts',- '5 GB storage',- ],- premium: (usage) => [- 'All agents',- 'All models',- ...(usage ? [usage] : []),- 'No email watermark',- 'AI projections',- 'Unlimited connected email accounts',- 'Calls',- 'Teams',- 'Team-level memory',- '100 GB storage',- ],- max: () => [- 'Everything in Pro',- '10x more AI usage than Pro',- 'Unlimited connected email accounts',- 'Team-level memory',- '1 TB storage',- 'Priority support',- ],-};--const PlanFeatures = (props: { tier: PlanTier; aiUsageEnabled: boolean }) => {- const allowance = () =>- props.aiUsageEnabled ? PLAN_USAGE_LABELS[props.tier] : undefined;- return (- <For each={BILLING_PLAN_FEATURES[props.tier](allowance())}>- {(label) => (- <li class="flex items-center gap-2">- <CheckIcon class="size-3 text-success" />- <span class="text-ink-muted text-xs">{label}</span>- </li>- )}- </For>- );-};--const PlanPrice = (props: {- tier: PaidPlanTier;- perSeat: boolean;- aiUsageEnabled: boolean;-}) => {- return (- <p class="text-ink-extra-muted text-xs">- ${PLAN_BY_TIER[props.tier].price}{' '}- {props.perSeat ? 'per seat / month' : '/ month'}- <Show when={props.aiUsageEnabled}>- <Show when={props.tier === 'max'}> · 10× usage</Show>- </Show>- </p>- );-};+import { BillingPlanCard, PlanFeatures } from './billing-plan-card';export function BillingSettingsView(props: {state: BillingState;@@ -216,69 +143,11 @@ export function BillingSettingsView(props: {)}>{(plan) => (- <SettingsCard class="@container/plan-card h-full">- <section class="flex h-full flex-col gap-4 p-5">- <header class="grid grid-cols-1 items-center gap-4 @sm/plan-card:grid-cols-[minmax(0,1fr)_auto]">- <div class="flex min-w-0 flex-col gap-1">- <div class="flex flex-wrap items-center gap-2">- <h3 class="text-lg font-medium text-ink">- {PLAN_BY_TIER[plan].name}- </h3>- <Show- when={!props.state.hasPaid && plan === 'premium'}- >- <span class="text-sm font-medium text-accent">- Free for one month!- </span>- </Show>- </div>- <PlanPrice- tier={plan}- perSeat={!!props.state.teamRole}- aiUsageEnabled={props.state.aiUsageEnabled}- />- </div>- <Button- class="w-full py-1.5 px-3 @sm/plan-card:w-auto @sm/plan-card:justify-self-end"- depth={2}- variant="cta"- disabled={props.state.pending}- onClick={() => props.onSelectPlan(plan)}- >- {props.state.hasPaid- ? plan === 'premium'- ? 'Switch to Pro'- : 'Upgrade to Max'- : plan === 'premium'- ? 'Get Pro'- : 'Get Max'}- </Button>- </header>- <ul class="border-t border-t-edge-muted pt-4 flex flex-col gap-3 text-sm text-ink-muted">- <PlanFeatures- tier={plan}- aiUsageEnabled={props.state.aiUsageEnabled}- />- </ul>- <Show- when={- props.state.hasPaid &&- (plan === 'max' || props.state.teamRole === 'owner')- }- >- <p class="text-xs text-ink-extra-muted">- <Show when={plan === 'max'}>- Prorated for the rest of this period.- </Show>- <Show when={props.state.teamRole === 'owner'}>- {' '}- This moves only your seat; teammates' plans are set- per seat in Team settings.- </Show>- </p>- </Show>- </section>- </SettingsCard>+ <BillingPlanCard+ plan={plan}+ state={props.state}+ onSelectPlan={props.onSelectPlan}+ />)}</For></div>diff --git a/apps/web/src/features/settings/views/billing-preview.tsx b/apps/web/src/features/settings/views/billing-preview.tsxindex 6bffb1602a..0bc456ca4b 100644--- a/apps/web/src/features/settings/views/billing-preview.tsx+++ b/apps/web/src/features/settings/views/billing-preview.tsx@@ -1,3 +1,5 @@+import { PaywallDialog } from '@app/features/paywall/components/paywall-dialog';+import { PaywallView } from '@app/features/paywall/components/paywall-view';import { PLAN_BY_TIER, type PlanTier } from '@app/features/paywall/plans';import { Button } from '@ui';import { createSignal, For, type JSX, Show } from 'solid-js';@@ -51,11 +53,12 @@ function PreviewCheckbox(props: {);}-/** Only loaded by Billing under the local HMR gate. No live billing capabilities. */+/** Only loaded by Billing under the local HMR gate. Billing previews simulate actions. */export function BillingPreview(props: {renderLive: (controls: JSX.Element) => JSX.Element;}) {const [active, setActive] = createSignal(false);+ const [paywallOpen, setPaywallOpen] = createSignal(false);const [account, setAccount] = createSignal<Account>('solo');const [plan, setPlan] = createSignal<PlanTier>('free');const [summaryStatus, setSummaryStatus] =@@ -67,7 +70,7 @@ export function BillingPreview(props: {const [action, setAction] = createSignal('');const state = () =>getBillingState({- hasPaid: hasPaid(),+ hasPaid: hasPaid() || (summaryStatus() === 'loaded' && plan() !== 'free'),canManageSubscription: permission(),teamRole:account() === 'solo'@@ -94,13 +97,130 @@ export function BillingPreview(props: {setAction('');};+ const previewControls = () => (+ <section aria-label="Billing preview" class="flex flex-col gap-4">+ <div class="flex flex-wrap items-center justify-between gap-3">+ <p class="text-sm text-ink-muted">+ Local preview · billing actions are simulated+ </p>+ <div class="flex flex-wrap gap-2">+ <Button+ size="sm"+ variant="outline"+ onClick={() => setPaywallOpen(true)}+ >+ Preview paywall+ </Button>+ <Button size="sm" variant="outline" onClick={reset}>+ Reset preview+ </Button>+ <Button+ size="sm"+ variant="outline"+ onClick={() => {+ reset();+ setPaywallOpen(false);+ setActive(false);+ }}+ >+ Exit preview+ </Button>+ </div>+ </div>+ <div class="grid grid-cols-1 gap-4 @sm:grid-cols-2">+ <PreviewSelect+ label="Account"+ value={account()}+ options={[+ { value: 'solo', label: 'Solo' },+ { value: 'team-member', label: 'Team member · team pays' },+ {+ value: 'self-paying-member',+ label: 'Team member · pays for own seat',+ },+ { value: 'team-owner', label: 'Team owner' },+ ]}+ onChange={(value) => {+ setAccount(value);+ setAction('');+ }}+ />+ <PreviewSelect+ label="Plan"+ value={plan()}+ options={(['free', 'premium', 'max'] as const).map((tier) => ({+ value: tier,+ label: PLAN_BY_TIER[tier].name,+ }))}+ onChange={(value) => {+ setPlan(value);+ setHasPaid(value !== 'free');+ setAction('');+ }}+ />+ </div>+ <details>+ <summary class="text-sm text-ink-muted">+ Permissions, loading, and feature states+ </summary>+ <div class="mt-3 flex flex-col gap-3">+ <PreviewSelect+ label="Billing summary"+ value={summaryStatus()}+ options={[+ { value: 'loaded', label: 'Loaded' },+ { value: 'loading', label: 'Loading' },+ { value: 'failed', label: 'Failed' },+ ]}+ onChange={setSummaryStatus}+ />+ <div class="flex flex-wrap gap-x-6">+ <PreviewCheckbox+ label="Billing permission"+ checked={permission()}+ onChange={setPermission}+ />+ <PreviewCheckbox+ label="Active or trialing license"+ checked={hasPaid()}+ onChange={setHasPaid}+ />+ <PreviewCheckbox+ label="AI usage billing enabled"+ checked={aiUsage()}+ onChange={setAiUsage}+ />+ <PreviewCheckbox+ label="Plan action pending"+ checked={pending()}+ onChange={setPending}+ />+ </div>+ </div>+ </details>+ <p role="status" class="text-xs text-ink-muted">+ {action() ||+ (state().canChangePlan+ ? 'Personal plan options available'+ : 'Personal plan options hidden')}+ </p>+ </section>+ );++ const selectPlan = (tier: 'premium' | 'max') =>+ setAction(+ `Preview only · ${state().tier === 'free' ? 'Checkout' : 'Change plan'}: ${PLAN_BY_TIER[tier].name}${state().tier === 'free' && tier === 'premium' ? ' · 30-day trial' : ''} · no billing changes made`+ );+ const manage = () =>+ setAction('Preview only · Manage subscription · no billing changes made');+return (<Showwhen={active()}fallback={props.renderLive(<div class="flex flex-wrap items-center gap-3"><Button size="sm" variant="outline" onClick={() => setActive(true)}>- Preview billing states+ Preview billing & paywall</Button><span class="text-xs text-ink-muted">Local development</span></div>@@ -108,117 +228,9 @@ export function BillingPreview(props: {><BillingSettingsViewstate={state()}- controls={- <section aria-label="Billing preview" class="flex flex-col gap-4">- <div class="flex flex-wrap items-center justify-between gap-3">- <p class="text-sm text-ink-muted">- Local preview · billing actions are simulated- </p>- <div class="flex flex-wrap gap-2">- <Button size="sm" variant="outline" onClick={reset}>- Reset preview- </Button>- <Button- size="sm"- variant="outline"- onClick={() => {- reset();- setActive(false);- }}- >- Exit preview- </Button>- </div>- </div>- <div class="grid grid-cols-1 gap-4 @sm:grid-cols-2">- <PreviewSelect- label="Account"- value={account()}- options={[- { value: 'solo', label: 'Solo' },- { value: 'team-member', label: 'Team member · team pays' },- {- value: 'self-paying-member',- label: 'Team member · pays for own seat',- },- { value: 'team-owner', label: 'Team owner' },- ]}- onChange={(value) => {- setAccount(value);- setAction('');- }}- />- <PreviewSelect- label="Plan"- value={plan()}- options={(['free', 'premium', 'max'] as const).map((tier) => ({- value: tier,- label: PLAN_BY_TIER[tier].name,- }))}- onChange={(value) => {- setPlan(value);- setHasPaid(value !== 'free');- setAction('');- }}- />- </div>- <details>- <summary class="text-sm text-ink-muted">- Permissions, loading, and feature states- </summary>- <div class="mt-3 flex flex-col gap-3">- <PreviewSelect- label="Billing summary"- value={summaryStatus()}- options={[- { value: 'loaded', label: 'Loaded' },- { value: 'loading', label: 'Loading' },- { value: 'failed', label: 'Failed' },- ]}- onChange={setSummaryStatus}- />- <div class="flex flex-wrap gap-x-6">- <PreviewCheckbox- label="Billing permission"- checked={permission()}- onChange={setPermission}- />- <PreviewCheckbox- label="Active or trialing license"- checked={hasPaid()}- onChange={setHasPaid}- />- <PreviewCheckbox- label="AI usage billing enabled"- checked={aiUsage()}- onChange={setAiUsage}- />- <PreviewCheckbox- label="Plan action pending"- checked={pending()}- onChange={setPending}- />- </div>- </div>- </details>- <p role="status" class="text-xs text-ink-muted">- {action() ||- (state().canChangePlan- ? 'Personal plan options available'- : 'Personal plan options hidden')}- </p>- </section>- }- onManage={() =>- setAction(- 'Preview only · Manage subscription · no billing changes made'- )- }- onSelectPlan={(tier) =>- setAction(- `Preview only · ${hasPaid() ? 'Change plan' : 'Checkout'}: ${PLAN_BY_TIER[tier].name} · no billing changes made`- )- }+ controls={previewControls()}+ onManage={manage}+ onSelectPlan={selectPlan}onTeamSettings={(event) => {event.preventDefault();setAction(@@ -226,6 +238,33 @@ export function BillingPreview(props: {);}}/>+ <Show when={paywallOpen()}>+ <PaywallDialog+ open={paywallOpen()}+ onClose={() => setPaywallOpen(false)}+ >+ <PaywallView+ state={{ ...state(), hasPaid: state().tier !== 'free' }}+ availability={+ summaryStatus() === 'loaded'+ ? 'ready'+ : summaryStatus() === 'loading'+ ? 'loading'+ : 'error'+ }+ onManagePlan={() => {+ setPaywallOpen(false);+ }}+ onDismiss={() => {+ setPaywallOpen(false);+ }}+ onRetry={() => {+ setSummaryStatus('loaded');+ setAction('Preview only · Retried billing summary');+ }}+ />+ </PaywallDialog>+ </Show></Show>);}diff --git a/docs/AGENT_GUIDE/surfaces.md b/docs/AGENT_GUIDE/surfaces.mdindex c1d10fe33a..03999cfd0d 100644--- a/docs/AGENT_GUIDE/surfaces.md+++ b/docs/AGENT_GUIDE/surfaces.md@@ -2272,14 +2272,25 @@ on Free seats. Member options stay hidden until the billing summary confirmsthey pay for their own seat. On a team, a plan change moves only the viewer'sown seat. Max lists "10x more AI usage than Pro"; Free and Pro allowance labelsstill follow the `enable-ai-usage-billing` flag. Usage controls live in Usage.--On a local HMR dev server, `Preview billing states` opens an opt-in preview in+The upgrade modal and Billing use the same plan cards and benefits, including+the same flag-gated AI usage label and responsive card layout. The modal offers+Pro and Max to Free accounts, only Max to Pro accounts, and no upgrade cards to+Max accounts. Cards in the modal show benefits without purchase buttons. The footer’s+`Manage plan` closes the modal and opens Billing settings, where checkout and+plan changes take place. Team-paid members see a message+to contact their team owner. Plan options wait for the billing summary and team+lookup; failed lookups show `Try again` rather than guessed upgrade options.++On a local HMR dev server, `Preview billing & paywall` opens an opt-in preview inBilling. Choose Solo, a team-paid member, a self-paying member, or a team owner,and Free, Pro, or Max. `Permissions, loading, and feature states` exposes thebilling summary status, billing permission, active/trialing license, AI usageflag, and pending plan actions. The preview uses the real Billing UI with localfixtures; checkout, plan changes, Manage, and Team settings only show preview-status messages. `Reset preview` restores Solo/Free; `Exit preview` restores+status messages. `Preview paywall` opens the same modal for the selected state,+without developer controls inside it. Dismissing the modal returns to Billing+with the selection preserved. `Manage plan` returns to the selected Billing preview.+`Reset preview` restores Solo/Free; `Exit preview` restoresthe signed-in account. State is not persisted and resets on leaving Billing.These controls are excluded from deployed builds, including dev.macro.com.