Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

chore(paywall): remove legacy plans and refactor (#3791)

dev-rb13fb3fd5437c
diff --git a/js/app/packages/app/component/paywall/PaywallComponent.tsx b/js/app/packages/app/component/paywall/PaywallComponent.tsx
index 56d1b69b0e..2e34569471 100644
--- a/js/app/packages/app/component/paywall/PaywallComponent.tsx
+++ b/js/app/packages/app/component/paywall/PaywallComponent.tsx
@@ -1,5 +1,16 @@
-import type { PaywallKey } from '@core/constant/PaywallState';
-import PaywallComponentNew from './PaywallComponentNew';
+import { useAnalytics } from '@app/component/analytics-context';
+import {
+ PLAN_FEATURES,
+ PLANS,
+ type PlanTier,
+} from '@app/component/paywall/plans';
+import SubscriptionTier from '@app/component/paywall/SubscriptionTier';
+import { useHasPaidAccess } from '@core/auth';
+import { type PaywallKey, PaywallMessages } from '@core/constant/PaywallState';
+import IconX from '@phosphor/x.svg';
+import { stripeServiceClient } from '@service-stripe/client';
+import { Button, cn } from '@ui';
+import { createMemo, createSignal, For, Show } from 'solid-js';
export interface PaywallProps {
cb: () => Promise<void> | void;
@@ -10,8 +21,170 @@ export interface PaywallProps {
hideCloseButton?: boolean;
}
-const PaywallComponent = (props: PaywallProps) => (
- <PaywallComponentNew {...props} />
-);
+const PaywallComponent = (props: PaywallProps) => {
+ const analytics = useAnalytics();
+ const hasPaid = useHasPaidAccess();
+
+ const currentTier = createMemo<PlanTier>(() =>
+ hasPaid() ? 'premium' : 'free'
+ );
+
+ // `userSelectedTier` is only set when the user explicitly clicks a plan card. Until
+ // then the UI reflects `currentTier`. This avoids mirroring derived state into a signal
+ // via `createEffect` and sidesteps the briefly-wrong-card window before permissions resolve.
+ const [userSelectedTier, setUserSelectedTier] = createSignal<PlanTier | null>(
+ null
+ );
+ const selectedTier = createMemo<PlanTier>(
+ () => userSelectedTier() ?? currentTier()
+ );
+
+ 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 manageSubscription = async () => {
+ try {
+ const url = await stripeServiceClient.createPortalSession();
+ window.location.href = url;
+ } catch (error) {
+ console.error(error);
+ }
+ };
+
+ const handleContinue = () => {
+ const tier = selectedTier();
+ // Paid users go to the Stripe portal regardless of selection — that's where
+ // they cancel (downgrade to free) or manage billing on premium.
+ if (hasPaid()) {
+ manageSubscription();
+ return;
+ }
+ if (tier === 'free') {
+ props.handleGuest?.();
+ return;
+ }
+ handleCheckout();
+ };
+
+ const ctaLabel = () => {
+ if (hasPaid()) {
+ return selectedTier() === 'free' ? 'Downgrade' : 'Manage Subscription';
+ }
+ if (selectedTier() === 'free') return 'Continue with Free';
+ return 'Get Premium';
+ };
+
+ return (
+ <div class="relative space-y-2 w-full">
+ <Show when={!props.hideCloseButton}>
+ <button
+ onClick={props.cb}
+ class="absolute -top-2 -right-2 sm:-top-3 sm:-right-3 text-ink-extra-muted hover:text-ink transition-colors z-10"
+ >
+ <IconX class="size-5 sm:size-6" />
+ </button>
+ </Show>
+ <Show when={!hasPaid()}>
+ <div class="relative w-full text-center">
+ <div class="space-y-6 sm:space-y-8">
+ <div class="text-center">
+ <h2 class="mb-2 font-semibold text-ink text-xl sm:text-2xl">
+ Choose your plan
+ </h2>
+ <Show when={props.errorKey}>
+ <p class="mb-4 text-failure-ink text-sm sm:text-base">
+ {PaywallMessages[props.errorKey as PaywallKey]}
+ </p>
+ </Show>
+ </div>
+ </div>
+ </div>
+ </Show>
+
+ <div class="w-full @container">
+ <div class="gap-2 grid grid-cols-1 @[400px]:grid-cols-2">
+ <For each={PLANS}>
+ {(plan) => (
+ <button
+ onClick={() => setUserSelectedTier(plan.tier)}
+ class={cn(
+ selectedTier() === plan.tier
+ ? 'border-accent bg-active'
+ : 'border-edge hover:border-edge',
+ 'p-4 sm:p-5 border flex flex-col transition-all relative text-left rounded-sm'
+ )}
+ >
+ <div class="flex flex-col gap-3 w-full">
+ <div class="flex justify-between items-start">
+ <div class="flex items-center gap-2">
+ <div class="font-semibold text-ink text-base sm:text-lg">
+ {plan.name}
+ </div>
+ <Show when={currentTier() === plan.tier}>
+ <span class="text-xs text-ink/60 px-1.5 py-0.5 border border-edge-muted rounded">
+ Current
+ </span>
+ </Show>
+ </div>
+ <SubscriptionTier
+ class="w-7 shrink-0"
+ tier={plan.tier === 'premium' ? 'premium' : undefined}
+ />
+ </div>
+ <div class="flex items-baseline gap-0.5">
+ <span class="text-3xl font-bold text-ink">
+ ${plan.price}
+ </span>
+ <span class="text-base text-ink/40">/mo</span>
+ </div>
+ <div class="text-sm text-ink/60 flex flex-col gap-1">
+ <For each={PLAN_FEATURES}>
+ {(feature) => (
+ <span>
+ {feature.label}: {feature.values[plan.tier]}
+ </span>
+ )}
+ </For>
+ </div>
+ </div>
+ </button>
+ )}
+ </For>
+ </div>
+ </div>
+
+ <div class="w-full">
+ <Button
+ onClick={handleContinue}
+ variant="base"
+ size="lg"
+ depth={3}
+ class="w-full"
+ disabled={
+ !hasPaid() && selectedTier() === 'free' && !props.handleGuest
+ }
+ >
+ {ctaLabel()}
+ </Button>
+ </div>
+ </div>
+ );
+};
export default PaywallComponent;
diff --git a/js/app/packages/app/component/paywall/PaywallComponentNew.tsx b/js/app/packages/app/component/paywall/PaywallComponentNew.tsx
deleted file mode 100644
index 204e0129eb..0000000000
--- a/js/app/packages/app/component/paywall/PaywallComponentNew.tsx
+++ /dev/null
@@ -1,178 +0,0 @@
-import { useAnalytics } from '@app/component/analytics-context';
-import { useHasPaidAccess } from '@core/auth';
-import { type PaywallKey, PaywallMessages } from '@core/constant/PaywallState';
-import IconX from '@phosphor/x.svg';
-import { stripeServiceClient } from '@service-stripe/client';
-import { Button, cn } from '@ui';
-import { createMemo, createSignal, For, Show } from 'solid-js';
-import type { PaywallProps } from './PaywallComponent';
-import { NEW_PLANS, PLAN_FEATURES, type PlanTier } from './plans';
-import SubscriptionTier from './SubscriptionTier';
-
-const PaywallComponentNew = (props: PaywallProps) => {
- const analytics = useAnalytics();
- const hasPaid = useHasPaidAccess();
-
- const currentTier = createMemo<PlanTier>(() =>
- hasPaid() ? 'premium' : 'free'
- );
-
- // `userSelectedTier` is only set when the user explicitly clicks a plan card. Until
- // then the UI reflects `currentTier`. This avoids mirroring derived state into a signal
- // via `createEffect` and sidesteps the briefly-wrong-card window before permissions resolve.
- const [userSelectedTier, setUserSelectedTier] = createSignal<PlanTier | null>(
- null
- );
- const selectedTier = createMemo<PlanTier>(
- () => userSelectedTier() ?? currentTier()
- );
-
- 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 manageSubscription = async () => {
- try {
- const url = await stripeServiceClient.createPortalSession();
- window.location.href = url;
- } catch (error) {
- console.error(error);
- }
- };
-
- const handleContinue = () => {
- const tier = selectedTier();
- // Paid users go to the Stripe portal regardless of selection — that's where
- // they cancel (downgrade to free) or manage billing on premium.
- if (hasPaid()) {
- manageSubscription();
- return;
- }
- if (tier === 'free') {
- props.handleGuest?.();
- return;
- }
- handleCheckout();
- };
-
- const ctaLabel = () => {
- if (hasPaid()) {
- return selectedTier() === 'free' ? 'Downgrade' : 'Manage Subscription';
- }
- if (selectedTier() === 'free') return 'Continue with Free';
- return 'Get Premium';
- };
-
- return (
- <div class="relative space-y-2 w-full">
- <Show when={!props.hideCloseButton}>
- <button
- onClick={props.cb}
- class="absolute -top-2 -right-2 sm:-top-3 sm:-right-3 text-ink-extra-muted hover:text-ink transition-colors z-10"
- >
- <IconX class="size-5 sm:size-6" />
- </button>
- </Show>
- <Show when={!hasPaid()}>
- <div class="relative w-full text-center">
- <div class="space-y-6 sm:space-y-8">
- <div class="text-center">
- <h2 class="mb-2 font-semibold text-ink text-xl sm:text-2xl">
- Choose your plan
- </h2>
- <Show when={props.errorKey}>
- <p class="mb-4 text-failure-ink text-sm sm:text-base">
- {PaywallMessages[props.errorKey as PaywallKey]}
- </p>
- </Show>
- </div>
- </div>
- </div>
- </Show>
-
- <div class="w-full @container">
- <div class="gap-2 grid grid-cols-1 @[400px]:grid-cols-2">
- <For each={NEW_PLANS}>
- {(plan) => (
- <button
- onClick={() => setUserSelectedTier(plan.tier)}
- class={cn(
- selectedTier() === plan.tier
- ? 'border-accent bg-active'
- : 'border-edge hover:border-edge',
- 'p-4 sm:p-5 border flex flex-col transition-all relative text-left rounded-sm'
- )}
- >
- <div class="flex flex-col gap-3 w-full">
- <div class="flex justify-between items-start">
- <div class="flex items-center gap-2">
- <div class="font-semibold text-ink text-base sm:text-lg">
- {plan.name}
- </div>
- <Show when={currentTier() === plan.tier}>
- <span class="text-xs text-ink/60 px-1.5 py-0.5 border border-edge-muted rounded">
- Current
- </span>
- </Show>
- </div>
- <SubscriptionTier
- class="w-7 shrink-0"
- tier={plan.tier === 'premium' ? 'premium' : undefined}
- />
- </div>
- <div class="flex items-baseline gap-0.5">
- <span class="text-3xl font-bold text-ink">
- ${plan.price}
- </span>
- <span class="text-base text-ink/40">/mo</span>
- </div>
- <div class="text-sm text-ink/60 flex flex-col gap-1">
- <For each={PLAN_FEATURES}>
- {(feature) => (
- <span>
- {feature.label}: {feature.values[plan.tier]}
- </span>
- )}
- </For>
- </div>
- </div>
- </button>
- )}
- </For>
- </div>
- </div>
-
- <div class="w-full">
- <Button
- onClick={handleContinue}
- variant="base"
- size="lg"
- depth={3}
- class="w-full"
- disabled={
- !hasPaid() && selectedTier() === 'free' && !props.handleGuest
- }
- >
- {ctaLabel()}
- </Button>
- </div>
- </div>
- );
-};
-
-export default PaywallComponentNew;
diff --git a/js/app/packages/app/component/paywall/PaywallTeamOwnerView.tsx b/js/app/packages/app/component/paywall/PaywallTeamOwnerView.tsx
index eab1976bfc..2479499f33 100644
--- a/js/app/packages/app/component/paywall/PaywallTeamOwnerView.tsx
+++ b/js/app/packages/app/component/paywall/PaywallTeamOwnerView.tsx
@@ -1,16 +1,16 @@
+import { PLANS } from '@app/component/paywall/plans';
import { useTeamQuery } from '@queries/team';
import type { Team } from '@service-auth/generated/schemas/team';
import { stripeServiceClient } from '@service-stripe/client';
import { Button } from '@ui';
import { createMemo } from 'solid-js';
-import { NEW_PLANS } from './plans';
import SubscriptionTier from './SubscriptionTier';
interface PaywallTeamOwnerViewProps {
team: Team;
}
-const PREMIUM_PRICE = NEW_PLANS.find((p) => p.tier === 'premium')!.price;
+const PREMIUM_PRICE = PLANS.find((p) => p.tier === 'premium')!.price;
const PaywallTeamOwnerView = (props: PaywallTeamOwnerViewProps) => {
const teamQuery = useTeamQuery(() => props.team.id);
diff --git a/js/app/packages/app/component/paywall/SubscriptionTier.tsx b/js/app/packages/app/component/paywall/SubscriptionTier.tsx
index 97353d096e..9a2345687a 100644
--- a/js/app/packages/app/component/paywall/SubscriptionTier.tsx
+++ b/js/app/packages/app/component/paywall/SubscriptionTier.tsx
@@ -6,8 +6,8 @@ interface SubscriptionTierProps {
}
const SubscriptionTier = (props: SubscriptionTierProps) => {
- const active1 = () => props.tier === 'opus';
- const active2 = () => props.tier === 'opus' || props.tier === 'sonnet';
+ const active1 = () => props.tier === 'premium';
+ const active2 = () => props.tier === 'premium';
const active3 = () => !!props.tier;
return (
diff --git a/js/app/packages/app/component/paywall/plans.ts b/js/app/packages/app/component/paywall/plans.ts
index 8e260dcb8e..3d12773155 100644
--- a/js/app/packages/app/component/paywall/plans.ts
+++ b/js/app/packages/app/component/paywall/plans.ts
@@ -1,33 +1,14 @@
-const FREE_PLAN = {
- tier: 'free' as const,
- name: 'Level 0',
- price: 0,
- highlighted: false,
+export type PlanTier = 'free' | 'premium';
+export type Plan = {
+ tier: PlanTier;
+ name: string;
+ price: number;
+ highlighted: boolean;
};
+/** Tiers that correspond to real Stripe products. Excludes 'free'. */
+export type PaidPlanTier = Exclude<PlanTier, 'free'>;
-export const LEGACY_PLANS = [
- { ...FREE_PLAN },
- {
- tier: 'haiku' as const,
- name: 'Level 1',
- price: 20,
- highlighted: false,
- },
- {
- tier: 'sonnet' as const,
- name: 'Level 2',
- price: 60,
- highlighted: false,
- },
- {
- tier: 'opus' as const,
- name: 'Level 3',
- price: 120,
- highlighted: true,
- },
-] as const;
-
-export const NEW_PLANS = [
+export const PLANS = [
{
tier: 'free' as const,
name: 'Free',
@@ -40,25 +21,7 @@ export const NEW_PLANS = [
price: 40,
highlighted: true,
},
-] as const;
-
-export type PlanTier = 'free' | 'haiku' | 'sonnet' | 'opus' | 'premium';
-export type Plan = {
- tier: PlanTier;
- name: string;
- price: number;
- highlighted: boolean;
-};
-/** Tiers that correspond to real Stripe products. Excludes 'free'. */
-export type PaidPlanTier = Exclude<PlanTier, 'free'>;
-
-/**
- * Default plan list used for tier lookups in onboarding flows. The paywall
- * components import {LEGACY_PLANS, NEW_PLANS} directly based on the
- * runtime feature flag; everywhere else, PLANS provides a stable catalog
- * for `.find(p => p.tier === ...)` lookups.
- */
-export const PLANS: readonly Plan[] = LEGACY_PLANS;
+] as const satisfies Plan[];
interface PlanFeature {
label: string;
@@ -70,19 +33,13 @@ export const PLAN_FEATURES: PlanFeature[] = [
label: 'AI Tool Calls',
values: {
free: '—',
- haiku: '1,000',
- sonnet: '5,000',
- opus: 'Unlimited',
premium: 'Unlimited',
},
},
{
label: 'AI Agent',
values: {
- free: '—',
- haiku: 'Haiku',
- sonnet: 'Sonnet',
- opus: 'Opus',
+ free: 'Haiku',
premium: 'All models',
},
},
@@ -90,9 +47,6 @@ export const PLAN_FEATURES: PlanFeature[] = [
label: 'Storage',
values: {
free: '5 GB',
- haiku: '25 GB',
- sonnet: '100 GB',
- opus: '1 TB',
premium: '1 TB',
},
},
diff --git a/js/app/packages/app/component/teams/TierSelect.tsx b/js/app/packages/app/component/teams/TierSelect.tsx
deleted file mode 100644
index d5b740ac10..0000000000
--- a/js/app/packages/app/component/teams/TierSelect.tsx
+++ /dev/null
@@ -1,92 +0,0 @@
-import { type PaidPlanTier, PLAN_FEATURES } from '@app/component/paywall/plans';
-import type { CollectionNode } from '@kobalte/core';
-import { Select } from '@kobalte/core/select';
-import CaretDownIcon from '@phosphor/caret-down.svg';
-import CheckIcon from '@phosphor/check.svg';
-import type { ValidComponent } from 'solid-js';
-
-type TierOption = { value: PaidPlanTier; label: string; description: string };
-
-const getTierDescription = (tier: PaidPlanTier): string => {
- const aiAgent =
- PLAN_FEATURES.find((f) => f.label === 'AI Agent')?.values[tier] ?? '';
- const aiCalls =
- PLAN_FEATURES.find((f) => f.label === 'AI tool calls')?.values[tier] ?? '';
- const storage =
- PLAN_FEATURES.find((f) => f.label === 'Storage')?.values[tier] ?? '';
- return `${aiAgent} · ${aiCalls} calls · ${storage}`;
-};
-
-const tierOptions: TierOption[] = [
- {
- value: 'haiku',
- label: 'Level 1',
- description: getTierDescription('haiku'),
- },
- {
- value: 'sonnet',
- label: 'Level 2',
- description: getTierDescription('sonnet'),
- },
- { value: 'opus', label: 'Level 3', description: getTierDescription('opus') },
-];
-
-export function TierSelect(props: {
- value: PaidPlanTier;
- onChange: (tier: PaidPlanTier) => void;
- triggerClass?: string;
- triggerAs?: ValidComponent;
- disabled?: boolean;
-}) {
- const selectedOption = () =>
- tierOptions.find((o) => o.value === props.value) ?? tierOptions[0];
-
- return (
- <Select<TierOption>
- options={tierOptions}
- value={selectedOption()}
- onChange={(opt) => opt && props.onChange(opt.value)}
- optionValue="value"
- optionTextValue="label"
- gutter={4}
- placement="bottom-end"
- disabled={props.disabled}
- itemComponent={(itemProps: { item: CollectionNode<TierOption> }) => (
- <Select.Item
- item={itemProps.item}
- class="flex items-center justify-between gap-2 px-2 py-1.5 text-sm rounded-xs hover:bg-hover/50 outline-none data-highlighted:bg-hover bracket-never"
- >
- <div class="flex flex-col">
- <Select.ItemLabel>{itemProps.item.rawValue.label}</Select.ItemLabel>
- <span class="text-xs text-ink/50">
- {itemProps.item.rawValue.description}
- </span>
- </div>
- <Select.ItemIndicator>
- <CheckIcon class="size-3" />
- </Select.ItemIndicator>
- </Select.Item>
- )}
- >
- <Select.Trigger
- as={props.triggerAs}
- tabIndex={0}
- class={
- props.triggerClass ??
- 'rounded-xs px-2 py-1 text-xs data-expanded:bg-ink/10'
- }
- disabled={props.disabled}
- >
- <Select.Value<TierOption>>
- {(state) => state.selectedOption().label}
- </Select.Value>
- <CaretDownIcon class="size-3 text-ink-muted shrink-0" />
- </Select.Trigger>
- <Select.Portal>
- <Select.Content class="flex flex-col justify-start items-start bg-surface shadow-lg ring-1 ring-edge-muted rounded-sm p-1 cursor-default select-none max-w-full max-h-[calc(100dvh-10rem)] overflow-y-auto z-modal">
- <Select.Listbox />
- </Select.Content>
- </Select.Portal>
- </Select>
- );
-}