From 7b5e65dfc3a687e4336422aa2033eabd4e23d57f Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 31 Aug 2025 12:17:39 +0000 Subject: [PATCH] fix issues --- src/lib/components/billing/planExcess.svelte | 2 +- .../billing/+page.svelte | 4 +- .../billing/+page.ts | 68 +------------------ .../billing/planSummary.svelte | 1 + .../settings/usage/[[invoice]]/+page.ts | 4 +- 5 files changed, 6 insertions(+), 73 deletions(-) diff --git a/src/lib/components/billing/planExcess.svelte b/src/lib/components/billing/planExcess.svelte index 51dd96d45..f512f7a6d 100644 --- a/src/lib/components/billing/planExcess.svelte +++ b/src/lib/components/billing/planExcess.svelte @@ -28,7 +28,7 @@ executions?: number; members?: number; } = null; - let aggregation: Aggregation = null; + let aggregation: AggregationTeam = null; let showExcess = false; onMount(async () => { diff --git a/src/routes/(console)/organization-[organization]/billing/+page.svelte b/src/routes/(console)/organization-[organization]/billing/+page.svelte index 05299ad92..4f1b4bad5 100644 --- a/src/routes/(console)/organization-[organization]/billing/+page.svelte +++ b/src/routes/(console)/organization-[organization]/billing/+page.svelte @@ -133,9 +133,7 @@ availableCredit={data?.availableCredit} currentPlan={data?.currentPlan} currentAggregation={data?.billingAggregation} - currentInvoice={data?.billingInvoice} - organizationUsage={data?.organizationUsage} - usageProjects={data?.usageProjects} /> + currentInvoice={data?.billingInvoice} /> {:else} { const { organization, scopes, currentPlan, countryList, locale } = await parent(); @@ -59,68 +57,6 @@ export const load: PageLoad = async ({ parent, depends }) => { organization?.billingPlan !== BillingPlan.GITHUB_EDUCATION)) : false; - // load organization usage data and project metadata for planSummary component - let organizationUsage = null; - let usageProjects: Record = {}; - - // Dont fetch organization usage if the plan uses per-project pricing - if (!currentPlan?.usagePerProject) { - try { - organizationUsage = await sdk.forConsole.billing.listUsage(organization.$id); - } catch (e) { - organizationUsage = null; - } - } - - try { - const neededIds = new Set(); - const addId = (id?: string) => id && neededIds.add(id); - - if (currentPlan?.usagePerProject) { - if (billingAggregation?.projectBreakdown?.length) { - for (const p of billingAggregation.projectBreakdown) addId(p.$id); - } - } else { - // For organization pricing, fetch all projects - const allProjectsResponse = await sdk.forConsole.projects.list([ - Query.equal('teamId', organization.$id), - Query.limit(1000) // get all projects - ]); - - for (const project of allProjectsResponse.projects) { - usageProjects[project.$id] = { - name: project.name, - region: project.region - }; - } - - 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); - } - } - - // Fetch project metadata for projects that need it - const missingIds = - neededIds.size > 0 ? Array.from(neededIds).filter((id) => !usageProjects[id]) : []; - - if (missingIds.length > 0) { - const projectsResponse = await sdk.forConsole.projects.list([ - Query.equal('$id', missingIds), - Query.limit(missingIds.length) - ]); - for (const project of projectsResponse.projects) { - usageProjects[project.$id] = { - name: project.name, - region: project.region - }; - } - } - } catch (e) { - // ignore error - } - const [paymentMethods, addressList, billingAddress, availableCredit] = await Promise.all([ sdk.forConsole.billing.listPaymentMethods(), sdk.forConsole.billing.listAddresses(), @@ -140,8 +76,6 @@ export const load: PageLoad = async ({ parent, depends }) => { billingInvoice, areCreditsSupported, countryList, - locale, - organizationUsage, - usageProjects + locale }; }; diff --git a/src/routes/(console)/organization-[organization]/billing/planSummary.svelte b/src/routes/(console)/organization-[organization]/billing/planSummary.svelte index 3ebed6c01..38e75c63a 100644 --- a/src/routes/(console)/organization-[organization]/billing/planSummary.svelte +++ b/src/routes/(console)/organization-[organization]/billing/planSummary.svelte @@ -19,6 +19,7 @@ export let currentPlan: Plan; export let currentInvoice: Invoice | undefined = undefined; export let currentAggregation: AggregationTeam | undefined = undefined; + export let availableCredit: number | undefined = undefined; let showCancel: boolean = false; diff --git a/src/routes/(console)/project-[region]-[project]/settings/usage/[[invoice]]/+page.ts b/src/routes/(console)/project-[region]-[project]/settings/usage/[[invoice]]/+page.ts index 8c92b6d92..9f6c7d7c3 100644 --- a/src/routes/(console)/project-[region]-[project]/settings/usage/[[invoice]]/+page.ts +++ b/src/routes/(console)/project-[region]-[project]/settings/usage/[[invoice]]/+page.ts @@ -40,8 +40,8 @@ export const load: PageLoad = async ({ params, parent }) => { if (currentAggregation) { let projectSpecificData = null; - if (currentAggregation.projectBreakdown) { - projectSpecificData = currentAggregation.projectBreakdown.find( + if (currentAggregation.breakdown) { + projectSpecificData = currentAggregation.breakdown.find( (p) => p.$id === project ); }