From 0ac710c974b4a7f85e007e327021d3cc18ae7bce Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Wed, 30 Sep 2026 13:00:12 -0400 Subject: [PATCH] feat(billing): gate Members credit limits behind their own flag billing_control_enabled gated both the team lifecycle banners and the Members credit column + Set credit limit action. The limit is not persisted yet (FE-1278), so move the Members surfaces behind member_credit_limits_enabled (default off) and let billing_control_enabled ramp with the banners only. Also add Storybook states for the scheduled plan change and Enterprise ending banners, and fix the useWorkspaceUI Storybook mock missing canReactivatePlan, which broke the Ending stories. --- src/composables/__mocks__/useFeatureFlags.ts | 1 + src/composables/useFeatureFlags.ts | 9 +++++ src/platform/remoteConfig/types.ts | 1 + .../settings/BillingStatusBanner.stories.ts | 36 +++++++++++++++++++ .../composables/useMembersPanel.test.ts | 19 ++++++++-- .../workspace/composables/useMembersPanel.ts | 2 +- .../composables/useWorkspaceUI.test.ts | 19 ++++++---- .../workspace/composables/useWorkspaceUI.ts | 2 +- src/storybook/mocks/useWorkspaceUI.ts | 9 +++-- 9 files changed, 85 insertions(+), 13 deletions(-) diff --git a/src/composables/__mocks__/useFeatureFlags.ts b/src/composables/__mocks__/useFeatureFlags.ts index 81d117f03bc..5b2217ca27f 100644 --- a/src/composables/__mocks__/useFeatureFlags.ts +++ b/src/composables/__mocks__/useFeatureFlags.ts @@ -31,6 +31,7 @@ const defaultFlags: FeatureFlags = { unifiedCloudAuthEnabled: false, unifiedWebSessionEnabled: false, billingControlEnabled: false, + memberCreditLimitsEnabled: false, legacyBillingMigrationEnabled: false, embeddedCheckoutEnabled: false, billingSdkTopupEnabled: false, diff --git a/src/composables/useFeatureFlags.ts b/src/composables/useFeatureFlags.ts index 137519ab2ac..6c6d108ae89 100644 --- a/src/composables/useFeatureFlags.ts +++ b/src/composables/useFeatureFlags.ts @@ -43,6 +43,7 @@ export enum ServerFeatureFlag { UNIFIED_CLOUD_AUTH = 'unified_cloud_auth', UNIFIED_WEB_SESSION = 'unified_web_session', BILLING_CONTROL_ENABLED = 'billing_control_enabled', + MEMBER_CREDIT_LIMITS_ENABLED = 'member_credit_limits_enabled', LEGACY_BILLING_MIGRATION_ENABLED = 'legacy_billing_migration_enabled', EMBEDDED_CHECKOUT_ENABLED = 'embedded_checked_enabled', BILLING_SDK_TOPUP_ENABLED = 'billing_sdk_topup_enabled', @@ -310,6 +311,12 @@ export function useFeatureFlags() { cachedBillingControlEnabled ) }, + get memberCreditLimitsEnabled() { + return resolveStrictBooleanFlag( + ServerFeatureFlag.MEMBER_CREDIT_LIMITS_ENABLED, + remoteConfig.value.member_credit_limits_enabled + ) + }, get legacyBillingMigrationEnabled() { return resolveAuthGatedFlag( ServerFeatureFlag.LEGACY_BILLING_MIGRATION_ENABLED, @@ -443,6 +450,8 @@ export function startFeatureFlagTelemetry() { [ServerFeatureFlag.SHOW_SIGNIN_BUTTON]: flags.showSignInButton, [ServerFeatureFlag.UNIFIED_CLOUD_AUTH]: flags.unifiedCloudAuthEnabled, [ServerFeatureFlag.BILLING_CONTROL_ENABLED]: flags.billingControlEnabled, + [ServerFeatureFlag.MEMBER_CREDIT_LIMITS_ENABLED]: + flags.memberCreditLimitsEnabled, [ServerFeatureFlag.LEGACY_BILLING_MIGRATION_ENABLED]: flags.legacyBillingMigrationEnabled, [ServerFeatureFlag.EMBEDDED_CHECKOUT_ENABLED]: diff --git a/src/platform/remoteConfig/types.ts b/src/platform/remoteConfig/types.ts index 5f382579912..3b8d2353643 100644 --- a/src/platform/remoteConfig/types.ts +++ b/src/platform/remoteConfig/types.ts @@ -133,6 +133,7 @@ export type RemoteConfig = GetFeaturesResponses[200] & { billing_sdk_topup_enabled?: boolean billing_sdk_subscription_enabled?: boolean billing_control_enabled?: boolean + member_credit_limits_enabled?: boolean legacy_billing_migration_enabled?: boolean v1_payment_recovery?: boolean churnkey_app_id?: string diff --git a/src/platform/workspace/components/dialogs/settings/BillingStatusBanner.stories.ts b/src/platform/workspace/components/dialogs/settings/BillingStatusBanner.stories.ts index f091966ef67..b4c8dd2ccd7 100644 --- a/src/platform/workspace/components/dialogs/settings/BillingStatusBanner.stories.ts +++ b/src/platform/workspace/components/dialogs/settings/BillingStatusBanner.stories.ts @@ -195,3 +195,39 @@ export const EndingPromotedOwner: Story = story( }, { canManageSubscriptionLifecycle: true } ) + +/** A plan change is scheduled for the next period. Informational. */ +export const PlanChangeOwner: Story = story( + { + subscription: { + ...teamSubscription, + scheduledChange: { + plan_slug: 'enterprise-monthly', + effective_at: PLAN_END_DATE, + team_credit_stop: null + } + }, + canAccessSubscriptionFeatures: true, + billingStatus: 'paid', + subscriptionStatus: 'active' + }, + owner +) + +const TEN_DAYS_MS = 10 * 24 * 60 * 60 * 1000 + +/** An Enterprise end date stays quiet until it is two weeks out. */ +export const EndingEnterpriseOwner: Story = story( + { + subscription: { + ...cancelled, + tier: 'ENTERPRISE', + endDate: new Date(Date.now() + TEN_DAYS_MS).toISOString() + }, + isTeamPlan: false, + canAccessSubscriptionFeatures: true, + billingStatus: 'paid', + subscriptionStatus: 'canceled' + }, + owner +) diff --git a/src/platform/workspace/composables/useMembersPanel.test.ts b/src/platform/workspace/composables/useMembersPanel.test.ts index 7e350c32fb3..fc7ccbd7b86 100644 --- a/src/platform/workspace/composables/useMembersPanel.test.ts +++ b/src/platform/workspace/composables/useMembersPanel.test.ts @@ -465,7 +465,7 @@ describe('useMembersPanel', () => { workspaceMembers = [] workspacePendingInvites = [] updateWorkspaceStore() - vi.mocked(useFeatureFlags().flags).billingControlEnabled = true + vi.mocked(useFeatureFlags().flags).memberCreditLimitsEnabled = true mockMaxSeats.value = 73 mockOccupiedSeats.value = 0 mockCanAccessSubscriptionFeatures.value = true @@ -893,7 +893,20 @@ describe('useMembersPanel', () => { }) it('omits the credit-limit action when the flag is disabled', async () => { - vi.mocked(useFeatureFlags().flags).billingControlEnabled = false + vi.mocked(useFeatureFlags().flags).memberCreditLimitsEnabled = false + const panel = await setup() + + expect(panel.memberMenuItems(createMember()).map((i) => i.label)).toEqual( + [ + 'workspacePanel.members.actions.changeRole', + 'workspacePanel.members.actions.removeMember' + ] + ) + }) + + it('omits the credit-limit action under billing controls alone', async () => { + vi.mocked(useFeatureFlags().flags).memberCreditLimitsEnabled = false + vi.mocked(useFeatureFlags().flags).billingControlEnabled = true const panel = await setup() expect(panel.memberMenuItems(createMember()).map((i) => i.label)).toEqual( @@ -905,7 +918,7 @@ describe('useMembersPanel', () => { }) it('keeps the creator menu hidden when the flag is disabled', async () => { - vi.mocked(useFeatureFlags().flags).billingControlEnabled = false + vi.mocked(useFeatureFlags().flags).memberCreditLimitsEnabled = false setOriginalOwner() const panel = await setup() diff --git a/src/platform/workspace/composables/useMembersPanel.ts b/src/platform/workspace/composables/useMembersPanel.ts index f29cac74459..3ae157c7379 100644 --- a/src/platform/workspace/composables/useMembersPanel.ts +++ b/src/platform/workspace/composables/useMembersPanel.ts @@ -352,7 +352,7 @@ export function useMembersPanel() { roleMenuItem(member, 'member', t('workspaceSwitcher.roleMember')) ] }, - ...(flags.billingControlEnabled && member.role === 'member' + ...(flags.memberCreditLimitsEnabled && member.role === 'member' ? [creditLimitItem] : []), { diff --git a/src/platform/workspace/composables/useWorkspaceUI.test.ts b/src/platform/workspace/composables/useWorkspaceUI.test.ts index 0c2186719a1..566a4e1c628 100644 --- a/src/platform/workspace/composables/useWorkspaceUI.test.ts +++ b/src/platform/workspace/composables/useWorkspaceUI.test.ts @@ -14,7 +14,7 @@ const mockShouldUseWorkspaceBilling = ref(true) const mockIsActiveSubscription = vi.hoisted(() => ({ value: false })) const mockIsCancelled = vi.hoisted(() => ({ value: false })) const mockIsTeamPlan = vi.hoisted(() => ({ value: false })) -const mockBillingControlEnabled = vi.hoisted(() => ({ value: false })) +const mockMemberCreditLimitsEnabled = vi.hoisted(() => ({ value: false })) const mockCanReactivate = ref(false) vi.mock(import('@/platform/distribution/types'), () => ({ @@ -69,8 +69,8 @@ const teamMemberWorkspace: WorkspaceWithRole = { } function loadComposable() { - vi.mocked(useFeatureFlags().flags).billingControlEnabled = - mockBillingControlEnabled.value + vi.mocked(useFeatureFlags().flags).memberCreditLimitsEnabled = + mockMemberCreditLimitsEnabled.value const ui = composableScope.run(useWorkspaceUI) if (!ui) throw new Error('Composable scope is inactive') return ui @@ -83,7 +83,7 @@ function resetStore() { mockIsActiveSubscription.value = false mockIsCancelled.value = false mockIsTeamPlan.value = false - mockBillingControlEnabled.value = false + mockMemberCreditLimitsEnabled.value = false mockCanReactivate.value = false mockIsCloud.value = true mockShouldUseWorkspaceBilling.value = true @@ -303,8 +303,15 @@ describe('useWorkspaceUI', { tags: ['shared-state'] }, () => { expect(ui.uiConfig.value.showCreditsColumn).toBe(false) }) - it('adds the credits column when billing controls are enabled', async () => { - mockBillingControlEnabled.value = true + it('keeps the credits column hidden under billing controls alone', async () => { + vi.mocked(useFeatureFlags().flags).billingControlEnabled = true + const ui = await loadComposable() + + expect(ui.uiConfig.value.showCreditsColumn).toBe(false) + }) + + it('adds the credits column when member credit limits are enabled', async () => { + mockMemberCreditLimitsEnabled.value = true const ui = await loadComposable() expect(ui.uiConfig.value.showCreditsColumn).toBe(true) diff --git a/src/platform/workspace/composables/useWorkspaceUI.ts b/src/platform/workspace/composables/useWorkspaceUI.ts index 11a79f1f3d1..dd5b03cdb11 100644 --- a/src/platform/workspace/composables/useWorkspaceUI.ts +++ b/src/platform/workspace/composables/useWorkspaceUI.ts @@ -220,7 +220,7 @@ function useWorkspaceUIInternal() { const uiConfig = computed(() => { const base = getUIConfig(workspaceType.value, workspaceRole.value) const showCreditsColumn = - flags.billingControlEnabled && + flags.memberCreditLimitsEnabled && workspaceType.value === 'team' && workspaceRole.value === 'owner' if (!showCreditsColumn) return base diff --git a/src/storybook/mocks/useWorkspaceUI.ts b/src/storybook/mocks/useWorkspaceUI.ts index f40b6fa19db..fed6b11f91a 100644 --- a/src/storybook/mocks/useWorkspaceUI.ts +++ b/src/storybook/mocks/useWorkspaceUI.ts @@ -13,6 +13,7 @@ export interface WorkspaceUIMockState { canManageSubscriptionLifecycle: boolean canDowngradeToPersonal: boolean isSubscriptionCancelled: boolean + canReactivatePlan: boolean } const defaultState: WorkspaceUIMockState = { @@ -21,7 +22,8 @@ const defaultState: WorkspaceUIMockState = { canManageSubscription: true, canManageSubscriptionLifecycle: true, canDowngradeToPersonal: true, - isSubscriptionCancelled: false + isSubscriptionCancelled: false, + canReactivatePlan: true } const state = ref({ ...defaultState }) @@ -42,6 +44,9 @@ export function useWorkspaceUI() { state.value.canManageSubscriptionLifecycle, canDowngradeToPersonal: state.value.canDowngradeToPersonal })), - isSubscriptionCancelled: computed(() => state.value.isSubscriptionCancelled) + isSubscriptionCancelled: computed( + () => state.value.isSubscriptionCancelled + ), + canReactivatePlan: computed(() => state.value.canReactivatePlan) } }