From 662e9161940136d74f003536c3393e4f8dcb3738 Mon Sep 17 00:00:00 2001 From: Jeremy Wharton Date: Thu, 2 Mar 2023 09:54:11 -0600 Subject: [PATCH] web/satellite: skip pricing plan step if no available packages The pricing plan selection step of the onboarding tour is skipped if there are no pricing packages configured for a user's partner. Change-Id: I14bacbfaa10acf4cb97db04724749111a73e3928 --- web/satellite/src/api/payments.ts | 16 ++++++ .../onboardingTour/steps/PricingPlanStep.vue | 52 +++++++++++++++---- web/satellite/src/types/payments.ts | 9 +++- web/satellite/tests/unit/mock/api/payments.ts | 4 ++ 4 files changed, 70 insertions(+), 11 deletions(-) diff --git a/web/satellite/src/api/payments.ts b/web/satellite/src/api/payments.ts index 9a68263cb..ba3eceea8 100644 --- a/web/satellite/src/api/payments.ts +++ b/web/satellite/src/api/payments.ts @@ -396,4 +396,20 @@ export class PaymentsHttpApi implements PaymentsApi { throw new Error('Could not purchase pricing package'); } + + /** + * Returns whether there is a pricing package configured for the user's partner. + * + * @throws Error + */ + public async pricingPackageAvailable(): Promise { + const path = `${this.ROOT_PATH}/package-available`; + const response = await this.client.get(path); + + if (response.ok) { + return await response.json(); + } + + throw new Error('Could not check pricing package availability'); + } } diff --git a/web/satellite/src/components/onboardingTour/steps/PricingPlanStep.vue b/web/satellite/src/components/onboardingTour/steps/PricingPlanStep.vue index 56edc43f2..cac9d748a 100644 --- a/web/satellite/src/components/onboardingTour/steps/PricingPlanStep.vue +++ b/web/satellite/src/components/onboardingTour/steps/PricingPlanStep.vue @@ -3,15 +3,18 @@ @@ -23,12 +26,17 @@ import { PricingPlanInfo, PricingPlanType } from '@/types/common'; import { User } from '@/types/users'; import { useNotify, useRouter, useStore } from '@/utils/hooks'; import { MetaUtils } from '@/utils/meta'; +import { PaymentsHttpApi } from '@/api/payments'; import PricingPlanContainer from '@/components/onboardingTour/steps/pricingPlanFlow/PricingPlanContainer.vue'; +import VLoader from '@/components/common/VLoader.vue'; const store = useStore(); const router = useRouter(); const notify = useNotify(); +const payments: PaymentsHttpApi = new PaymentsHttpApi(); + +const isLoading = ref(true); const plans = ref([ new PricingPlanInfo( @@ -58,7 +66,7 @@ const plans = ref([ /* * Loads pricing plan config. */ -onBeforeMount(() => { +onBeforeMount(async () => { const user: User = store.getters.user; const nextPath = RouteConfig.OnboardingTour.with(RouteConfig.OverviewStep).path; @@ -68,16 +76,29 @@ onBeforeMount(() => { return; } + let pkgAvailable = false; + try { + pkgAvailable = await payments.pricingPackageAvailable(); + } catch (error) { + notify.error(error.message, null); + } + if (!pkgAvailable) { + router.push(nextPath); + return; + } + let config; try { config = require('@/components/onboardingTour/steps/pricingPlanFlow/pricingPlanConfig.json'); } catch { + notify.error('No pricing plan configuration file.', null); router.push(nextPath); return; } const plan = config[user.partner]; if (!plan) { + notify.error(`No pricing plan configuration for partner '${user.partner}'.`, null); router.push(nextPath); return; } @@ -93,12 +114,23 @@ onBeforeMount(() => { plan.activationDescription, plan.successSubtitle, )); + + isLoading.value = false; });