Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
},
"dependencies": {
"@ai-sdk/svelte": "^1.1.24",
"@appwrite.io/console": "https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@6031134",
"@appwrite.io/console": "https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@2515",
"@appwrite.io/pink-icons": "0.25.0",
"@appwrite.io/pink-icons-svelte": "https://pkg.vc/-/@appwrite/@appwrite.io/pink-icons-svelte@2cf27e0",
"@appwrite.io/pink-icons-svelte": "https://pkg.vc/-/@appwrite/@appwrite.io/pink-icons-svelte@ba96092",
"@appwrite.io/pink-legacy": "^1.0.3",
"@appwrite.io/pink-svelte": "https://pkg.vc/-/@appwrite/@appwrite.io/pink-svelte@fb8b1ed",
"@appwrite.io/pink-svelte": "https://pkg.vc/-/@appwrite/@appwrite.io/pink-svelte@ba96092",
"@faker-js/faker": "^9.9.0",
"@popperjs/core": "^2.11.8",
"@sentry/sveltekit": "^8.38.0",
Expand Down
30 changes: 15 additions & 15 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions src/lib/sdk/billing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -934,12 +934,19 @@ export class Billing {
);
}

async getAggregation(organizationId: string, aggregationId: string): Promise<AggregationTeam> {
async getAggregation(
organizationId: string,
aggregationId: string,
limit?: number,
offset?: number
): Promise<AggregationTeam> {
const path = `/organizations/${organizationId}/aggregations/${aggregationId}`;
const params = {
const params: Record<string, unknown> = {
organizationId,
aggregationId
};
if (typeof limit === 'number') params['limit'] = limit;
if (typeof offset === 'number') params['offset'] = offset;
const uri = new URL(this.client.config.endpoint + path);
return await this.client.call(
'get',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@
availableCredit={data?.availableCredit}
currentPlan={data?.currentPlan}
nextPlan={data?.nextPlan}
currentAggregation={data?.billingAggregation} />
currentAggregation={data?.billingAggregation}
limit={data?.limit}
offset={data?.offset}
aggregationKey={data?.aggregationKey} />
{:else}
<PlanSummaryOld
availableCredit={data?.availableCredit}
Expand Down
20 changes: 17 additions & 3 deletions src/routes/(console)/organization-[organization]/billing/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { redirect } from '@sveltejs/kit';
import type { PageLoad } from './$types';
import { isCloud } from '$lib/system';

export const load: PageLoad = async ({ parent, depends }) => {
import { getLimit, getPage, pageToOffset } from '$lib/helpers/load';

export const load: PageLoad = async ({ parent, depends, url, route }) => {
const { organization, scopes, currentPlan, countryList, locale } = await parent();

if (!scopes.includes('billing.read')) {
Expand All @@ -18,6 +20,8 @@ export const load: PageLoad = async ({ parent, depends }) => {
depends(Dependencies.CREDIT);
depends(Dependencies.INVOICES);
depends(Dependencies.ADDRESS);
//aggregation reloads on page param changes
depends('billing:aggregation');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets make a const in Dependencies for this.


const billingAddressId = (organization as Organization)?.billingAddressId;
const billingAddressPromise: Promise<Address> = billingAddressId
Expand All @@ -33,9 +37,14 @@ export const load: PageLoad = async ({ parent, depends }) => {
*/
let billingAggregation = null;
try {
const currentPage = getPage(url) || 1;
const limit = getLimit(url, route, 5);
const offset = pageToOffset(currentPage, limit);
billingAggregation = await sdk.forConsole.billing.getAggregation(
organization.$id,
(organization as Organization)?.billingAggregationId
(organization as Organization)?.billingAggregationId,
limit,
offset
);
} catch (e) {
// ignore error
Expand Down Expand Up @@ -83,6 +92,11 @@ export const load: PageLoad = async ({ parent, depends }) => {
areCreditsSupported,
countryList,
locale,
nextPlan: billingPlanDowngrade
nextPlan: billingPlanDowngrade,
// expose pagination for components
limit: getLimit(url, route, 5),
offset: pageToOffset(getPage(url) || 1, getLimit(url, route, 5)),
// unique key to force component refresh on page change
aggregationKey: `agg:${getPage(url) || 1}:${getLimit(url, route, 5)}`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just invalidate the dependency?

};
};
Loading