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.

feat(settings): show current plan card on the account page (#8015)

teoabb8f0a98bdd
diff --git a/apps/web/src/features/settings/Account.tsx b/apps/web/src/features/settings/Account.tsx
index 81eed1b0c4..c082d2f27b 100644
--- a/apps/web/src/features/settings/Account.tsx
+++ b/apps/web/src/features/settings/Account.tsx
@@ -1,6 +1,7 @@
import { useAnalytics } from '@app/lib/analytics/analytics-context';
import type { AccountDeletionReason } from '@app/lib/analytics/app-events';
import { useFeatureFlag } from '@app/lib/analytics/posthog';
+import { useHasPaidAccess } from '@core/auth';
import { useLogout } from '@core/auth/logout';
import { toast } from '@core/component/Toast/Toast';
import { UserIcon } from '@core/component/UserIcon';
@@ -13,7 +14,9 @@ import {
ENABLE_PROFILE_PICTURES,
enableAutoUpdateUiOverride,
} from '@core/constant/featureFlags';
+import { useSettingsState } from '@core/constant/SettingsState';
import { staticFileIdEndpoint } from '@core/constant/servers';
+import { useSettingsTabAvailable } from '@core/constant/settingsTabsConfig';
import { useEmail, useUserId } from '@core/context/user';
import { isNativeMobilePlatform } from '@core/mobile/isNativeMobilePlatform';
import { isTouchDevice } from '@core/mobile/isTouchDevice';
@@ -35,6 +38,7 @@ import TrashIcon from '@phosphor/trash.svg';
import WarningCircleIcon from '@phosphor/warning-circle.svg';
import SignOutIcon from '@phosphor-icons/core/regular/sign-out.svg?component-solid';
import IconUpload from '@phosphor-icons/core/regular/upload-simple.svg?component-solid';
+import { useAiBillingSummaryQuery } from '@queries/auth';
import {
invalidateOwnUserName,
useOwnUserName,
@@ -61,6 +65,8 @@ import {
buildAccountDeletionFeedbackPayload,
performAccountDeletion,
} from './account-deletion-feedback';
+import { CurrentPlanCard } from './components/current-plan-card';
+import { resolvePlanTier } from './core/billing-state';
import {
SettingsCard,
SettingsPage,
@@ -308,12 +314,32 @@ function ProfilePictureRow(props: { userId: string }) {
);
}
+function AccountPlanCard() {
+ const { openSettings } = useSettingsState();
+ const hasPaid = useHasPaidAccess();
+ const summary = useAiBillingSummaryQuery();
+ // Wait for the summary before falling back to the license, so a Max plan
+ // doesn't flash as Pro while it loads.
+ const tier = () =>
+ summary.isFetching && !summary.isSuccess
+ ? undefined
+ : resolvePlanTier(
+ summary.isSuccess ? summary.data.tier : undefined,
+ hasPaid()
+ );
+
+ return (
+ <CurrentPlanCard tier={tier()} onOpen={() => openSettings('Billing')} />
+ );
+}
+
// Not accessible if user is not authenticated
export function Account() {
const analytics = useAnalytics();
const email = useEmail();
const userId = useUserId();
const logout = useLogout();
+ const isSettingsTabAvailable = useSettingsTabAvailable();
const disableAutoUpdateUIFlag = useFeatureFlag(disableAutoUpdateUi);
const autoUpdateUIEnabled = createMemo(
() => enableAutoUpdateUiOverride ?? !disableAutoUpdateUIFlag().enabled
@@ -456,6 +482,10 @@ export function Account() {
</SettingsCard>
</SettingsSection>
+ <Show when={isSettingsTabAvailable('Billing')}>
+ <AccountPlanCard />
+ </Show>
+
<Show when={isTouchDevice()}>
<SettingsSection>
<SettingsCard>
diff --git a/apps/web/src/features/settings/components/current-plan-card.test.tsx b/apps/web/src/features/settings/components/current-plan-card.test.tsx
new file mode 100644
index 0000000000..df0eb0478a
--- /dev/null
+++ b/apps/web/src/features/settings/components/current-plan-card.test.tsx
@@ -0,0 +1,32 @@
+import type { PlanTier } from '@app/features/paywall/plans';
+import { cleanup, fireEvent, render, screen } from '@solidjs/testing-library';
+import { createSignal } from 'solid-js';
+import { afterEach, expect, it, vi } from 'vitest';
+import { CurrentPlanCard } from './current-plan-card';
+
+afterEach(cleanup);
+
+it.each<[PlanTier, string]>([
+ ['free', 'Free plan'],
+ ['premium', 'Pro plan'],
+ ['max', 'Max plan'],
+])('shows the %s tier by its display name', (tier, label) => {
+ render(() => <CurrentPlanCard tier={tier} onOpen={() => {}} />);
+ expect(screen.getByRole('button', { name: new RegExp(label) })).toBeTruthy();
+});
+
+it('shows a loading label until the tier resolves, then the plan', () => {
+ const [tier, setTier] = createSignal<PlanTier>();
+ render(() => <CurrentPlanCard tier={tier()} onOpen={() => {}} />);
+ expect(screen.getByText('Loading plan…')).toBeTruthy();
+ setTier('max');
+ expect(screen.queryByText('Loading plan…')).toBeNull();
+ expect(screen.getByText('Max plan')).toBeTruthy();
+});
+
+it('opens billing when the card is clicked', () => {
+ const open = vi.fn();
+ render(() => <CurrentPlanCard tier="premium" onOpen={open} />);
+ fireEvent.click(screen.getByRole('button', { name: /Pro plan/ }));
+ expect(open).toHaveBeenCalledOnce();
+});
diff --git a/apps/web/src/features/settings/components/current-plan-card.tsx b/apps/web/src/features/settings/components/current-plan-card.tsx
new file mode 100644
index 0000000000..dcd14a7eed
--- /dev/null
+++ b/apps/web/src/features/settings/components/current-plan-card.tsx
@@ -0,0 +1,34 @@
+import { PLAN_BY_TIER, type PlanTier } from '@app/features/paywall/plans';
+import CaretRightIcon from '@phosphor/caret-right.svg';
+import CreditCardIcon from '@phosphor/credit-card.svg';
+import { Show } from 'solid-js';
+import { IntegrationRow, SettingsCard } from '../primitives';
+
+/** The current plan as a card that opens Billing settings. */
+export function CurrentPlanCard(props: {
+ /** Undefined while the plan is loading. */
+ tier?: PlanTier;
+ onOpen: () => void;
+}) {
+ return (
+ <SettingsCard>
+ <button
+ type="button"
+ class="w-full rounded-[inherit] text-left outline-none hover:bg-ink/4 focus-visible:bg-ink/6 focus-visible:inset-ring-2 focus-visible:inset-ring-accent"
+ onClick={() => props.onOpen()}
+ >
+ <IntegrationRow
+ icon={<CreditCardIcon />}
+ title={
+ <Show when={props.tier} fallback="Loading plan…">
+ {(tier) => `${PLAN_BY_TIER[tier()].name} plan`}
+ </Show>
+ }
+ description="See your plan and billing details"
+ >
+ <CaretRightIcon class="size-4 text-ink-extra-muted" />
+ </IntegrationRow>
+ </button>
+ </SettingsCard>
+ );
+}
diff --git a/apps/web/src/features/settings/core/billing-state.test.ts b/apps/web/src/features/settings/core/billing-state.test.ts
index f45791cbe4..09978c9524 100644
--- a/apps/web/src/features/settings/core/billing-state.test.ts
+++ b/apps/web/src/features/settings/core/billing-state.test.ts
@@ -5,6 +5,7 @@ import {
describeSeatPlans,
getBillingState,
getFreePlanCheckoutRequest,
+ resolvePlanTier,
} from './billing-state';
const baseline: BillingInput = {
@@ -82,6 +83,18 @@ describe('billing presentation policy', () => {
).toBe('max');
});
+ it.each<[PlanTier | undefined, boolean, PlanTier]>([
+ ['max', false, 'max'],
+ ['free', true, 'free'],
+ [undefined, true, 'premium'],
+ [undefined, false, 'free'],
+ ])(
+ 'resolves summary tier %s with paid access %s to %s',
+ (summaryTier, hasPaid, expected) => {
+ expect(resolvePlanTier(summaryTier, hasPaid)).toBe(expected);
+ }
+ );
+
it('describes mixed seat plans without conflating Pro and Max', () => {
expect(describeSeatPlans(['premium', 'premium', 'max'])).toBe(
'2 Pro seats, 1 Max seat'
diff --git a/apps/web/src/features/settings/core/billing-state.ts b/apps/web/src/features/settings/core/billing-state.ts
index 67afdf7a97..a099385f54 100644
--- a/apps/web/src/features/settings/core/billing-state.ts
+++ b/apps/web/src/features/settings/core/billing-state.ts
@@ -10,9 +10,17 @@ export type BillingInput = {
pending: boolean;
};
+/** The billing summary's tier wins; without it, paid access implies Pro. */
+export function resolvePlanTier(
+ summaryTier: PlanTier | undefined,
+ hasPaid: boolean
+): PlanTier {
+ return summaryTier ?? (hasPaid ? 'premium' : 'free');
+}
+
/** Shared presentation policy for live billing and local previews. */
export function getBillingState(input: BillingInput) {
- const tier = input.summary?.tier ?? (input.hasPaid ? 'premium' : 'free');
+ const tier = resolvePlanTier(input.summary?.tier, input.hasPaid);
const billedThroughTeam = input.summary?.canManageBilling === false;
const isOwnerOrSolo =
!input.teamRole ||
diff --git a/docs/AGENT_GUIDE/surfaces.md b/docs/AGENT_GUIDE/surfaces.md
index 1376bd11e9..df27c9a94a 100644
--- a/docs/AGENT_GUIDE/surfaces.md
+++ b/docs/AGENT_GUIDE/surfaces.md
@@ -2424,6 +2424,10 @@ update also installs on normal app quit. Closing a window only triggers
installation if it exits the app. Browser, mobile, and development builds do not
show this native updater row.
+Below Profile, **Account** shows a card naming the current plan (**Free plan**,
+**Pro plan**, or **Max plan**; **Loading plan…** until the billing summary
+arrives). Clicking it opens **Billing** settings.
+
Left nav (feature and platform gates still apply):
- **Blocks**: Email, Calendar, Agents, CRM.