An open-source, faster Devin alternative
TypeScript
Fix organization plan shown in settings (#766)
Mohamed Habibd5da4a0a73a0
diff --git a/web/src/lib/plan-label.test.ts b/web/src/lib/plan-label.test.tsnew file mode 100644index 00000000..fa30ff8e--- /dev/null+++ b/web/src/lib/plan-label.test.ts@@ -0,0 +1,40 @@+import { describe, expect, it } from 'vitest'+import { organizationPlanLabel, planLabel } from '@/lib/plan-label'++describe('planLabel', () => {+ it.each([+ ['free', 'Free'],+ ['pro', 'Pro'],+ ['base', 'Base'],+ ['max', 'Max'],+ ])('formats %s as %s', (plan, label) => {+ expect(planLabel(plan)).toBe(label)+ })++ it('formats an unknown plan instead of exposing its identifier', () => {+ expect(planLabel('enterprise_custom')).toBe('Enterprise Custom')+ })+})++describe('organizationPlanLabel', () => {+ const org = { plan: 'free' }++ it('uses the Autumn usage plan instead of the legacy org plan or concurrency tier', () => {+ expect(+ organizationPlanLabel(+ org,+ {+ plan: 'free',+ billingProvider: 'autumn',+ },+ {+ usagePlan: 'max',+ },+ ),+ ).toBe('Max')+ })++ it('uses the standard billing plan for legacy billing', () => {+ expect(organizationPlanLabel(org, { plan: 'pro' }, undefined)).toBe('Pro')+ })+})diff --git a/web/src/lib/plan-label.ts b/web/src/lib/plan-label.tsnew file mode 100644index 00000000..13d4a1e9--- /dev/null+++ b/web/src/lib/plan-label.ts@@ -0,0 +1,31 @@+export function planLabel(plan: string): string {+ return plan+ .split('_')+ .filter(Boolean)+ .map((part) => part[0]?.toUpperCase() + part.slice(1))+ .join(' ')+}++type PlanSource = {+ plan: string+}++type BillingPlanSource = PlanSource & {+ billingProvider?: string+}++type AutumnPlanSource = {+ usagePlan: string+}++export function organizationPlanLabel(+ org: PlanSource | undefined,+ billing: BillingPlanSource | undefined,+ autumn: AutumnPlanSource | undefined,+): string {+ if (billing?.billingProvider === 'autumn') {+ return planLabel(autumn?.usagePlan ?? 'base')+ }++ return planLabel(billing?.plan ?? org?.plan ?? 'free')+}diff --git a/web/src/pages/Settings.tsx b/web/src/pages/Settings.tsxindex f5847e83..28f8eeac 100644--- a/web/src/pages/Settings.tsx+++ b/web/src/pages/Settings.tsx@@ -3,8 +3,11 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'import { notifyError } from '@/lib/errors'import { useTransientFlag } from '@/lib/use-transient-flag'import { useAuth } from '@/hooks/useAuth'+import { organizationPlanLabel } from '@/lib/plan-label'import {deleteCustomDomain,+ getAutumnBilling,+ getBilling,getInvitations,getOrg,getOrgMembers,@@ -82,6 +85,16 @@ export default function Settings() {queryKey: ['org'],queryFn: getOrg,})+ const { data: billing, isLoading: isBillingLoading } = useQuery({+ queryKey: ['billing'],+ queryFn: getBilling,+ })+ const usesAutumnBilling = billing?.billingProvider === 'autumn'+ const { data: autumn, isLoading: isAutumnLoading } = useQuery({+ queryKey: ['autumn-billing'],+ queryFn: getAutumnBilling,+ enabled: usesAutumnBilling,+ })const {data: runtimeProfile,isLoading: runtimeProfileLoading,@@ -139,7 +152,7 @@ export default function Settings() {onSettled: () => queryClient.invalidateQueries({ queryKey: ['org'] }),})- if (isLoading) {+ if (isLoading || isBillingLoading || (usesAutumnBilling && isAutumnLoading)) {return (<div><PageHeader title="Settings" description="Organization configuration" />@@ -153,6 +166,7 @@ export default function Settings() {const unchanged = name === (org?.name ?? '')const hasDomain = !!org?.customDomain && org.customDomain !== ''+ const plan = organizationPlanLabel(org, billing, autumn)return (<div>@@ -217,7 +231,7 @@ export default function Settings() {<div className="mb-5"><PanelTitle>Organization</PanelTitle><PanelDescription className="mt-1">- Your organization's name and plan limits.+ Your organization's name and plan.</PanelDescription></div><div className="space-y-5">@@ -229,21 +243,7 @@ export default function Settings() {/></Field>- <ReadOnlyField- label="Plan"- value={<span className="capitalize">{org?.plan ?? 'free'}</span>}- />-- <div className="grid grid-cols-1 gap-4 sm:grid-cols-2">- <ReadOnlyField- label="Max concurrent sandboxes"- value={org?.maxConcurrentSandboxes}- />- <ReadOnlyField- label="Max timeout (sec)"- value={org?.maxSandboxTimeoutSec}- />- </div>+ <ReadOnlyField label="Plan" value={plan} /><div className="flex items-center gap-3"><Button