Line data Source code
1 : import { computed } from 'vue'
2 :
3 : import { useFeatureFlags } from '@/composables/useFeatureFlags'
4 : import { useBillingSdkStore } from '@/platform/billing/sdk/billingSdkStore'
5 : import type { SubscriptionRail } from '@/platform/billing/sdk/subscriptionOperationView'
6 : import { useBillingOperationStore } from '@/platform/billing/stores/billingOperationStore'
7 :
8 : /**
9 : * Which rail cancel, resubscribe and the payment portal run on. Null is the
10 : * legacy path.
11 : *
12 : * Read once at the start of an action and held for the whole of it, for the
13 : * same reason as `useTopupOperation`: a flag flip mid-flow must not issue on
14 : * one rail and observe the result on the other.
15 : */
16 0 : export function useSubscriptionRail(): SubscriptionRail | null {
17 0 : const { flags } = useFeatureFlags()
18 0 : return flags.billingSdkRailEnabled ? useBillingSdkStore() : null
19 : }
20 :
21 : /**
22 : * The pending subscription operation as the billing surfaces read it, from
23 : * whichever rail owns it. The reads are the commands' other half: an operation
24 : * issued on the SDK rail is driven by the lifecycle, so a surface reading the
25 : * legacy store describes one nothing is writing.
26 : */
27 0 : export function useSubscriptionOperationView() {
28 0 : const { flags } = useFeatureFlags()
29 0 : const sdkStore = flags.billingSdkRailEnabled ? useBillingSdkStore() : null
30 0 : const operationStore = useBillingOperationStore()
31 :
32 : const isSettingUp = computed(() =>
33 : sdkStore ? sdkStore.isSettingUp : operationStore.isSettingUp
34 : )
35 :
36 : const subscriptionActionUrl = computed(
37 : () =>
38 : (sdkStore ?? operationStore).subscriptionActionOperation?.actionUrl ??
39 : null
40 : )
41 :
42 0 : return { isSettingUp, subscriptionActionUrl }
43 : }
|