Skip to content

Commit 29c12d6

Browse files
committed
feat: pagination on billing ui table
1 parent 7ba5bfd commit 29c12d6

File tree

6 files changed

+300
-208
lines changed

6 files changed

+300
-208
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
},
2323
"dependencies": {
2424
"@ai-sdk/svelte": "^1.1.24",
25-
"@appwrite.io/console": "https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@6031134",
25+
"@appwrite.io/console": "https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@2515",
2626
"@appwrite.io/pink-icons": "0.25.0",
2727
"@appwrite.io/pink-icons-svelte": "https://pkg.vc/-/@appwrite/@appwrite.io/pink-icons-svelte@2cf27e0",
2828
"@appwrite.io/pink-legacy": "^1.0.3",

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/sdk/billing.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -934,12 +934,19 @@ export class Billing {
934934
);
935935
}
936936

937-
async getAggregation(organizationId: string, aggregationId: string): Promise<AggregationTeam> {
937+
async getAggregation(
938+
organizationId: string,
939+
aggregationId: string,
940+
limit?: number,
941+
offset?: number
942+
): Promise<AggregationTeam> {
938943
const path = `/organizations/${organizationId}/aggregations/${aggregationId}`;
939-
const params = {
944+
const params: Record<string, unknown> = {
940945
organizationId,
941946
aggregationId
942947
};
948+
if (typeof limit === 'number') params['limit'] = limit;
949+
if (typeof offset === 'number') params['offset'] = offset;
943950
const uri = new URL(this.client.config.endpoint + path);
944951
return await this.client.call(
945952
'get',

src/routes/(console)/organization-[organization]/billing/+page.svelte

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,10 @@
133133
availableCredit={data?.availableCredit}
134134
currentPlan={data?.currentPlan}
135135
nextPlan={data?.nextPlan}
136-
currentAggregation={data?.billingAggregation} />
136+
currentAggregation={data?.billingAggregation}
137+
limit={data?.limit}
138+
offset={data?.offset}
139+
aggregationKey={data?.aggregationKey} />
137140
{:else}
138141
<PlanSummaryOld
139142
availableCredit={data?.availableCredit}

src/routes/(console)/organization-[organization]/billing/+page.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import { redirect } from '@sveltejs/kit';
66
import type { PageLoad } from './$types';
77
import { isCloud } from '$lib/system';
88

9-
export const load: PageLoad = async ({ parent, depends }) => {
9+
import { getLimit, getPage, pageToOffset } from '$lib/helpers/load';
10+
11+
export const load: PageLoad = async ({ parent, depends, url, route }) => {
1012
const { organization, scopes, currentPlan, countryList, locale } = await parent();
1113

1214
if (!scopes.includes('billing.read')) {
@@ -18,6 +20,8 @@ export const load: PageLoad = async ({ parent, depends }) => {
1820
depends(Dependencies.CREDIT);
1921
depends(Dependencies.INVOICES);
2022
depends(Dependencies.ADDRESS);
23+
//aggregation reloads on page param changes
24+
depends('billing:aggregation');
2125

2226
const billingAddressId = (organization as Organization)?.billingAddressId;
2327
const billingAddressPromise: Promise<Address> = billingAddressId
@@ -33,9 +37,14 @@ export const load: PageLoad = async ({ parent, depends }) => {
3337
*/
3438
let billingAggregation = null;
3539
try {
40+
const currentPage = getPage(url) || 1;
41+
const limit = getLimit(url, route, 5);
42+
const offset = pageToOffset(currentPage, limit);
3643
billingAggregation = await sdk.forConsole.billing.getAggregation(
3744
organization.$id,
38-
(organization as Organization)?.billingAggregationId
45+
(organization as Organization)?.billingAggregationId,
46+
limit,
47+
offset
3948
);
4049
} catch (e) {
4150
// ignore error
@@ -83,6 +92,11 @@ export const load: PageLoad = async ({ parent, depends }) => {
8392
areCreditsSupported,
8493
countryList,
8594
locale,
86-
nextPlan: billingPlanDowngrade
95+
nextPlan: billingPlanDowngrade,
96+
// expose pagination for components
97+
limit: getLimit(url, route, 5),
98+
offset: pageToOffset(getPage(url) || 1, getLimit(url, route, 5)),
99+
// unique key to force component refresh on page change
100+
aggregationKey: `agg:${getPage(url) || 1}:${getLimit(url, route, 5)}`
87101
};
88102
};

0 commit comments

Comments
 (0)