mirror of
https://github.com/appwrite/console.git
synced 2026-06-06 19:27:48 +00:00
fix issues
This commit is contained in:
@@ -28,7 +28,7 @@
|
||||
executions?: number;
|
||||
members?: number;
|
||||
} = null;
|
||||
let aggregation: Aggregation = null;
|
||||
let aggregation: AggregationTeam = null;
|
||||
let showExcess = false;
|
||||
|
||||
onMount(async () => {
|
||||
|
||||
@@ -133,9 +133,7 @@
|
||||
availableCredit={data?.availableCredit}
|
||||
currentPlan={data?.currentPlan}
|
||||
currentAggregation={data?.billingAggregation}
|
||||
currentInvoice={data?.billingInvoice}
|
||||
organizationUsage={data?.organizationUsage}
|
||||
usageProjects={data?.usageProjects} />
|
||||
currentInvoice={data?.billingInvoice} />
|
||||
{:else}
|
||||
<PlanSummaryOld
|
||||
availableCredit={data?.availableCredit}
|
||||
|
||||
@@ -5,8 +5,6 @@ import { sdk } from '$lib/stores/sdk';
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
import type { PageLoad } from './$types';
|
||||
import { isCloud } from '$lib/system';
|
||||
import { Query } from '@appwrite.io/console';
|
||||
import type { UsageProjectInfo } from '../store';
|
||||
|
||||
export const load: PageLoad = async ({ parent, depends }) => {
|
||||
const { organization, scopes, currentPlan, countryList, locale } = await parent();
|
||||
@@ -59,68 +57,6 @@ export const load: PageLoad = async ({ parent, depends }) => {
|
||||
organization?.billingPlan !== BillingPlan.GITHUB_EDUCATION))
|
||||
: false;
|
||||
|
||||
// load organization usage data and project metadata for planSummary component
|
||||
let organizationUsage = null;
|
||||
let usageProjects: Record<string, UsageProjectInfo> = {};
|
||||
|
||||
// Dont fetch organization usage if the plan uses per-project pricing
|
||||
if (!currentPlan?.usagePerProject) {
|
||||
try {
|
||||
organizationUsage = await sdk.forConsole.billing.listUsage(organization.$id);
|
||||
} catch (e) {
|
||||
organizationUsage = null;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const neededIds = new Set<string>();
|
||||
const addId = (id?: string) => id && neededIds.add(id);
|
||||
|
||||
if (currentPlan?.usagePerProject) {
|
||||
if (billingAggregation?.projectBreakdown?.length) {
|
||||
for (const p of billingAggregation.projectBreakdown) addId(p.$id);
|
||||
}
|
||||
} else {
|
||||
// For organization pricing, fetch all projects
|
||||
const allProjectsResponse = await sdk.forConsole.projects.list([
|
||||
Query.equal('teamId', organization.$id),
|
||||
Query.limit(1000) // get all projects
|
||||
]);
|
||||
|
||||
for (const project of allProjectsResponse.projects) {
|
||||
usageProjects[project.$id] = {
|
||||
name: project.name,
|
||||
region: project.region
|
||||
};
|
||||
}
|
||||
|
||||
if (organizationUsage?.projects?.length) {
|
||||
for (const p of organizationUsage.projects) addId(p.projectId);
|
||||
} else if (billingAggregation?.projectBreakdown?.length) {
|
||||
for (const p of billingAggregation.projectBreakdown) addId(p.$id);
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch project metadata for projects that need it
|
||||
const missingIds =
|
||||
neededIds.size > 0 ? Array.from(neededIds).filter((id) => !usageProjects[id]) : [];
|
||||
|
||||
if (missingIds.length > 0) {
|
||||
const projectsResponse = await sdk.forConsole.projects.list([
|
||||
Query.equal('$id', missingIds),
|
||||
Query.limit(missingIds.length)
|
||||
]);
|
||||
for (const project of projectsResponse.projects) {
|
||||
usageProjects[project.$id] = {
|
||||
name: project.name,
|
||||
region: project.region
|
||||
};
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore error
|
||||
}
|
||||
|
||||
const [paymentMethods, addressList, billingAddress, availableCredit] = await Promise.all([
|
||||
sdk.forConsole.billing.listPaymentMethods(),
|
||||
sdk.forConsole.billing.listAddresses(),
|
||||
@@ -140,8 +76,6 @@ export const load: PageLoad = async ({ parent, depends }) => {
|
||||
billingInvoice,
|
||||
areCreditsSupported,
|
||||
countryList,
|
||||
locale,
|
||||
organizationUsage,
|
||||
usageProjects
|
||||
locale
|
||||
};
|
||||
};
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
export let currentPlan: Plan;
|
||||
export let currentInvoice: Invoice | undefined = undefined;
|
||||
export let currentAggregation: AggregationTeam | undefined = undefined;
|
||||
export let availableCredit: number | undefined = undefined;
|
||||
|
||||
let showCancel: boolean = false;
|
||||
|
||||
|
||||
@@ -40,8 +40,8 @@ export const load: PageLoad = async ({ params, parent }) => {
|
||||
|
||||
if (currentAggregation) {
|
||||
let projectSpecificData = null;
|
||||
if (currentAggregation.projectBreakdown) {
|
||||
projectSpecificData = currentAggregation.projectBreakdown.find(
|
||||
if (currentAggregation.breakdown) {
|
||||
projectSpecificData = currentAggregation.breakdown.find(
|
||||
(p) => p.$id === project
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user