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(); }