mirror of
https://github.com/appwrite/console.git
synced 2026-04-07 19:17:46 +00:00
Fix missing limits data for non-standard tiers
This commit is contained in:
@@ -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];
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
</script>
|
||||
@@ -78,29 +65,11 @@
|
||||
</p>
|
||||
{:else if $organization.billingPlan === BillingPlan.FREE}
|
||||
<p class="text">
|
||||
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.
|
||||
<a href={$upgradeURL} class="link">Upgrade for greater capacity</a>.
|
||||
</p>
|
||||
{/if}
|
||||
|
||||
<!--<div class="u-flex u-gap-8 u-cross-center">
|
||||
<p class="text">Usage period:</p>
|
||||
<InputSelect
|
||||
wrapperTag="div"
|
||||
id="period"
|
||||
label="Usage period"
|
||||
showLabel={false}
|
||||
bind:value={invoice}
|
||||
on:change={handlePeriodChange}
|
||||
options={[
|
||||
{
|
||||
label: 'Current billing cycle',
|
||||
value: null
|
||||
},
|
||||
...cycles
|
||||
]} />
|
||||
</div>-->
|
||||
</div>
|
||||
|
||||
<CardGrid>
|
||||
@@ -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)}
|
||||
<ProgressBarBig
|
||||
currentUnit={currentHumanized.unit}
|
||||
currentValue={currentHumanized.value}
|
||||
@@ -178,7 +147,7 @@
|
||||
<svelte:fragment slot="aside">
|
||||
{#if data.organizationUsage.users}
|
||||
{@const current = data.organizationUsage.usersTotal}
|
||||
{@const max = getServiceLimit('users', tier)}
|
||||
{@const max = getServiceLimit('users', tier, plan)}
|
||||
<ProgressBarBig
|
||||
currentUnit="Users"
|
||||
currentValue={formatNum(current)}
|
||||
@@ -233,7 +202,7 @@
|
||||
<svelte:fragment slot="aside">
|
||||
{#if data.organizationUsage.executionsTotal}
|
||||
{@const current = data.organizationUsage.executionsTotal}
|
||||
{@const max = getServiceLimit('executions', tier)}
|
||||
{@const max = getServiceLimit('executions', tier, plan)}
|
||||
<ProgressBarBig
|
||||
currentUnit="Executions"
|
||||
currentValue={formatNum(current)}
|
||||
@@ -290,7 +259,7 @@
|
||||
{#if data.organizationUsage.storageTotal}
|
||||
{@const current = data.organizationUsage.storageTotal}
|
||||
{@const currentHumanized = humanFileSize(current)}
|
||||
{@const max = getServiceLimit('storage', tier)}
|
||||
{@const max = getServiceLimit('storage', tier, plan)}
|
||||
{@const progressBarStorageDate = [
|
||||
{
|
||||
size: bytesToSize(data.organizationUsage.filesStorageTotal, 'GB'),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { Query, type Models } from '@appwrite.io/console';
|
||||
import type { PageLoad } from './$types';
|
||||
import type { Organization } from '$lib/stores/organization';
|
||||
import { type Organization } from '$lib/stores/organization';
|
||||
import type { Invoice } from '$lib/sdk/billing';
|
||||
|
||||
export const load: PageLoad = async ({ params, parent }) => {
|
||||
@@ -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
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user