Line data Source code
1 : import { computed } from 'vue'
2 :
3 : import { useBillingContext } from '@/platform/billing/composables/useBillingContext'
4 : import { isSalesManagedTier } from '@/platform/billing/subscription/constants/tierPricing'
5 : import { useTeamPlan } from '@/platform/billing/composables/useTeamPlan'
6 :
7 13 : export function usePlanEnded() {
8 13 : const { subscription, subscriptionStatus, canAccessSubscriptionFeatures } =
9 : useBillingContext()
10 13 : const { hasTeamPlan } = useTeamPlan()
11 :
12 : // Ended (billing_status inactive) is the only member-management freeze.
13 : // A cancel-scheduled subscription stays active until cancel_at and the
14 : // backend permits seat adds the whole time — capability, invite endpoint,
15 : // and Stripe write path all allow it (DES-1200; verified on cloud/main
16 : // 2026-09-23) — so cancelled workspaces keep invites live. Two payload
17 : // shapes report a terminal plan: subscription_status 'ended', and a
18 : // cancelled row whose access has already closed (the backend reconciles
19 : // that shape into 'ended' on read, but a stale payload can still carry
20 : // it). Scoped by subscription shape, not seat capacity: when a plan
21 : // truly ends the backend collapses max_seats to the no-plan default of 1
22 : // (observed on test: ended + ENTERPRISE + max_seats 1), so a seat gate
23 : // reads the flagship ended workspace as "seatless" and hides the very
24 : // explanation this state exists to show. A lapsed personal subscription
25 : // stays out via the team/sales-managed gate instead.
26 13 : const isPlanTerminal = computed(
27 : () =>
28 : subscriptionStatus.value === 'ended' ||
29 : (subscriptionStatus.value === 'canceled' &&
30 : !canAccessSubscriptionFeatures.value)
31 : )
32 : // Qualifying for the treatment needs a KNOWN signal — the team classifier
33 : // or a real tier that is sales-managed. A terminal payload with no tier
34 : // and no team signal is most plausibly a lapsed personal subscription,
35 : // which belongs to the upgrade banner. (The nullish fail-close in
36 : // isSalesManagedPlan below governs only the route back once a workspace
37 : // is already in the treatment.)
38 : const isPlanEnded = computed(() => {
39 0 : if (!isPlanTerminal.value) return false
40 0 : if (hasTeamPlan.value) return true
41 0 : const tier = subscription.value?.tier
42 0 : return tier != null && isSalesManagedTier(tier)
43 : })
44 : // Sales-managed, not strictly ENTERPRISE: isSalesManagedTier() treats an
45 : // unrecognized tier as sales-managed too, so an ended unknown/future plan
46 : // routes to Contact sales rather than borrowing the self-serve Reactivate
47 : // claim (the same fail-closed contract the pricing surfaces follow). A
48 : // missing tier is equally unidentifiable, so it fails closed to the sales
49 : // route too — never a self-serve Resume the capability would refuse.
50 : const isSalesManagedPlan = computed(() => {
51 0 : const tier = subscription.value?.tier
52 0 : return tier == null ? true : isSalesManagedTier(tier)
53 : })
54 : // Strict: drives the contactSales copy only — an unrecognized tier keeps
55 : // the sales route but gets plan-neutral wording.
56 : const isEnterprisePlan = computed(
57 : () => subscription.value?.tier === 'ENTERPRISE'
58 : )
59 :
60 13 : return { isPlanEnded, isPlanTerminal, isSalesManagedPlan, isEnterprisePlan }
61 : }
|