From d8deeb2ef4504e6dcc4b62dcde6ae48697213ac8 Mon Sep 17 00:00:00 2001 From: ernstmul Date: Tue, 15 Apr 2025 11:22:08 +0200 Subject: [PATCH] Fix flow for campaign credits apply --- .../billing/estimatedTotalBox.svelte | 2 +- .../(console)/apply-credit/+page.svelte | 29 ++++++++++++++----- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/lib/components/billing/estimatedTotalBox.svelte b/src/lib/components/billing/estimatedTotalBox.svelte index e8adcb489..112d506c1 100644 --- a/src/lib/components/billing/estimatedTotalBox.svelte +++ b/src/lib/components/billing/estimatedTotalBox.svelte @@ -43,7 +43,7 @@ Additional seats ({collaborators?.length}) + >Additional seats ({collaborators?.length ?? 0}) {formatCurrency(extraSeatsCost)} diff --git a/src/routes/(console)/apply-credit/+page.svelte b/src/routes/(console)/apply-credit/+page.svelte index 7defef00c..382ece19c 100644 --- a/src/routes/(console)/apply-credit/+page.svelte +++ b/src/routes/(console)/apply-credit/+page.svelte @@ -19,7 +19,7 @@ import { ID } from '@appwrite.io/console'; import { onMount } from 'svelte'; import { writable } from 'svelte/store'; - import { plansInfo } from '$lib/stores/billing'; + import { plansInfo, type Tier } from '$lib/stores/billing'; import { Fieldset, Icon, Layout, Tooltip } from '@appwrite.io/pink-svelte'; import { IconInfo } from '@appwrite.io/pink-icons-svelte'; @@ -66,7 +66,7 @@ let coupon: string; let couponData = data?.couponData; let campaign = data?.campaign; - let billingPlan = BillingPlan.PRO; + let billingPlan: Tier = BillingPlan.PRO; let tempOrgId = null; $: onlyNewOrgs = (campaign && campaign.onlyNewOrgs) || (couponData && couponData.onlyNewOrgs); @@ -197,10 +197,25 @@ (team) => team.$id === selectedOrgId ) as Organization; - $: billingPlan = - selectedOrg?.billingPlan === BillingPlan.SCALE - ? BillingPlan.SCALE - : (campaign?.plan ?? BillingPlan.PRO); + function getBillingPlan(): Tier | undefined { + const plansInfo = page.data.plansInfo; + const campaignPlan = + campaign?.plan && plansInfo.get(campaign.plan) ? plansInfo.get(campaign.plan) : null; + const orgPlan = + selectedOrg?.billingPlan && plansInfo.get(selectedOrg.billingPlan) + ? plansInfo.get(selectedOrg.billingPlan) + : null; + + if (!campaignPlan || !orgPlan) { + return; + } + + return campaignPlan.order > orgPlan.order ? campaign.plan : selectedOrg?.billingPlan; + } + + $: if (selectedOrg) { + billingPlan = getBillingPlan(); + } @@ -286,7 +301,7 @@ - {#if selectedOrg?.$id && selectedOrg?.billingPlan !== BillingPlan.FREE && selectedOrg?.billingPlan !== BillingPlan.GITHUB_EDUCATION} + {#if selectedOrg?.$id && selectedOrg?.billingPlan === billingPlan}