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
This commit is contained in:
Jeremy Wharton 2023-03-02 09:54:11 -06:00 committed by Storj Robot
parent 0676a4ca89
commit 662e916194
4 changed files with 70 additions and 11 deletions

View File

@ -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<boolean> {
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');
}
}

View File

@ -3,15 +3,18 @@
<template>
<div class="pricing-area">
<h1 class="pricing-area__title" aria-roledescription="title">Welcome to Storj</h1>
<p class="pricing-area__subtitle">Select an account type to continue.</p>
<div class="pricing-area__plans">
<PricingPlanContainer
v-for="(plan, index) in plans"
:key="index"
:plan="plan"
/>
</div>
<VLoader v-if="isLoading" class="pricing-area__loader" width="90px" height="90px" />
<template v-else>
<h1 class="pricing-area__title" aria-roledescription="title">Welcome to Storj</h1>
<p class="pricing-area__subtitle">Select an account type to continue.</p>
<div class="pricing-area__plans">
<PricingPlanContainer
v-for="(plan, index) in plans"
:key="index"
:plan="plan"
/>
</div>
</template>
</div>
</template>
@ -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<boolean>(true);
const plans = ref<PricingPlanInfo[]>([
new PricingPlanInfo(
@ -58,7 +66,7 @@ const plans = ref<PricingPlanInfo[]>([
/*
* 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;
});
</script>
<style scoped lang="scss">
.pricing-area {
&__loader {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
align-items: center;
}
&__title {
color: #14142b;
font-family: 'font_bold', sans-serif;

View File

@ -28,7 +28,7 @@ export interface PaymentsApi {
/**
* projectUsagePriceModel returns the project usage price model for the user.
*/
projectUsagePriceModel(): Promise<ProjectUsagePriceModel>;
projectUsagePriceModel(): Promise<ProjectUsagePriceModel>;
/**
* Add credit card
@ -112,6 +112,13 @@ export interface PaymentsApi {
* @throws Error
*/
purchasePricingPackage(token: string): Promise<void>;
/**
* Returns whether there is a pricing package configured for the user's partner.
*
* @throws Error
*/
pricingPackageAvailable(): Promise<boolean>;
}
export class AccountBalance {

View File

@ -87,4 +87,8 @@ export class PaymentsMock implements PaymentsApi {
purchasePricingPackage(_: string): Promise<void> {
throw new Error('Method not implemented');
}
pricingPackageAvailable(): Promise<boolean> {
throw new Error('Method not implemented');
}
}