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
1 change: 1 addition & 0 deletions src/composables/__mocks__/useFeatureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const defaultFlags: FeatureFlags = {
unifiedCloudAuthEnabled: false,
unifiedWebSessionEnabled: false,
billingControlEnabled: false,
memberCreditLimitsEnabled: false,
legacyBillingMigrationEnabled: false,
embeddedCheckoutEnabled: false,
billingSdkTopupEnabled: false,
Expand Down
9 changes: 9 additions & 0 deletions src/composables/useFeatureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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]:
Expand Down
1 change: 1 addition & 0 deletions src/platform/remoteConfig/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
19 changes: 16 additions & 3 deletions src/platform/workspace/composables/useMembersPanel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion src/platform/workspace/composables/useMembersPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ export function useMembersPanel() {
roleMenuItem(member, 'member', t('workspaceSwitcher.roleMember'))
]
},
...(flags.billingControlEnabled && member.role === 'member'
...(flags.memberCreditLimitsEnabled && member.role === 'member'
? [creditLimitItem]
: []),
{
Expand Down
19 changes: 13 additions & 6 deletions src/platform/workspace/composables/useWorkspaceUI.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'), () => ({
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/platform/workspace/composables/useWorkspaceUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ function useWorkspaceUIInternal() {
const uiConfig = computed<WorkspaceUIConfig>(() => {
const base = getUIConfig(workspaceType.value, workspaceRole.value)
const showCreditsColumn =
flags.billingControlEnabled &&
flags.memberCreditLimitsEnabled &&
workspaceType.value === 'team' &&
workspaceRole.value === 'owner'
if (!showCreditsColumn) return base
Expand Down
9 changes: 7 additions & 2 deletions src/storybook/mocks/useWorkspaceUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface WorkspaceUIMockState {
canManageSubscriptionLifecycle: boolean
canDowngradeToPersonal: boolean
isSubscriptionCancelled: boolean
canReactivatePlan: boolean
}

const defaultState: WorkspaceUIMockState = {
Expand All @@ -21,7 +22,8 @@ const defaultState: WorkspaceUIMockState = {
canManageSubscription: true,
canManageSubscriptionLifecycle: true,
canDowngradeToPersonal: true,
isSubscriptionCancelled: false
isSubscriptionCancelled: false,
canReactivatePlan: true
}

const state = ref<WorkspaceUIMockState>({ ...defaultState })
Expand All @@ -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)
}
}
Loading