From aa5672156358ace3800842cd7ea4aaceac2f2341 Mon Sep 17 00:00:00 2001 From: Harsh Mahajan <127186841+HarshMN2345@users.noreply.github.com> Date: Thu, 28 Aug 2025 17:21:07 +0530 Subject: [PATCH] gate new pricing UI by plan flag; optimize billing loads Add billingPlan prop to createProject.svelte; derive isProPlan from prop Introduce useNewPricingModal derived from currentPlan.usagePerProject Wire pricing modal triggers to use new modal only when usagePerProject is true Add planSummaryOld.svelte and conditionally render based on useNewPricingModal Optimize billing/+page.ts to fetch only needed projects by from usage/aggregation Remove no-op reactive block in planSummary.svelte; resolve unused prop warning --- src/lib/layout/containerHeader.svelte | 7 +- src/lib/layout/createProject.svelte | 4 +- src/lib/stores/billing.ts | 1 + .../billing/+page.svelte | 25 +- .../billing/+page.ts | 30 ++- .../billing/budgetCap.svelte | 4 +- .../billing/planSummary.svelte | 8 - .../billing/planSummaryOld.svelte | 250 ++++++++++++++++++ .../usage/[[invoice]]/+page.svelte | 9 +- .../settings/usage/[[invoice]]/+page.svelte | 11 +- 10 files changed, 313 insertions(+), 36 deletions(-) create mode 100644 src/routes/(console)/organization-[organization]/billing/planSummaryOld.svelte diff --git a/src/lib/layout/containerHeader.svelte b/src/lib/layout/containerHeader.svelte index 1e5a9fb95..a7af909f0 100644 --- a/src/lib/layout/containerHeader.svelte +++ b/src/lib/layout/containerHeader.svelte @@ -11,6 +11,7 @@ getServiceLimit, readOnly, showUsageRatesModal, + useNewPricingModal, tierToPlan, upgradeURL, type PlanServices @@ -101,7 +102,7 @@ You've reached the {services} limit for the {tier} plan. - ($showUsageRatesModal = true)} + ($showUsageRatesModal = $useNewPricingModal)} >Excess usage fees will apply. @@ -159,7 +160,9 @@

You are limited to {limit} {title.toLocaleLowerCase()} per organization on the {tier} plan. - ($showUsageRatesModal = true)} + + ($showUsageRatesModal = $useNewPricingModal)} >Excess usage fees will apply.

diff --git a/src/lib/layout/createProject.svelte b/src/lib/layout/createProject.svelte index 90701ef4d..13538ca1a 100644 --- a/src/lib/layout/createProject.svelte +++ b/src/lib/layout/createProject.svelte @@ -19,6 +19,7 @@ regions = [], region = $bindable(''), showTitle = true, + billingPlan = undefined, projects = undefined, submit }: { @@ -27,12 +28,13 @@ regions: Array; region: string; showTitle: boolean; + billingPlan?: BillingPlan; projects?: number; submit?: Snippet; } = $props(); let showCustomId = $state(false); - let isProPlan = $derived($organization?.billingPlan === BillingPlan.PRO); + let isProPlan = $derived((billingPlan ?? $organization?.billingPlan) === BillingPlan.PRO); let projectsLimited = $derived( isProPlan ? projects && projects >= 2 diff --git a/src/lib/stores/billing.ts b/src/lib/stores/billing.ts index e8b78bad8..c08cd31b1 100644 --- a/src/lib/stores/billing.ts +++ b/src/lib/stores/billing.ts @@ -235,6 +235,7 @@ export const tierEnterprise: TierData = { }; export const showUsageRatesModal = writable(false); +export const useNewPricingModal = derived(currentPlan, ($plan) => $plan?.usagePerProject === true); export function checkForUsageFees(plan: Tier, id: PlanServices) { if (plan === BillingPlan.PRO || plan === BillingPlan.SCALE) { diff --git a/src/routes/(console)/organization-[organization]/billing/+page.svelte b/src/routes/(console)/organization-[organization]/billing/+page.svelte index 8b5413f62..05299ad92 100644 --- a/src/routes/(console)/organization-[organization]/billing/+page.svelte +++ b/src/routes/(console)/organization-[organization]/billing/+page.svelte @@ -2,12 +2,13 @@ import { Container } from '$lib/layout'; import BudgetCap from './budgetCap.svelte'; import PlanSummary from './planSummary.svelte'; + import PlanSummaryOld from './planSummaryOld.svelte'; import BillingAddress from './billingAddress.svelte'; import PaymentMethods from './paymentMethods.svelte'; import AvailableCredit from './availableCredit.svelte'; import PaymentHistory from './paymentHistory.svelte'; import TaxId from './taxId.svelte'; - import { failedInvoice, tierToPlan, upgradeURL } from '$lib/stores/billing'; + import { failedInvoice, tierToPlan, upgradeURL, useNewPricingModal } from '$lib/stores/billing'; import type { PaymentMethodData } from '$lib/sdk/billing'; import { onMount } from 'svelte'; import { page } from '$app/state'; @@ -127,13 +128,21 @@ until your billing period ends on {toLocaleDate(organization.billingNextInvoiceDate)}.
{/if} - + {#if $useNewPricingModal} + + {:else} + + {/if} { } try { - const projectsResponse = await sdk.forConsole.projects.list([ - Query.equal('teamId', organization.$id), - Query.limit(1000) - ]); - for (const project of projectsResponse.projects) { - usageProjects[project.$id] = { - name: project.name, - region: project.region - }; + const neededIds = new Set(); + const addId = (id?: string) => id && neededIds.add(id); + + if (organizationUsage?.projects?.length) { + for (const p of organizationUsage.projects) addId(p.projectId); + } else if (billingAggregation?.projectBreakdown?.length) { + for (const p of billingAggregation.projectBreakdown) addId(p.$id); + } + + if (neededIds.size > 0) { + const ids = Array.from(neededIds); + const projectsResponse = await sdk.forConsole.projects.list([ + Query.equal('$id', ids), + Query.limit(ids.length) + ]); + for (const project of projectsResponse.projects) { + usageProjects[project.$id] = { + name: project.name, + region: project.region + }; + } } } catch (e) { // ignore error diff --git a/src/routes/(console)/organization-[organization]/billing/budgetCap.svelte b/src/routes/(console)/organization-[organization]/billing/budgetCap.svelte index bd08a88ca..dc8043eaa 100644 --- a/src/routes/(console)/organization-[organization]/billing/budgetCap.svelte +++ b/src/routes/(console)/organization-[organization]/billing/budgetCap.svelte @@ -4,7 +4,7 @@ import { CardGrid } from '$lib/components'; import { BillingPlan, Dependencies } from '$lib/constants'; import { Button, Form, InputNumber, InputSwitch } from '$lib/elements/forms'; - import { showUsageRatesModal, upgradeURL } from '$lib/stores/billing'; + import { showUsageRatesModal, upgradeURL, useNewPricingModal } from '$lib/stores/billing'; import { addNotification } from '$lib/stores/notifications'; import { type Organization } from '$lib/stores/organization'; import { sdk } from '$lib/stores/sdk'; @@ -72,7 +72,7 @@ Budget cap limits do not include the base amount of your plan. diff --git a/src/routes/(console)/organization-[organization]/billing/planSummary.svelte b/src/routes/(console)/organization-[organization]/billing/planSummary.svelte index 5c8167f4c..1a8f610ea 100644 --- a/src/routes/(console)/organization-[organization]/billing/planSummary.svelte +++ b/src/routes/(console)/organization-[organization]/billing/planSummary.svelte @@ -19,17 +19,9 @@ export let currentPlan: Plan; export let currentInvoice: Invoice | undefined = undefined; export let currentAggregation: AggregationTeam | undefined = undefined; - export let availableCredit: number | undefined = undefined; export let organizationUsage: any = undefined; export let usageProjects: Record = {}; - $: { - currentAggregation; - availableCredit; - organizationUsage; - usageProjects; - } - let showCancel: boolean = false; // define columns for the expandable table diff --git a/src/routes/(console)/organization-[organization]/billing/planSummaryOld.svelte b/src/routes/(console)/organization-[organization]/billing/planSummaryOld.svelte new file mode 100644 index 000000000..3f27119c9 --- /dev/null +++ b/src/routes/(console)/organization-[organization]/billing/planSummaryOld.svelte @@ -0,0 +1,250 @@ + + +{#if $organization} + + Payment estimates + A breakdown of your estimated upcoming payment for the current billing period. Totals displayed + exclude accumulated credits and applicable taxes. + +

+ Due at: {toLocaleDate($organization?.billingNextInvoiceDate)} +

+ + + + + {currentPlan.name} plan + + + {isTrial || $organization?.billingPlan === BillingPlan.GITHUB_EDUCATION + ? formatCurrency(0) + : currentPlan + ? formatCurrency(currentPlan?.price) + : ''} + + + + {#if currentPlan.budgeting && extraUsage > 0} + 0 + ? currentInvoice.usage.length + 1 + : currentInvoice.usage.length + ).toString()}> + + {formatCurrency(extraUsage >= 0 ? extraUsage : 0)} + + + {#if currentAggregation.additionalMembers} + + + Additional members + + {formatCurrency( + currentAggregation.additionalMemberAmount + )} + + + + {currentAggregation.additionalMembers} + + + {/if} + {#if currentInvoice?.usage} + {#each currentInvoice.usage as excess, i} + {#if i > 0 || currentAggregation.additionalMembers} + + {/if} + + + + + {excess.name} + + + {formatCurrency(excess.amount)} + + + + + + {formatNumberWithCommas(excess.value)} + + {abbreviateNumber(excess.value)} + + + + {/each} + {/if} + + + {/if} + + {#if currentPlan.supportsCredits && availableCredit > 0} + + + + Credits to be applied + + + -{formatCurrency( + Math.min(availableCredit, currentInvoice?.amount ?? 0) + )} + + + {/if} + + {#if $organization?.billingPlan !== BillingPlan.FREE && $organization?.billingPlan !== BillingPlan.GITHUB_EDUCATION} + + + + + Current total (USD) + + + + Estimates are updated daily and may differ from your + final invoice. + + + + + + {formatCurrency( + Math.max( + (currentInvoice?.amount ?? 0) - + Math.min(availableCredit, currentInvoice?.amount ?? 0), + 0 + ) + )} + + + {/if} + + +
+ + {#if $organization?.billingPlan === BillingPlan.FREE || $organization?.billingPlan === BillingPlan.GITHUB_EDUCATION} +
+ + +
+ {:else} +
+ {#if $organization?.billingPlanDowngrade !== null} + + {:else} + + {/if} + +
+ {/if} +
+
+{/if} + + + + diff --git a/src/routes/(console)/organization-[organization]/usage/[[invoice]]/+page.svelte b/src/routes/(console)/organization-[organization]/usage/[[invoice]]/+page.svelte index e27353624..99d1077f6 100644 --- a/src/routes/(console)/organization-[organization]/usage/[[invoice]]/+page.svelte +++ b/src/routes/(console)/organization-[organization]/usage/[[invoice]]/+page.svelte @@ -8,7 +8,8 @@ getServiceLimit, showUsageRatesModal, type Tier, - upgradeURL + upgradeURL, + useNewPricingModal } from '$lib/stores/billing'; import { organization } from '$lib/stores/organization'; import ProjectBreakdown from './ProjectBreakdown.svelte'; @@ -76,13 +77,15 @@ {#if $organization.billingPlan === BillingPlan.SCALE}

On the Scale plan, you'll be charged only for any usage that exceeds the thresholds per - resource listed below. ($showUsageRatesModal = true)} + resource listed below. ($showUsageRatesModal = $useNewPricingModal)} >Learn more

{:else if $organization.billingPlan === BillingPlan.PRO}

On the Pro plan, you'll be charged only for any usage that exceeds the thresholds per - resource listed below. ($showUsageRatesModal = true)} + resource listed below. ($showUsageRatesModal = $useNewPricingModal)} >Learn more

{:else if $organization.billingPlan === BillingPlan.FREE} diff --git a/src/routes/(console)/project-[region]-[project]/settings/usage/[[invoice]]/+page.svelte b/src/routes/(console)/project-[region]-[project]/settings/usage/[[invoice]]/+page.svelte index 24b82ae7b..a6ad580a0 100644 --- a/src/routes/(console)/project-[region]-[project]/settings/usage/[[invoice]]/+page.svelte +++ b/src/routes/(console)/project-[region]-[project]/settings/usage/[[invoice]]/+page.svelte @@ -1,7 +1,12 @@