From b887d0e82527761af10ce6bad30dbcb3cb46efc3 Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Sat, 31 May 2025 14:41:17 -0700 Subject: [PATCH] fix: billingPlan when applying credits Ensure applying: 1. credits when on Free org will upgrade org to Pro 2. regular credits when on Pro org will leave plan unchanged 3. regular credits when on Scale or above org will leave plan unchanged 4. startup credits when on Free org will upgrade org to Scale --- .../(console)/apply-credit/+page.svelte | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/routes/(console)/apply-credit/+page.svelte b/src/routes/(console)/apply-credit/+page.svelte index 876badabf..e667f6456 100644 --- a/src/routes/(console)/apply-credit/+page.svelte +++ b/src/routes/(console)/apply-credit/+page.svelte @@ -77,7 +77,7 @@ $: selectedOrgId = tempOrgId; function isUpgrade() { - const newPlan = page.data.plansInfo.get(billingPlan); + const newPlan = $plansInfo.get(billingPlan); return currentPlan && newPlan && currentPlan.order < newPlan.order; } @@ -227,24 +227,22 @@ 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; + const newPlan = $plansInfo.get(billingPlan); - if (!campaignPlan && !orgPlan) { - return; + // if campaign has a plan and it's higher than the selected new plan + if (campaignPlan?.order > newPlan?.order) { + return campaignPlan.$id as Tier; } - if (!campaignPlan) { - return selectedOrg?.billingPlan; + + // if current plan's order is higher than the selected new plan + if (currentPlan?.order > newPlan?.order) { + return currentPlan.$id as Tier; } - if (!orgPlan) { - return campaign.plan; - } - return campaignPlan.order > orgPlan.order ? campaign.plan : selectedOrg?.billingPlan; + + return billingPlan; } - $: if (selectedOrg) { + $: if (currentPlan) { billingPlan = getBillingPlan(); }