From ad77b4ecff1fef0c1eabe73179e37b58568b580c Mon Sep 17 00:00:00 2001 From: Harsh Mahajan <127186841+HarshMN2345@users.noreply.github.com> Date: Thu, 14 Aug 2025 18:50:43 +0530 Subject: [PATCH] feat: adding new design chnages --- src/lib/components/estimatedCard.svelte | 11 + src/lib/components/index.ts | 1 + src/lib/sdk/billing.ts | 6 +- .../billing/+page.svelte | 4 +- .../billing/+page.ts | 58 ++- .../billing/planSummary.svelte | 425 ++++++++---------- .../billing/projectUsageAccordion.svelte | 65 +++ .../change-plan/+page.ts | 4 +- 8 files changed, 314 insertions(+), 260 deletions(-) create mode 100644 src/lib/components/estimatedCard.svelte create mode 100644 src/routes/(console)/organization-[organization]/billing/projectUsageAccordion.svelte diff --git a/src/lib/components/estimatedCard.svelte b/src/lib/components/estimatedCard.svelte new file mode 100644 index 000000000..14b5aaf1e --- /dev/null +++ b/src/lib/components/estimatedCard.svelte @@ -0,0 +1,11 @@ + + + + + + + diff --git a/src/lib/components/index.ts b/src/lib/components/index.ts index 3f451a4bf..678861167 100644 --- a/src/lib/components/index.ts +++ b/src/lib/components/index.ts @@ -84,3 +84,4 @@ export { default as UsageCard } from './usageCard.svelte'; export { default as ViewToggle } from './viewToggle.svelte'; export { default as RegionEndpoint } from './regionEndpoint.svelte'; export { default as ExpirationInput } from './expirationInput.svelte'; +export { default as EstimatedCard } from './estimatedCard.svelte'; diff --git a/src/lib/sdk/billing.ts b/src/lib/sdk/billing.ts index 4692bbcd7..9a0163599 100644 --- a/src/lib/sdk/billing.ts +++ b/src/lib/sdk/billing.ts @@ -207,7 +207,7 @@ export type AggregationTeam = { * Aggregation billing plan */ plan: string; - projectBreakdown: ProjectBreakdown[] + projectBreakdown: ProjectBreakdown[]; }; export type ProjectBreakdown = { @@ -215,13 +215,13 @@ export type ProjectBreakdown = { name: string; amount: number; resources: InvoiceUsage[]; -} +}; export type InvoiceUsage = { resourceId: string; value: number; amount: number; -} +}; export type AvailableCredit = { available: number; diff --git a/src/routes/(console)/organization-[organization]/billing/+page.svelte b/src/routes/(console)/organization-[organization]/billing/+page.svelte index ae2674465..bd3ee281f 100644 --- a/src/routes/(console)/organization-[organization]/billing/+page.svelte +++ b/src/routes/(console)/organization-[organization]/billing/+page.svelte @@ -132,7 +132,9 @@ availableCredit={data?.availableCredit} currentPlan={data?.currentPlan} currentAggregation={data?.billingAggregation} - currentInvoice={data?.billingInvoice} /> + currentInvoice={data?.billingInvoice} + organizationUsage={data?.organizationUsage} + usageProjects={data?.usageProjects} /> { const { organization, scopes, currentPlan, countryList, locale } = await parent(); @@ -57,16 +60,27 @@ export const load: PageLoad = async ({ parent, depends }) => { organization?.billingPlan !== BillingPlan.GITHUB_EDUCATION)) : false; - const [paymentMethods, addressList, billingAddress, availableCredit] = await Promise.all([ - sdk.forConsole.billing.listPaymentMethods(), - sdk.forConsole.billing.listAddresses(), - billingAddressPromise, - areCreditsSupported ? sdk.forConsole.billing.getAvailableCredit(organization.$id) : null - ]); + const [paymentMethods, addressList, billingAddress, availableCredit, organizationUsage] = + await Promise.all([ + sdk.forConsole.billing.listPaymentMethods(), + sdk.forConsole.billing.listAddresses(), + billingAddressPromise, + areCreditsSupported + ? sdk.forConsole.billing.getAvailableCredit(organization.$id) + : null, + sdk.forConsole.billing.listUsage( + organization.$id, + organization.billingCurrentInvoiceDate, + organization.billingNextInvoiceDate + ) + ]); // make number const credits = availableCredit ? availableCredit.available : null; + // Get project information for usage display + const usageProjects = organizationUsage ? await getUsageProjects(organizationUsage) : {}; + return { paymentMethods, addressList, @@ -76,6 +90,36 @@ export const load: PageLoad = async ({ parent, depends }) => { billingInvoice, areCreditsSupported, countryList, - locale + locale, + organizationUsage, + usageProjects }; }; + +// Get project names and regions for usage display +async function getUsageProjects( + usage: OrganizationUsage +): Promise> { + const projects: Record = {}; + const limit = 100; + const requests = []; + + for (let index = 0; index < usage.projects.length; index += limit) { + const chunkIds = usage.projects.slice(index, index + limit).map((p) => p.projectId); + requests.push( + sdk.forConsole.projects.list([Query.limit(limit), Query.equal('$id', chunkIds)]) + ); + } + + const responses = await Promise.all(requests); + for (const response of responses) { + for (const project of response.projects) { + projects[project.$id] = { + name: project.name, + region: project.region + }; + } + } + + return projects; +} diff --git a/src/routes/(console)/organization-[organization]/billing/planSummary.svelte b/src/routes/(console)/organization-[organization]/billing/planSummary.svelte index 11b2e824c..324a30b23 100644 --- a/src/routes/(console)/organization-[organization]/billing/planSummary.svelte +++ b/src/routes/(console)/organization-[organization]/billing/planSummary.svelte @@ -1,31 +1,25 @@ {#if $organization} - {#if currentPlan.usagePerProject} - + + {currentPlan.name} plan + + + Next payment of {formatCurrency(currentInvoice?.amount || currentPlan?.price || 0)} + will occur on + {toLocaleDate($organization?.billingNextInvoiceDate)}. + + + + +
+ + Current billing cycle ({new Date( + $organization?.billingCurrentInvoiceDate + ).toLocaleDateString('en', { day: 'numeric', month: 'short' })}-{new Date( + $organization?.billingNextInvoiceDate + ).toLocaleDateString('en', { day: 'numeric', month: 'short' })}) + + + Estimate, subject to change based on usage. + +
+ + + - - {currentPlan.name} plan - - - Next payment of ${currentAggregation.amount} - will occur on - {toLocaleDate($organization?.billingNextInvoiceDate)} - - - - - - - + +
+ Base plan + + {formatCurrency( + isTrial || $organization?.billingPlan === BillingPlan.GITHUB_EDUCATION + ? 0 + : currentPlan?.price || 0 + )} + +
+ + + {#if organizationUsage?.projects && organizationUsage.projects.length > 0} + + {/if} + + + {#if currentPlan.budgeting && extraUsage > 0} + {#each currentAggregation.resources.filter((r) => r.amount && r.amount > 0) as excess} +
Base plan - - {isTrial || - $organization?.billingPlan === BillingPlan.GITHUB_EDUCATION - ? formatCurrency(0) - : currentPlan - ? formatCurrency(currentPlan?.price) - : ''} - - - - - {#each currentAggregation.resources.filter((r) => r.amount && r.amount > 0 && Object.keys(currentPlan.addons).includes(r.resourceId) && currentPlan.addons[r.resourceId].price > 0) as excess, i} - {#if i > 0} - - {/if} - - - - {excess.resourceId} - - {formatCurrency(excess.amount)} - - - - - {/each} - {#each currentAggregation.projectBreakdown as projectBreakdown} - - - {formatCurrency(projectBreakdown.amount)} - - - {#each projectBreakdown.resources as resource, i} - {#if i > 0} - - {/if} + >{excess.resourceId} + {formatCurrency(excess.amount)} +
+ {/each} + {/if} - - - - {resource.resourceId} - - - {formatCurrency(resource.amount)} - - - - - - {formatNumberWithCommas(resource.value)} - - {abbreviateNumber(resource.value)} - - - - {/each} -
- - {/each} -
+ {#if currentPlan.supportsCredits && availableCredit > 0} +
+
+ + Credits to be applied +
+ + -{formatCurrency( + Math.min(availableCredit, currentInvoice?.amount ?? 0) + )} + +
+ {/if} + + + + +
+ Total + + {formatCurrency( + Math.max( + (currentInvoice?.amount ?? 0) - + Math.min(availableCredit, currentInvoice?.amount ?? 0), + 0 + ) + )} + +
+
- {:else} - - 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} - r.amount && r.amount > 0) - .length.toString()}> - - {formatCurrency(extraUsage >= 0 ? extraUsage : 0)} - - - {#each currentAggregation.resources.filter((r) => r.amount && r.amount > 0) as excess, i} - {#if i > 0} - - {/if} - - - - - {excess.resourceId} - - - {formatCurrency(excess.amount)} - - - - - - {formatNumberWithCommas(excess.value)} - - {abbreviateNumber(excess.value)} - - - - {/each} - - - {/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} -
- + +
+ {#if $organization?.billingPlan === BillingPlan.FREE || $organization?.billingPlan === BillingPlan.GITHUB_EDUCATION} +
+ + +
+ {:else} +
+ {#if $organization?.billingPlanDowngrade !== null} + + {:else} -
- {:else} -
- {#if $organization?.billingPlanDowngrade !== null} - - {:else} - - {/if} - -
- {/if} - - - {/if} + {/if} + +
+ {/if} +
+
{/if} @@ -290,6 +182,44 @@ --billing-card-border-color: hsl(var(--color-neutral-10)); } + .billing-row { + display: flex; + justify-content: space-between; + align-items: center; + padding: 0.75rem 0; + border-bottom: 1px solid var(--bgcolor-neutral-invert); + } + + .billing-row:last-child { + border-bottom: none; + } + + .billing-row.total { + border-top: 1px solid var(--bgcolor-neutral-invert); + border-bottom: none; + padding-top: 1rem; + margin-top: 0.5rem; + } + + .price { + text-align: right; + min-width: 80px; + } + + .credits-content { + display: flex; + align-items: center; + gap: 0.5rem; + } + + .billing-cycle-header { + display: flex; + justify-content: space-between; + align-items: flex-start; + margin-bottom: 1rem; + margin-top: 1.5rem; + } + :global(.card-only-on-desktop) { background: hsl(var(--color-neutral-5)); border-radius: var(--corner-radius-medium, 8px); @@ -307,12 +237,15 @@ } @media (max-width: 768px) { + .billing-cycle-header { + flex-direction: column; + gap: 8px; + } + :global(.card-only-on-desktop) { padding: 0.5rem; box-shadow: unset; border-radius: unset; - - /* yes, these `!important`s are needed */ border: unset !important; background: unset !important; } diff --git a/src/routes/(console)/organization-[organization]/billing/projectUsageAccordion.svelte b/src/routes/(console)/organization-[organization]/billing/projectUsageAccordion.svelte new file mode 100644 index 000000000..1cf10c181 --- /dev/null +++ b/src/routes/(console)/organization-[organization]/billing/projectUsageAccordion.svelte @@ -0,0 +1,65 @@ + + +{#if projects && projects.length > 0} + + {#each projects as project, index} + {@const projectInfo = usageProjects[project.projectId]} + {@const projectCost = getUsageCost(project.projectId)} + {@const projectName = projectInfo?.name || 'Unknown Project'} + {@const isLastItem = index === projects.length - 1} + + + + {formatCurrency(projectCost)} + + +
+ {projectName} + {formatCurrency(projectCost)} +
+
+
+ {/each} +
+{:else} + + + No projects with usage data found + + +{/if} + + diff --git a/src/routes/(console)/organization-[organization]/change-plan/+page.ts b/src/routes/(console)/organization-[organization]/change-plan/+page.ts index 5f1af0a4e..2272bd636 100644 --- a/src/routes/(console)/organization-[organization]/change-plan/+page.ts +++ b/src/routes/(console)/organization-[organization]/change-plan/+page.ts @@ -7,9 +7,7 @@ export const load: PageLoad = async ({ depends, parent }) => { const { members, currentPlan, organizations } = await parent(); depends(Dependencies.UPGRADE_PLAN); - const [plans] = await Promise.all([ - sdk.forConsole.billing.listPlans() - ]); + const [plans] = await Promise.all([sdk.forConsole.billing.listPlans()]); let plan: BillingPlan; if (currentPlan?.$id === BillingPlan.SCALE) {