Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/app/cloud-models/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -52,6 +52,8 @@ export interface CloudStatus {
export const PLAN_LABEL: Record<CloudQuota['plan'], string> = {
free: 'Free',
paid: 'Pro',
plus: 'Plus',
max: 'Max',
admin: 'Admin',
};

Expand Down
3 changes: 2 additions & 1 deletion src/app/components/account-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -99,7 +100,7 @@ export default function AccountMenu({ user }: { user?: any }) {
<Box className="text-faint text-xs leading-tight mt-0.5 truncate">{user.email}</Box>
)}
<Box className="text-muted text-xs leading-tight mt-1.5">
{(user.is_paid || user.is_premium ? 'Pro Plan' : 'Free Plan')}
{`${BILLING_PLAN_LABEL[user.billing_plan] ?? 'Free'} Plan`}
</Box>
</Box>

Expand Down
3 changes: 2 additions & 1 deletion src/app/profile/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;

Expand Down
4 changes: 4 additions & 0 deletions src/app/services/user.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down
8 changes: 5 additions & 3 deletions src/app/settings/sections/billing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ function PlanCards({
<Box>
<div className="text-base font-semibold text-content tracking-tight">{p.name}</div>
<div className="text-xs text-faint mt-0.5">
{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'}
</div>
</Box>
{featured && <Chip label="Best value" accent />}
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/app/settings/sections/credits.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -57,6 +57,7 @@ const PLAN_LABEL: Record<Quota['plan'], string> = {
free: 'Free',
paid: 'Pro',
plus: 'Plus',
max: 'Max',
admin: 'Admin',
};

Expand Down
13 changes: 8 additions & 5 deletions src/app/settings/sections/websearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -60,6 +60,7 @@ const PLAN_LABEL: Record<Quota['plan'], string> = {
free: 'Free',
paid: 'Pro',
plus: 'Plus',
max: 'Max',
admin: 'Admin',
};

Expand Down Expand Up @@ -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') && (
<Row
label="Need more searches?"
description={
quota.plan === 'free'
? 'Pro brings more monthly credits, and Plus more still.'
: 'Plus brings more monthly credits.'
? 'Pro brings more monthly credits, and Plus and Max more still.'
: quota.plan === 'paid'
? 'Plus brings more monthly credits, and Max the most.'
: 'Max brings the most monthly credits.'
}
>
<a
href="/settings/billing"
className="inline-flex items-center justify-center px-4 py-2.5 rounded-lg text-sm font-medium transition-colors border border-accent-border hover:bg-accent-soft text-accent-text whitespace-nowrap"
>
{quota.plan === 'free' ? 'See plans' : 'Upgrade to Plus'}
{quota.plan === 'free' ? 'See plans' : quota.plan === 'paid' ? 'Upgrade to Plus' : 'Upgrade to Max'}
</a>
</Row>
)}
Expand Down
8 changes: 6 additions & 2 deletions src/app/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, number> = { free: 0, paid: 1, plus: 2, admin: 3 };
export const PLAN_RANK: Record<string, number> = { 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<string, string> = { 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<string, string> = { pro: 'paid', plus: 'plus' };
export const PURCHASABLE_PLANS: Record<string, string> = { pro: 'paid', plus: 'plus', max: 'max' };

// The checkout route for a purchasable plan; Pro is the route's default.
export const checkoutPath = (plan: string) =>
Expand Down
6 changes: 4 additions & 2 deletions src/app/upgrade/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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;
}
Expand Down
Loading