From d22b5783bed36ef5a92412ab60d5b7a0ac764b68 Mon Sep 17 00:00:00 2001 From: Vikhyath Mondreti Date: Thu, 4 Dec 2025 16:22:29 -0800 Subject: [PATCH] fix(enterprise-plan): seats should be taken from metadata (#2200) * fix(enterprise): seats need to be picked up from metadata not column * fix env var access * fix user avatar --- .../components/subscription/subscription.tsx | 4 +- .../team-seats-overview.tsx | 9 +-- .../components/team-seats/team-seats.tsx | 3 +- .../components/team-usage/team-usage.tsx | 8 +-- .../team-management/team-management.tsx | 57 ++++++++++--------- .../components/user-avatar/user-avatar.tsx | 2 +- .../lib/billing/calculations/usage-monitor.ts | 2 +- apps/sim/lib/billing/client/utils.ts | 3 - apps/sim/lib/billing/core/billing.ts | 4 +- apps/sim/lib/billing/core/organization.ts | 18 +++--- apps/sim/lib/billing/core/usage.ts | 8 +-- apps/sim/lib/billing/subscriptions/utils.ts | 33 +++++++++++ apps/sim/lib/billing/threshold-billing.ts | 2 +- .../lib/billing/validation/seat-management.ts | 10 ++-- apps/sim/lib/billing/webhooks/enterprise.ts | 4 +- 15 files changed, 101 insertions(+), 66 deletions(-) diff --git a/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components-new/settings-modal/components/subscription/subscription.tsx b/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components-new/settings-modal/components/subscription/subscription.tsx index 247603144d..1d8d4afe94 100644 --- a/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components-new/settings-modal/components/subscription/subscription.tsx +++ b/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components-new/settings-modal/components/subscription/subscription.tsx @@ -197,7 +197,7 @@ export function Subscription({ onOpenChange }: SubscriptionProps) { subscriptionData?.data?.status === 'active', plan: subscriptionData?.data?.plan || 'free', status: subscriptionData?.data?.status || 'inactive', - seats: subscriptionData?.data?.seats || 1, + seats: organizationBillingData?.totalSeats ?? 0, } const usage = { @@ -373,7 +373,7 @@ export function Subscription({ onOpenChange }: SubscriptionProps) { onBadgeClick={handleBadgeClick} seatsText={ permissions.canManageTeam || subscription.isEnterprise - ? `${organizationBillingData?.totalSeats || subscription.seats || 1} seats` + ? `${subscription.seats} seats` : undefined } current={ diff --git a/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components-new/settings-modal/components/team-management/components/team-seats-overview/team-seats-overview.tsx b/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components-new/settings-modal/components/team-management/components/team-seats-overview/team-seats-overview.tsx index b2b2e8d253..283adeb749 100644 --- a/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components-new/settings-modal/components/team-management/components/team-seats-overview/team-seats-overview.tsx +++ b/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components-new/settings-modal/components/team-management/components/team-seats-overview/team-seats-overview.tsx @@ -3,23 +3,20 @@ import { Skeleton } from '@/components/ui/skeleton' import { checkEnterprisePlan } from '@/lib/billing/subscriptions/utils' import { cn } from '@/lib/core/utils/cn' -const PILL_COUNT = 8 - type Subscription = { id: string plan: string status: string - seats?: number referenceId: string cancelAtPeriodEnd?: boolean periodEnd?: number | Date trialEnd?: number | Date - metadata?: any } interface TeamSeatsOverviewProps { subscriptionData: Subscription | null isLoadingSubscription: boolean + totalSeats: number usedSeats: number isLoading: boolean onConfirmTeamUpgrade: (seats: number) => Promise @@ -55,6 +52,7 @@ function TeamSeatsSkeleton() { export function TeamSeatsOverview({ subscriptionData, isLoadingSubscription, + totalSeats, usedSeats, isLoading, onConfirmTeamUpgrade, @@ -78,7 +76,7 @@ export function TeamSeatsOverview({