diff --git a/src/locales/en/main.json b/src/locales/en/main.json index 81405dd3426..9e697e9103e 100644 --- a/src/locales/en/main.json +++ b/src/locales/en/main.json @@ -3359,6 +3359,16 @@ "reactivate": "Resume plan", "contactSales": "Contact sales" }, + "planEnded": { + "teamTitle": "Your team plan ended on {date}", + "teamBody": "Resubscribe to run workflows and get shared credits again.", + "teamMemberBody": "Ask your workspace owner to resubscribe.", + "enterpriseTitle": "Your Enterprise plan ended on {date}", + "enterpriseBody": "Contact sales to start a new Enterprise plan.", + "planTitle": "Your plan ended on {date}", + "salesBody": "Contact sales to start a new plan.", + "salesMemberBody": "Ask your workspace owner to contact sales." + }, "planChange": { "title": "Your plan changes to {plan} on {date}.", "body": "Your current plan stays active until then." @@ -3431,6 +3441,7 @@ "reactivateTeam": "Reactivate Team", "totalMembersCount": "{count} of {maxSeats} total members.", "needMoreMembers": "Need more members?", + "planEndedFooter": "Your plan has ended, so you can't add new members.", "contactUs": "Contact us", "noInvites": "No pending invites", "noInvitesMatch": "No invites match \"{query}\"", diff --git a/src/platform/workspace/components/dialogs/settings/BillingStatusBanner.stories.ts b/src/platform/workspace/components/dialogs/settings/BillingStatusBanner.stories.ts index a653dbe0b9a..ce3e08d01e9 100644 --- a/src/platform/workspace/components/dialogs/settings/BillingStatusBanner.stories.ts +++ b/src/platform/workspace/components/dialogs/settings/BillingStatusBanner.stories.ts @@ -231,3 +231,32 @@ const enterpriseEnding: Partial = { export const EndingEnterpriseOwner: Story = story(enterpriseEnding, owner) export const EndingEnterpriseMember: Story = story(enterpriseEnding, member) + +const endedTeam: Partial = { + subscription: { + ...cancelled, + tier: 'PRO', + hasFunds: false, + endDate: '2026-09-12T12:00:00Z' + }, + canAccessSubscriptionFeatures: false, + billingStatus: 'inactive', + subscriptionStatus: 'ended' +} + +/** The plan is over. Ships without the billing control flag. */ +export const PlanEndedOwner: Story = story(endedTeam, owner) + +export const PlanEndedMember: Story = story(endedTeam, member, { + canTopUp: false +}) + +const endedEnterprise: Partial = { + ...endedTeam, + subscription: { ...endedTeam.subscription!, tier: 'ENTERPRISE' }, + isTeamPlan: false +} + +export const PlanEndedEnterpriseOwner: Story = story(endedEnterprise, owner) + +export const PlanEndedEnterpriseMember: Story = story(endedEnterprise, member) diff --git a/src/platform/workspace/components/dialogs/settings/BillingStatusBanner.test.ts b/src/platform/workspace/components/dialogs/settings/BillingStatusBanner.test.ts index 86eedfd67e7..99578236753 100644 --- a/src/platform/workspace/components/dialogs/settings/BillingStatusBanner.test.ts +++ b/src/platform/workspace/components/dialogs/settings/BillingStatusBanner.test.ts @@ -27,6 +27,7 @@ const state = vi.hoisted(() => ({ canAccessSubscriptionFeatures: true, isTeamPlan: true, billingStatus: 'paid' as string | null, + subscriptionStatus: 'active' as string | null, subscription: { hasFunds: true, isCancelled: false, @@ -41,7 +42,8 @@ const state = vi.hoisted(() => ({ canReactivatePlan: true, shouldUseWorkspaceBilling: true, manageSubscription: vi.fn(), - handleResubscribe: vi.fn() + handleResubscribe: vi.fn(), + showSubscriptionDialog: vi.fn() })) vi.mock(import('@/composables/billing/useBillingRouting'), () => ({ @@ -61,6 +63,7 @@ vi.mock(import('@/composables/billing/useBillingContext'), () => ({ ), isTeamPlan: computed(() => state.isTeamPlan), billingStatus: computed(() => state.billingStatus as BillingStatus | null), + subscriptionStatus: computed(() => state.subscriptionStatus), subscription: computed(() => state.subscription), plans: computed(() => [ { slug: 'pro-annual', tier: 'PRO', duration: 'ANNUAL' } @@ -98,12 +101,25 @@ vi.mock(import('@/platform/workspace/composables/useResubscribe'), () => ({ vi.mock(import('@/services/dialogService')) +vi.mock( + import('@/platform/cloud/subscription/composables/useSubscriptionDialog'), + () => ({ + useSubscriptionDialog: () => ({ show: state.showSubscriptionDialog }) + }) +) + const i18n = createI18n({ legacy: false, locale: 'en', messages: { en: { workspacePanel: { + members: { + resubscribe: 'Resubscribe', + endedTeamTitle: 'Your team plan has ended', + endedEnterpriseTitle: 'Your Enterprise plan has ended', + endedPlanTitle: 'Your plan has ended' + }, billingStatus: { paused: { title: 'Subscription paused', @@ -132,6 +148,17 @@ const i18n = createI18n({ reactivate: 'Resume plan', contactSales: 'Contact sales' }, + planEnded: { + teamTitle: 'Your team plan ended on {date}', + teamBody: + 'Resubscribe to run workflows and get shared credits again.', + teamMemberBody: 'Ask your workspace owner to resubscribe.', + enterpriseTitle: 'Your Enterprise plan ended on {date}', + enterpriseBody: 'Contact sales to start a new Enterprise plan.', + planTitle: 'Your plan ended on {date}', + salesBody: 'Contact sales to start a new plan.', + salesMemberBody: 'Ask your workspace owner to contact sales.' + }, planChange: { title: 'Your plan changes to {plan} on {date}.', body: 'Your current plan stays active until then.' @@ -202,6 +229,7 @@ describe('BillingStatusBanner', () => { state.canAccessSubscriptionFeatures = true state.isTeamPlan = true state.billingStatus = 'paid' + state.subscriptionStatus = 'active' state.subscription = { hasFunds: true, isCancelled: false, @@ -571,6 +599,85 @@ describe('BillingStatusBanner', () => { expect(screen.queryByRole('status')).not.toBeInTheDocument() }) + describe('plan ended', () => { + function endedPlan(tier: SubscriptionInfo['tier'] = 'PRO') { + state.subscriptionStatus = 'ended' + state.billingStatus = 'inactive' + state.canAccessSubscriptionFeatures = false + state.subscription = { + hasFunds: false, + isCancelled: true, + endDate: '2026-09-12T12:00:00Z', + scheduledChange: null, + tier + } + } + + it('lets a team owner resubscribe through the pricing table', async () => { + endedPlan() + renderBanner() + + expect(screen.getByRole('status')).toHaveTextContent( + 'Your team plan ended on September 12, 2026' + ) + await userEvent.click(screen.getByRole('button', { name: 'Resubscribe' })) + expect(state.showSubscriptionDialog).toHaveBeenCalledWith( + expect.objectContaining({ planMode: 'team' }) + ) + }) + + it('points a team member to the owner', () => { + endedPlan() + state.canManageSubscription = false + renderBanner() + + expect(screen.getByRole('status')).toHaveTextContent( + 'Ask your workspace owner to resubscribe.' + ) + expect( + screen.queryByRole('button', { name: 'Resubscribe' }) + ).not.toBeInTheDocument() + }) + + it('sends an Enterprise owner to sales', async () => { + endedPlan('ENTERPRISE') + state.isTeamPlan = false + const open = vi.spyOn(window, 'open').mockReturnValue(null) + renderBanner() + + expect(screen.getByRole('status')).toHaveTextContent( + 'Your Enterprise plan ended on September 12, 2026' + ) + await userEvent.click( + screen.getByRole('button', { name: 'Contact sales' }) + ) + expect(open).toHaveBeenCalledWith( + 'https://comfy.org/cloud/enterprise/', + '_blank', + 'noopener,noreferrer' + ) + open.mockRestore() + }) + + it('dismisses for the session', async () => { + endedPlan() + renderBanner() + + await userEvent.click(screen.getByRole('button', { name: 'Dismiss' })) + expect(screen.queryByRole('status')).not.toBeInTheDocument() + }) + + it('shows even when billing control is rolled back', () => { + endedPlan() + vi.mocked(useFeatureFlags().flags).billingControlEnabled = false + renderBanner() + + expect(screen.getByRole('status')).toHaveTextContent( + 'Your team plan ended on' + ) + }) + }) + describe('enterprise ending notice', () => { const NOW = new Date('2026-09-03T12:00:00Z') const DAY = 24 * 60 * 60 * 1000 diff --git a/src/platform/workspace/components/dialogs/settings/BillingStatusBanner.vue b/src/platform/workspace/components/dialogs/settings/BillingStatusBanner.vue index 8a9e81e104e..b4e0ab981bd 100644 --- a/src/platform/workspace/components/dialogs/settings/BillingStatusBanner.vue +++ b/src/platform/workspace/components/dialogs/settings/BillingStatusBanner.vue @@ -49,6 +49,14 @@ > {{ $t('workspacePanel.billingStatus.ending.reactivate') }} + +

@@ -335,8 +353,8 @@ function handleContactUs() { window.open(TEAM_PLAN_REQUEST_URL, '_blank', 'noopener,noreferrer') } -// The ended-banner action: a sales-managed plan's route back is the -// enterprise page, not the team-plan request form the footer link uses. +// The ended banner and footer action: a sales-managed plan's route back is the +// enterprise page, not the team-plan request form the Contact us link uses. function handleContactSales() { window.open(ENTERPRISE_URL, '_blank', 'noopener,noreferrer') } diff --git a/src/platform/workspace/composables/deriveBillingBanner.test.ts b/src/platform/workspace/composables/deriveBillingBanner.test.ts index e7ff7e8612f..dbd3f53aa11 100644 --- a/src/platform/workspace/composables/deriveBillingBanner.test.ts +++ b/src/platform/workspace/composables/deriveBillingBanner.test.ts @@ -16,6 +16,8 @@ const funded: BillingBannerInputs = { isCancelled: false, endDate: null, canManage: true, + isPlanEnded: false, + planEndedDismissed: false, outOfCreditsDismissed: false, planChangeDismissed: false, hasScheduledChange: false @@ -153,6 +155,37 @@ describe('deriveBillingBanner', () => { ).toBe('ending') }) + describe('plan ended', () => { + const ended: Partial = { + isPlanEnded: true, + canAccessSubscriptionFeatures: false, + billingStatus: 'inactive' + } + + it('shows for team and Enterprise, owners and members alike', () => { + expect(derive(ended)).toBe('planEnded') + expect(derive({ ...ended, canManage: false })).toBe('planEnded') + expect(derive({ ...ended, isTeamPlan: false, isEnterprise: true })).toBe( + 'planEnded' + ) + }) + + it('ships without the billing control flag', () => { + expect(derive({ ...ended, billingControlEnabled: false })).toBe( + 'planEnded' + ) + }) + + it('ranks below payment recovery and above out of credits', () => { + expect(derive({ ...ended, ...paused })).toBe('paused') + expect(derive({ ...ended, hasFunds: false })).toBe('planEnded') + }) + + it('stays hidden once dismissed', () => { + expect(derive({ ...ended, planEndedDismissed: true })).toBeNull() + }) + }) + it('shows no banner for an inactive subscription (that is a run-lock modal)', () => { expect( derive({ diff --git a/src/platform/workspace/composables/useBillingBanner.ts b/src/platform/workspace/composables/useBillingBanner.ts index 8f4e930423f..ec9077a9669 100644 --- a/src/platform/workspace/composables/useBillingBanner.ts +++ b/src/platform/workspace/composables/useBillingBanner.ts @@ -14,11 +14,13 @@ import type { SubscriptionTier, BillingStatus } from '@/platform/workspace/api/workspaceApi' +import { usePlanEnded } from '@/platform/workspace/composables/usePlanEnded' import { useWorkspaceUI } from '@/platform/workspace/composables/useWorkspaceUI' export type BillingBannerKind = | 'paused' | 'paymentFailed' + | 'planEnded' | 'outOfCredits' | 'ending' | 'planChange' @@ -36,6 +38,8 @@ export interface BillingBannerInputs { isCancelled: boolean endDate: string | null canManage: boolean + isPlanEnded: boolean + planEndedDismissed: boolean outOfCreditsDismissed: boolean planChangeDismissed: boolean hasScheduledChange: boolean @@ -118,15 +122,21 @@ function deriveTeamNoticeBanner( } // The single billing banner slot, in priority order: paused > paymentFailed > -// outOfCredits > ending > planChange. The Enterprise policy takes precedence -// over any team-plan reading of the same subscription. +// planEnded > outOfCredits > ending > planChange. The Enterprise policy takes +// precedence over any team-plan reading of the same subscription. Plan ended +// ships without a rollout flag. export function deriveBillingBanner( inputs: BillingBannerInputs, now: number = Date.now() ): BillingBannerKind | null { if (!inputs.isLoaded) return null + const recovery = inputs.isEnterprise + ? null + : derivePaymentRecoveryBanner(inputs) + if (recovery) return recovery + if (inputs.isPlanEnded) return inputs.planEndedDismissed ? null : 'planEnded' if (inputs.isEnterprise) return deriveEnterpriseBanner(inputs, now) - return derivePaymentRecoveryBanner(inputs) ?? deriveTeamNoticeBanner(inputs) + return deriveTeamNoticeBanner(inputs) } function classifyTier( @@ -172,6 +182,8 @@ function useBillingBannerInternal() { const { permissions } = useWorkspaceUI() const { flags } = useFeatureFlags() + const { isPlanEnded } = usePlanEnded() + const planEndedDismissed = ref(false) const outOfCreditsDismissed = ref(false) const planChangeDismissed = ref(false) @@ -186,6 +198,8 @@ function useBillingBannerInternal() { canAccessSubscriptionFeatures: canAccessSubscriptionFeatures.value, billingStatus: billingStatus.value, canManage: permissions.value.canManageSubscription, + isPlanEnded: isPlanEnded.value, + planEndedDismissed: planEndedDismissed.value, outOfCreditsDismissed: outOfCreditsDismissed.value, planChangeDismissed: planChangeDismissed.value, ...readSubscriptionInputs(subscription.value) @@ -196,8 +210,8 @@ function useBillingBannerInternal() { ) // Out-of-credits dismissal lasts one exhaustion episode: reset once the - // workspace is funded again so a later exhaustion re-shows. A plan change - // dismissal lasts the session. Shared state, so both survive the settings + // workspace is funded again so a later exhaustion re-shows. Plan ended and + // plan change dismissals last the session. Shared state, so both survive the settings // panel unmounting when the dialog closes. const hasExhaustedFunds = computed( () => subscription.value?.hasFunds === false @@ -212,6 +226,7 @@ function useBillingBannerInternal() { }) function dismiss() { + if (kind.value === 'planEnded') planEndedDismissed.value = true if (kind.value === 'outOfCredits') outOfCreditsDismissed.value = true if (kind.value === 'planChange') planChangeDismissed.value = true } diff --git a/src/platform/workspace/composables/useMembersPanel.ts b/src/platform/workspace/composables/useMembersPanel.ts index e16283d7467..c0ccbf8f4d8 100644 --- a/src/platform/workspace/composables/useMembersPanel.ts +++ b/src/platform/workspace/composables/useMembersPanel.ts @@ -7,11 +7,11 @@ import { useI18n } from 'vue-i18n' import { useCurrentUser } from '@/composables/auth/useCurrentUser' import { useBillingContext } from '@/composables/billing/useBillingContext' import { useFeatureFlags } from '@/composables/useFeatureFlags' -import { isSalesManagedTier } from '@/platform/cloud/subscription/constants/tierPricing' import { useSubscriptionDialog } from '@/platform/cloud/subscription/composables/useSubscriptionDialog' import { isCloud } from '@/platform/distribution/types' import type { WorkspaceRole } from '@/platform/workspace/api/workspaceApi' import { useBillingCapabilities } from '@/platform/workspace/composables/useBillingCapabilities' +import { usePlanEnded } from '@/platform/workspace/composables/usePlanEnded' import { useTeamPlan } from '@/platform/workspace/composables/useTeamPlan' import { useWorkspaceUI } from '@/platform/workspace/composables/useWorkspaceUI' import type { @@ -117,62 +117,10 @@ export function useMembersPanel() { const { hasTeamPlan, isOnTeamPlan, hasMemberSeats, isPlanLoading } = useTeamPlan() const subscriptionDialog = useSubscriptionDialog() - const { - maxSeats, - occupiedSeats, - subscription, - subscriptionStatus, - canAccessSubscriptionFeatures - } = useBillingContext() + const { maxSeats, occupiedSeats } = useBillingContext() const { canChangeSeats, canInviteMembers } = useBillingCapabilities() - // Ended (billing_status inactive) is the only member-management freeze. - // A cancel-scheduled subscription stays active until cancel_at and the - // backend permits seat adds the whole time — capability, invite endpoint, - // and Stripe write path all allow it (DES-1200; verified on cloud/main - // 2026-09-23) — so cancelled workspaces keep invites live. Two payload - // shapes report a terminal plan: subscription_status 'ended', and a - // cancelled row whose access has already closed (the backend reconciles - // that shape into 'ended' on read, but a stale payload can still carry - // it). Scoped by subscription shape, not seat capacity: when a plan - // truly ends the backend collapses max_seats to the no-plan default of 1 - // (observed on test: ended + ENTERPRISE + max_seats 1), so a seat gate - // reads the flagship ended workspace as "seatless" and hides the very - // explanation this state exists to show. A lapsed personal subscription - // stays out via the team/sales-managed gate instead. - const isPlanTerminal = computed( - () => - subscriptionStatus.value === 'ended' || - (subscriptionStatus.value === 'canceled' && - !canAccessSubscriptionFeatures.value) - ) - // Qualifying for the treatment needs a KNOWN signal — the team classifier - // or a real tier that is sales-managed. A terminal payload with no tier - // and no team signal is most plausibly a lapsed personal subscription, - // which belongs to the upgrade banner. (The nullish fail-close in - // isSalesManagedPlan below governs only the route back once a workspace - // is already in the treatment.) - const isPlanEnded = computed(() => { - if (!isPlanTerminal.value) return false - if (hasTeamPlan.value) return true - const tier = subscription.value?.tier - return tier != null && isSalesManagedTier(tier) - }) - // Sales-managed, not strictly ENTERPRISE: isSalesManagedTier() treats an - // unrecognized tier as sales-managed too, so an ended unknown/future plan - // routes to Contact sales rather than borrowing the self-serve Reactivate - // claim (the same fail-closed contract the pricing surfaces follow). A - // missing tier is equally unidentifiable, so it fails closed to the sales - // route too — never a self-serve Resume the capability would refuse. - const isSalesManagedPlan = computed(() => { - const tier = subscription.value?.tier - return tier == null ? true : isSalesManagedTier(tier) - }) - // Strict: drives the contactSales copy only — an unrecognized tier keeps - // the sales route but gets plan-neutral wording. - const isEnterprisePlan = computed( - () => subscription.value?.tier === 'ENTERPRISE' - ) + const { isPlanEnded, isSalesManagedPlan, isEnterprisePlan } = usePlanEnded() const permissions = computed(() => { const canManageMembers = diff --git a/src/platform/workspace/composables/usePlanEnded.ts b/src/platform/workspace/composables/usePlanEnded.ts new file mode 100644 index 00000000000..4f55aea1e70 --- /dev/null +++ b/src/platform/workspace/composables/usePlanEnded.ts @@ -0,0 +1,61 @@ +import { computed } from 'vue' + +import { useBillingContext } from '@/composables/billing/useBillingContext' +import { isSalesManagedTier } from '@/platform/cloud/subscription/constants/tierPricing' +import { useTeamPlan } from '@/platform/workspace/composables/useTeamPlan' + +export function usePlanEnded() { + const { subscription, subscriptionStatus, canAccessSubscriptionFeatures } = + useBillingContext() + const { hasTeamPlan } = useTeamPlan() + + // Ended (billing_status inactive) is the only member-management freeze. + // A cancel-scheduled subscription stays active until cancel_at and the + // backend permits seat adds the whole time — capability, invite endpoint, + // and Stripe write path all allow it (DES-1200; verified on cloud/main + // 2026-09-23) — so cancelled workspaces keep invites live. Two payload + // shapes report a terminal plan: subscription_status 'ended', and a + // cancelled row whose access has already closed (the backend reconciles + // that shape into 'ended' on read, but a stale payload can still carry + // it). Scoped by subscription shape, not seat capacity: when a plan + // truly ends the backend collapses max_seats to the no-plan default of 1 + // (observed on test: ended + ENTERPRISE + max_seats 1), so a seat gate + // reads the flagship ended workspace as "seatless" and hides the very + // explanation this state exists to show. A lapsed personal subscription + // stays out via the team/sales-managed gate instead. + const isPlanTerminal = computed( + () => + subscriptionStatus.value === 'ended' || + (subscriptionStatus.value === 'canceled' && + !canAccessSubscriptionFeatures.value) + ) + // Qualifying for the treatment needs a KNOWN signal — the team classifier + // or a real tier that is sales-managed. A terminal payload with no tier + // and no team signal is most plausibly a lapsed personal subscription, + // which belongs to the upgrade banner. (The nullish fail-close in + // isSalesManagedPlan below governs only the route back once a workspace + // is already in the treatment.) + const isPlanEnded = computed(() => { + if (!isPlanTerminal.value) return false + if (hasTeamPlan.value) return true + const tier = subscription.value?.tier + return tier != null && isSalesManagedTier(tier) + }) + // Sales-managed, not strictly ENTERPRISE: isSalesManagedTier() treats an + // unrecognized tier as sales-managed too, so an ended unknown/future plan + // routes to Contact sales rather than borrowing the self-serve Reactivate + // claim (the same fail-closed contract the pricing surfaces follow). A + // missing tier is equally unidentifiable, so it fails closed to the sales + // route too — never a self-serve Resume the capability would refuse. + const isSalesManagedPlan = computed(() => { + const tier = subscription.value?.tier + return tier == null ? true : isSalesManagedTier(tier) + }) + // Strict: drives the contactSales copy only — an unrecognized tier keeps + // the sales route but gets plan-neutral wording. + const isEnterprisePlan = computed( + () => subscription.value?.tier === 'ENTERPRISE' + ) + + return { isPlanEnded, isSalesManagedPlan, isEnterprisePlan } +}