1- import { BillingPlan , Dependencies } from '$lib/constants' ;
1+ import { BillingPlan , DEFAULT_BILLING_PROJECTS_LIMIT , Dependencies } from '$lib/constants' ;
22import type { Address } from '$lib/sdk/billing' ;
33import { type Organization } from '$lib/stores/organization' ;
44import { sdk } from '$lib/stores/sdk' ;
@@ -7,7 +7,9 @@ import type { PageLoad } from './$types';
77import { isCloud } from '$lib/system' ;
88import { base } from '$app/paths' ;
99
10- export const load : PageLoad = async ( { parent, depends } ) => {
10+ import { getLimit , getPage , pageToOffset } from '$lib/helpers/load' ;
11+
12+ export const load : PageLoad = async ( { parent, depends, url, route } ) => {
1113 const { organization, scopes, currentPlan, countryList, locale } = await parent ( ) ;
1214
1315 if ( ! scopes . includes ( 'billing.read' ) ) {
@@ -19,6 +21,8 @@ export const load: PageLoad = async ({ parent, depends }) => {
1921 depends ( Dependencies . CREDIT ) ;
2022 depends ( Dependencies . INVOICES ) ;
2123 depends ( Dependencies . ADDRESS ) ;
24+ //aggregation reloads on page param changes
25+ depends ( Dependencies . BILLING_AGGREGATION ) ;
2226
2327 const billingAddressId = ( organization as Organization ) ?. billingAddressId ;
2428 const billingAddressPromise : Promise < Address > = billingAddressId
@@ -34,9 +38,14 @@ export const load: PageLoad = async ({ parent, depends }) => {
3438 */
3539 let billingAggregation = null ;
3640 try {
41+ const currentPage = getPage ( url ) || 1 ;
42+ const limit = getLimit ( url , route , DEFAULT_BILLING_PROJECTS_LIMIT ) ;
43+ const offset = pageToOffset ( currentPage , limit ) ;
3744 billingAggregation = await sdk . forConsole . billing . getAggregation (
3845 organization . $id ,
39- ( organization as Organization ) ?. billingAggregationId
46+ ( organization as Organization ) ?. billingAggregationId ,
47+ limit ,
48+ offset
4049 ) ;
4150 } catch ( e ) {
4251 // ignore error
@@ -84,6 +93,11 @@ export const load: PageLoad = async ({ parent, depends }) => {
8493 areCreditsSupported,
8594 countryList,
8695 locale,
87- nextPlan : billingPlanDowngrade
96+ nextPlan : billingPlanDowngrade ,
97+ limit : getLimit ( url , route , DEFAULT_BILLING_PROJECTS_LIMIT ) ,
98+ offset : pageToOffset (
99+ getPage ( url ) || 1 ,
100+ getLimit ( url , route , DEFAULT_BILLING_PROJECTS_LIMIT )
101+ )
88102 } ;
89103} ;
0 commit comments