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
This commit is contained in:
Steven Nguyen
2025-06-01 10:24:50 -07:00
parent 763927afd2
commit b887d0e825
+12 -14
View File
@@ -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();
}