From b9eaaac79abc95a890696ae858c909a0f5b96000 Mon Sep 17 00:00:00 2001 From: mehfuz Date: Wed, 18 Nov 2026 19:10:49 -0800 Subject: [PATCH] Show the plan paid for in billing; add the Max plan Billing, /upgrade, the account menu and the profile badge read the API's new billing_plan: the plan the account pays for. Admin and hand-granted premium accounts with no subscription now show Free and can buy a plan (an admin's 'admin' plan outranked every card, so it could never upgrade). Model access still follows is_paid/is_premium. Max is added to the purchasable plans, plan ranks, cards and labels. --- src/app/cloud-models/shared.ts | 4 +++- src/app/components/account-menu.tsx | 3 ++- src/app/profile/page.tsx | 3 ++- src/app/services/user.service.js | 4 ++++ src/app/settings/sections/billing.tsx | 8 +++++--- src/app/settings/sections/credits.tsx | 3 ++- src/app/settings/sections/websearch.tsx | 13 ++++++++----- src/app/shared/utils.ts | 8 ++++++-- src/app/upgrade/page.tsx | 6 ++++-- 9 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/app/cloud-models/shared.ts b/src/app/cloud-models/shared.ts index 5cd5c10..4b51e60 100644 --- a/src/app/cloud-models/shared.ts +++ b/src/app/cloud-models/shared.ts @@ -36,7 +36,7 @@ export interface CloudQuota { /** YYYY-MM. */ period: string; resets_at: string; - plan: 'free' | 'paid' | 'admin'; + plan: 'free' | 'paid' | 'plus' | 'max' | 'admin'; } /** Why cloud models can't run right now, from GET /v1/chat/status. @@ -52,6 +52,8 @@ export interface CloudStatus { export const PLAN_LABEL: Record = { free: 'Free', paid: 'Pro', + plus: 'Plus', + max: 'Max', admin: 'Admin', }; diff --git a/src/app/components/account-menu.tsx b/src/app/components/account-menu.tsx index 7add096..faa59f9 100644 --- a/src/app/components/account-menu.tsx +++ b/src/app/components/account-menu.tsx @@ -14,6 +14,7 @@ import { Box, Menu, MenuItem } from '@mui/material'; import LogoutIcon from '@mui/icons-material/Logout'; import PersonOutlineIcon from '@mui/icons-material/PersonOutline'; import { userService } from '@/app/services/user.service'; +import { BILLING_PLAN_LABEL } from '@/app/shared/utils'; export default function AccountMenu({ user }: { user?: any }) { const router = useRouter(); @@ -99,7 +100,7 @@ export default function AccountMenu({ user }: { user?: any }) { {user.email} )} - {(user.is_paid || user.is_premium ? 'Pro Plan' : 'Free Plan')} + {`${BILLING_PLAN_LABEL[user.billing_plan] ?? 'Free'} Plan`} diff --git a/src/app/profile/page.tsx b/src/app/profile/page.tsx index ca5749f..5f4b73c 100644 --- a/src/app/profile/page.tsx +++ b/src/app/profile/page.tsx @@ -18,6 +18,7 @@ import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; import { useAuth } from '@/app/hooks/useAuth'; import { userService } from '@/app/services/user.service'; import { API_ENDPOINT } from '@/app/constants'; +import { BILLING_PLAN_LABEL } from '@/app/shared/utils'; import AppShell from '@/app/components/app-shell'; import { Row, Section } from '@/app/components/rows'; import ActivityChart from '@/app/components/activity-chart'; @@ -88,7 +89,7 @@ export default function Profile() { ); }, [user]); - const plan = user?.is_premium ? 'Premium' : user?.is_paid ? 'Pro' : 'Free'; + const plan = BILLING_PLAN_LABEL[user?.billing_plan] ?? 'Free'; if (!user) return null; diff --git a/src/app/services/user.service.js b/src/app/services/user.service.js index a77a489..012ecc8 100644 --- a/src/app/services/user.service.js +++ b/src/app/services/user.service.js @@ -66,6 +66,8 @@ const getUser = async () => { is_paid: result.is_paid || false, // Subscription status from API is_premium: result.is_premium || false, // Premium status from API + plan: result.plan || 'free', // What metering applies (admin is unmetered) + billing_plan: result.billing_plan || 'free', // What the account pays for is_invited: result.is_invited || false, // Invite status from API is_accepted: result.is_accepted || false, // Accepted status from API @@ -153,6 +155,8 @@ const fetchAndStoreUser = async (token) => { admin: result.is_superuser, is_paid: result.is_paid || false, is_premium: result.is_premium || false, + plan: result.plan || 'free', + billing_plan: result.billing_plan || 'free', is_invited: result.is_invited || false, is_accepted: result.is_accepted || false, premium: result.is_paid || false, diff --git a/src/app/settings/sections/billing.tsx b/src/app/settings/sections/billing.tsx index 3eda6c2..064bbe3 100644 --- a/src/app/settings/sections/billing.tsx +++ b/src/app/settings/sections/billing.tsx @@ -235,7 +235,7 @@ function PlanCards({
{p.name}
- {p.id === 'plus' ? 'For heavy cloud model use' : 'For everyday cloud model use'} + {p.id === 'max' ? 'For the heaviest cloud model use' : p.id === 'plus' ? 'For heavy cloud model use' : 'For everyday cloud model use'}
{featured && } @@ -368,9 +368,11 @@ export default function BillingSection() { // account itself is flagged paid/premium (premium granted outside Stripe has // no subscription object, so /payments/subscription 404s). const hasActiveSubscription = subscription?.status === 'active' || subscription?.status === 'will_cancel'; - const isPro = hasActiveSubscription || !!subscription?.is_premium || !!(user?.is_paid || user?.is_premium); + // Billing reflects what the account pays for, not its entitlements: an + // admin or hand-granted premium account with no subscription shows Free. + const isPro = hasActiveSubscription || !!subscription?.is_premium || (user?.billing_plan ?? 'free') !== 'free'; // Which plan, as the API names it: free, paid (Pro), plus or admin. - const plan: string = subscription?.plan ?? user?.plan ?? (isPro ? 'paid' : 'free'); + const plan: string = subscription?.plan ?? user?.billing_plan ?? (isPro ? 'paid' : 'free'); const willCancel = subscription?.status === 'will_cancel'; // current_period_end is an ISO date-time string from the API. const periodEnd = subscription?.current_period_end diff --git a/src/app/settings/sections/credits.tsx b/src/app/settings/sections/credits.tsx index 3513b10..fe26f3b 100644 --- a/src/app/settings/sections/credits.tsx +++ b/src/app/settings/sections/credits.tsx @@ -36,7 +36,7 @@ interface Quota { in_flight: number; period: string; resets_at: string; - plan: 'free' | 'paid' | 'plus' | 'admin'; + plan: 'free' | 'paid' | 'plus' | 'max' | 'admin'; } interface CreditStatus { @@ -57,6 +57,7 @@ const PLAN_LABEL: Record = { free: 'Free', paid: 'Pro', plus: 'Plus', + max: 'Max', admin: 'Admin', }; diff --git a/src/app/settings/sections/websearch.tsx b/src/app/settings/sections/websearch.tsx index 6589c54..6f8daf6 100644 --- a/src/app/settings/sections/websearch.tsx +++ b/src/app/settings/sections/websearch.tsx @@ -35,7 +35,7 @@ interface Quota { credits_remaining?: number | null; period: string; resets_at: string; - plan: 'free' | 'paid' | 'plus' | 'admin'; + plan: 'free' | 'paid' | 'plus' | 'max' | 'admin'; } interface SearchStatus { @@ -60,6 +60,7 @@ const PLAN_LABEL: Record = { free: 'Free', paid: 'Pro', plus: 'Plus', + max: 'Max', admin: 'Admin', }; @@ -194,20 +195,22 @@ export default function WebSearchSection({ user }: { user: any }) { limit is hit as well as after — finding out at zero is too late to be useful. The allowances themselves are on the billing page, read from the API, so no number is kept here. */} - {(quota?.plan === 'free' || quota?.plan === 'paid') && ( + {(quota?.plan === 'free' || quota?.plan === 'paid' || quota?.plan === 'plus') && ( - {quota.plan === 'free' ? 'See plans' : 'Upgrade to Plus'} + {quota.plan === 'free' ? 'See plans' : quota.plan === 'paid' ? 'Upgrade to Plus' : 'Upgrade to Max'} )} diff --git a/src/app/shared/utils.ts b/src/app/shared/utils.ts index 6d6f0ea..b8dacdb 100644 --- a/src/app/shared/utils.ts +++ b/src/app/shared/utils.ts @@ -17,10 +17,14 @@ export const CHECKOUT_PATH = '/upgrade'; // The plans an account can be on, as the API reports them (`plan` on // /users/me, /payments/subscription and the usage meters), low to high. -export const PLAN_RANK: Record = { free: 0, paid: 1, plus: 2, admin: 3 }; +export const PLAN_RANK: Record = { free: 0, paid: 1, plus: 2, max: 3, admin: 4 }; + +// What billing shows for a plan; admin and premium accounts that pay nothing +// are reported as `billing_plan: 'free'` by the API, so they never reach here. +export const BILLING_PLAN_LABEL: Record = { free: 'Free', paid: 'Pro', plus: 'Plus', max: 'Max' }; // What checkout takes (the marketing names) -> the plan it puts the account on. -export const PURCHASABLE_PLANS: Record = { pro: 'paid', plus: 'plus' }; +export const PURCHASABLE_PLANS: Record = { pro: 'paid', plus: 'plus', max: 'max' }; // The checkout route for a purchasable plan; Pro is the route's default. export const checkoutPath = (plan: string) => diff --git a/src/app/upgrade/page.tsx b/src/app/upgrade/page.tsx index 37d60c9..e889c53 100644 --- a/src/app/upgrade/page.tsx +++ b/src/app/upgrade/page.tsx @@ -6,7 +6,7 @@ // // Marketing links point here (directly, or via /login?plan=pro), so the intent // survives the whole auth round-trip instead of being lost on the way to the -// dashboard. ?plan=plus buys Plus; no plan means Pro. Someone already paying +// dashboard. ?plan=plus buys Plus, ?plan=max buys Max; no plan means Pro. Someone already paying // for a lower plan is moved up through Stripe's plan-change confirmation, // which the same API call returns. @@ -133,7 +133,9 @@ export default function Upgrade() { // send them to Stripe's customer portal instead. Paying for a lower // plan, checkout moves them up (the API answers with the portal's // plan-change confirmation). Either way this route ends up on Stripe. - if ((u.is_paid || u.is_premium) && alreadyOn(u.plan, wantedPlan())) { + // billing_plan, not plan: an admin or premium account that pays + // nothing is on Free here and can buy any plan. + if (alreadyOn(u.billing_plan, wantedPlan())) { openBillingPortal(); return; }