From 2bd38e3c93de3f29730df31d9a9687933cb3c2b5 Mon Sep 17 00:00:00 2001 From: ernstmul Date: Mon, 28 Apr 2025 12:04:12 +0200 Subject: [PATCH] Fix: correct apply credit flow on main --- .../(console)/apply-credit/+page.svelte | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/routes/(console)/apply-credit/+page.svelte b/src/routes/(console)/apply-credit/+page.svelte index e6c43520e..6b1bb48f8 100644 --- a/src/routes/(console)/apply-credit/+page.svelte +++ b/src/routes/(console)/apply-credit/+page.svelte @@ -14,7 +14,7 @@ } from '$lib/layout'; import { type PaymentList, type Plan } from '$lib/sdk/billing'; import { app } from '$lib/stores/app'; - import { isOrganization } from '$lib/stores/billing.js'; + import { plansInfo, isOrganization, type Tier } from '$lib/stores/billing.js'; import { addNotification } from '$lib/stores/notifications'; import { organizationList, @@ -71,7 +71,7 @@ let coupon: string; let couponData = data?.couponData; let campaign = data?.campaign; - let billingPlan = BillingPlan.PRO; + let billingPlan: Tier = BillingPlan.PRO; let currentPlan: Plan; function isUpgrade() { @@ -219,10 +219,21 @@ (team) => team.$id === selectedOrgId ) as Organization; - $: billingPlan = - selectedOrg?.billingPlan === BillingPlan.SCALE - ? BillingPlan.SCALE - : (campaign?.plan ?? BillingPlan.PRO); + function getBillingPlan(): Tier | undefined { + 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(); + } $: { if (selectedOrgId) { @@ -310,7 +321,7 @@ {/if} - {#if selectedOrg?.$id && selectedOrg?.billingPlan !== BillingPlan.FREE && selectedOrg?.billingPlan !== BillingPlan.GITHUB_EDUCATION} + {#if selectedOrg?.$id && selectedOrg?.billingPlan === billingPlan}