Skip to content

Commit b592255

Browse files
Merge pull request #2350 from appwrite/feat-SER-347-Add-pagination-new-billing-ui
feat: pagination on billing ui table and refactoring it
2 parents 4371c8f + 1a0ea48 commit b592255

7 files changed

Lines changed: 568 additions & 448 deletions

File tree

src/lib/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export const PAGE_LIMIT = 12; // default page limit
22
export const SPREADSHEET_PAGE_LIMIT = 50; // default sheet page limit
33
export const CARD_LIMIT = 6; // default card limit
4+
export const DEFAULT_BILLING_PROJECTS_LIMIT = 5; // default billing projects page limit
45
export const INTERVAL = 5 * 60000; // default interval to check for feedback
56
export const NEW_DEV_PRO_UPGRADE_COUPON = 'appw50';
67

@@ -24,6 +25,7 @@ export enum Dependencies {
2425
CREDIT = 'dependency:credit',
2526
INVOICES = 'dependency:invoices',
2627
ADDRESS = 'dependency:address',
28+
BILLING_AGGREGATION = 'dependency:billing_aggregation',
2729
UPGRADE_PLAN = 'dependency:upgrade_plan',
2830
ORGANIZATIONS = 'dependency:organizations',
2931
PAYMENT_METHODS = 'dependency:paymentMethods',

src/lib/sdk/billing.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -935,12 +935,24 @@ export class Billing {
935935
);
936936
}
937937

938-
async getAggregation(organizationId: string, aggregationId: string): Promise<AggregationTeam> {
938+
async getAggregation(
939+
organizationId: string,
940+
aggregationId: string,
941+
limit?: number,
942+
offset?: number
943+
): Promise<AggregationTeam> {
939944
const path = `/organizations/${organizationId}/aggregations/${aggregationId}`;
940-
const params = {
945+
const params: {
946+
organizationId: string;
947+
aggregationId: string;
948+
limit?: number;
949+
offset?: number;
950+
} = {
941951
organizationId,
942952
aggregationId
943953
};
954+
if (typeof limit === 'number') params.limit = limit;
955+
if (typeof offset === 'number') params.offset = offset;
944956
const uri = new URL(this.client.config.endpoint + path);
945957
return await this.client.call(
946958
'get',

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@
135135
availableCredit={data?.availableCredit}
136136
currentPlan={data?.currentPlan}
137137
nextPlan={data?.nextPlan}
138-
currentAggregation={data?.billingAggregation} />
138+
currentAggregation={data?.billingAggregation}
139+
limit={data?.limit}
140+
offset={data?.offset} />
139141
{:else}
140142
<PlanSummaryOld
141143
availableCredit={data?.availableCredit}

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BillingPlan, Dependencies } from '$lib/constants';
1+
import { BillingPlan, DEFAULT_BILLING_PROJECTS_LIMIT, Dependencies } from '$lib/constants';
22
import type { Address } from '$lib/sdk/billing';
33
import { type Organization } from '$lib/stores/organization';
44
import { sdk } from '$lib/stores/sdk';
@@ -7,7 +7,9 @@ import type { PageLoad } from './$types';
77
import { isCloud } from '$lib/system';
88
import { 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

Comments
 (0)