From 293eac04ff0a9bfa15228560d92f5d7e88c56edd Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 15 Jan 2025 06:50:01 +0000 Subject: [PATCH] refactor plan selection --- src/lib/components/billing/index.ts | 2 + src/lib/components/billing/selectPlan.svelte | 52 +++++++++++++++++++ src/lib/sdk/billing.ts | 6 ++- .../create-organization/+page.svelte | 8 +-- .../change-plan/+page.svelte | 22 +++----- 5 files changed, 69 insertions(+), 21 deletions(-) create mode 100644 src/lib/components/billing/selectPlan.svelte diff --git a/src/lib/components/billing/index.ts b/src/lib/components/billing/index.ts index 266d217d8..0643e5922 100644 --- a/src/lib/components/billing/index.ts +++ b/src/lib/components/billing/index.ts @@ -7,3 +7,5 @@ export { default as PlanComparisonBox } from './planComparisonBox.svelte'; export { default as EmptyCardCloud } from './emptyCardCloud.svelte'; export { default as CreditsApplied } from './creditsApplied.svelte'; export { default as PlanSelection } from './planSelection.svelte'; +export { default as EstimatedTotal } from './estimatedTotal.svelte'; +export { default as SelectPlan } from './selectPlan.svelte'; \ No newline at end of file diff --git a/src/lib/components/billing/selectPlan.svelte b/src/lib/components/billing/selectPlan.svelte new file mode 100644 index 000000000..ecff50f99 --- /dev/null +++ b/src/lib/components/billing/selectPlan.svelte @@ -0,0 +1,52 @@ + + +{#if billingPlan} + +{/if} diff --git a/src/lib/sdk/billing.ts b/src/lib/sdk/billing.ts index f4734d500..2245053c6 100644 --- a/src/lib/sdk/billing.ts +++ b/src/lib/sdk/billing.ts @@ -296,7 +296,9 @@ export type PlanAddon = { export type Plan = { $id: string; name: string; + desc: string; price: number; + order: number; bandwidth: number; storage: number; webhooks: number; @@ -332,7 +334,7 @@ export type Plan = { supportsCredit: boolean; }; -export type PlansInfo = { +export type PlanList = { plans: Plan[]; total: number; }; @@ -1262,7 +1264,7 @@ export class Billing { ); } - async getPlansInfo(): Promise { + async getPlansInfo(): Promise { const path = `/console/plans`; const params = {}; const uri = new URL(this.client.config.endpoint + path); diff --git a/src/routes/(console)/create-organization/+page.svelte b/src/routes/(console)/create-organization/+page.svelte index 59e84076c..3b758b0d3 100644 --- a/src/routes/(console)/create-organization/+page.svelte +++ b/src/routes/(console)/create-organization/+page.svelte @@ -6,8 +6,10 @@ import { EstimatedTotalBox, PlanComparisonBox, - PlanSelection, - SelectPaymentMethod + SelectPaymentMethod, + + SelectPlan + } from '$lib/components/billing'; import EstimatedTotal from '$lib/components/billing/estimatedTotal.svelte'; import ValidateCreditModal from '$lib/components/billing/validateCreditModal.svelte'; @@ -222,7 +224,7 @@ For more details on our plans, visit our .

- + {#if billingPlan !== BillingPlan.FREE} $organization.billingPlan; - $: isDowngrade = billingPlan < $organization.billingPlan; + $: isUpgrade = $plansInfo.get(billingPlan).order > $currentPlan.order; + $: isDowngrade = $plansInfo.get(billingPlan).order < $currentPlan.order; $: if (billingPlan !== BillingPlan.FREE) { loadPaymentMethods(); } @@ -300,9 +299,8 @@ >Your contract is not eligible for manual changes. Please reach out to schedule a call or setup a dialog. {/if} - - {#if billingPlan !== BillingPlan.FREE && $organization.billingPlan !== billingPlan && $organization.billingPlan !== BillingPlan.CUSTOM} + {#if billingPlan !== BillingPlan.FREE && $organization.billingPlan !== billingPlan && $organization.billingPlan !== BillingPlan.CUSTOM && isUpgrade} - + {couponId} /> {:else if $organization.billingPlan !== BillingPlan.CUSTOM} {/if}