From 8a69bf00a07a5d7aa89f607d08cd5dc84d345f00 Mon Sep 17 00:00:00 2001
From: ernstmul
Date: Wed, 20 Nov 2024 15:09:44 +0100
Subject: [PATCH] Fix missing limits data for non-standard tiers
---
src/lib/stores/billing.ts | 6 ++-
.../usage/[[invoice]]/+page.svelte | 51 ++++---------------
.../usage/[[invoice]]/+page.ts | 6 ++-
3 files changed, 18 insertions(+), 45 deletions(-)
diff --git a/src/lib/stores/billing.ts b/src/lib/stores/billing.ts
index e6688ea06..c7ab3752a 100644
--- a/src/lib/stores/billing.ts
+++ b/src/lib/stores/billing.ts
@@ -130,12 +130,14 @@ export type PlanServices =
| 'usersAddon'
| 'webhooks';
-export function getServiceLimit(serviceId: PlanServices, tier: Tier = null): number {
+export function getServiceLimit(serviceId: PlanServices, tier: Tier = null, plan?: Plan): number {
if (!isCloud) return 0;
if (!serviceId) return 0;
const info = get(plansInfo);
if (!info) return 0;
- const plan = info.get(tier ?? get(organization)?.billingPlan);
+ if (!plan) {
+ plan = info.get(tier ?? get(organization)?.billingPlan);
+ }
return plan?.[serviceId];
}
diff --git a/src/routes/(console)/organization-[organization]/usage/[[invoice]]/+page.svelte b/src/routes/(console)/organization-[organization]/usage/[[invoice]]/+page.svelte
index 8dddbb419..82c211c19 100644
--- a/src/routes/(console)/organization-[organization]/usage/[[invoice]]/+page.svelte
+++ b/src/routes/(console)/organization-[organization]/usage/[[invoice]]/+page.svelte
@@ -4,7 +4,7 @@
import {
getServiceLimit,
showUsageRatesModal,
- tierToPlan,
+ type Tier,
upgradeURL
} from '$lib/stores/billing';
import { organization } from '$lib/stores/organization';
@@ -21,23 +21,10 @@
export let data;
- const tier = data?.currentInvoice?.plan ?? $organization?.billingPlan;
- const plan = tierToPlan(tier).name;
-
- // let invoice = null;
- // async function handlePeriodChange() {
- // const target = invoice
- // ? `/console/organization-${$organization.$id}/usage/${invoice}`
- // : `/console/organization-${$organization.$id}/usage`;
- // if ($page.url.pathname !== target) {
- // await goto(target);
- // }
- // }
-
- // const cycles = data.invoices.invoices.map((invoice) => ({
- // label: toLocaleDate(invoice.from),
- // value: invoice.$id
- // }));
+ const tier = data?.plan
+ ? (data.plan.$id as Tier)
+ : (data?.currentInvoice?.plan ?? $organization?.billingPlan);
+ const plan = data?.plan ?? undefined;
$: project = (data.organizationUsage as OrganizationUsage).projects;
@@ -78,29 +65,11 @@
{:else if $organization.billingPlan === BillingPlan.FREE}
- If you exceed the limits of the {plan} plan, services for your organization's projects
+ If you exceed the limits of the Free plan, services for your organization's projects
may be disrupted.
Upgrade for greater capacity.
{/if}
-
-
@@ -115,7 +84,7 @@
{#if data.organizationUsage.bandwidth}
{@const current = total(data.organizationUsage.bandwidth)}
{@const currentHumanized = humanFileSize(current)}
- {@const max = getServiceLimit('bandwidth', tier)}
+ {@const max = getServiceLimit('bandwidth', tier, plan)}
{#if data.organizationUsage.users}
{@const current = data.organizationUsage.usersTotal}
- {@const max = getServiceLimit('users', tier)}
+ {@const max = getServiceLimit('users', tier, plan)}
{#if data.organizationUsage.executionsTotal}
{@const current = data.organizationUsage.executionsTotal}
- {@const max = getServiceLimit('executions', tier)}
+ {@const max = getServiceLimit('executions', tier, plan)}
{
@@ -41,6 +41,7 @@ export const load: PageLoad = async ({ params, parent }) => {
startDate = currentInvoice.from;
endDate = currentInvoice.to;
}
+ const plan = await sdk.forConsole.billing.getPlan(org.$id);
const [invoices, usage, organizationMembers] = await Promise.all([
sdk.forConsole.billing.listInvoices(org.$id, [Query.orderDesc('from')]),
@@ -77,6 +78,7 @@ export const load: PageLoad = async ({ params, parent }) => {
projectNames,
invoices,
currentInvoice,
- organizationMembers
+ organizationMembers,
+ plan
};
};