From fd2eceba7d519aeaba7f8d328b1e34810f67abb3 Mon Sep 17 00:00:00 2001 From: Arman Date: Mon, 11 Dec 2023 16:24:46 +0100 Subject: [PATCH] fix: excess modal --- .../excesLimitModal.svelte | 21 ++++++++---- .../planExcess.svelte | 33 ++++++++++++------- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/routes/console/organization-[organization]/excesLimitModal.svelte b/src/routes/console/organization-[organization]/excesLimitModal.svelte index 537ffb87e..000c17b4f 100644 --- a/src/routes/console/organization-[organization]/excesLimitModal.svelte +++ b/src/routes/console/organization-[organization]/excesLimitModal.svelte @@ -12,6 +12,7 @@ import { wizard } from '$lib/stores/wizard'; import ChangeOrganizationTierCloud from '../changeOrganizationTierCloud.svelte'; import { goto } from '$app/navigation'; + import { last } from '$lib/helpers/array'; export let show = false; const plan = $plansInfo.plans.find((plan) => plan.$id === $organization.billingPlan); @@ -30,18 +31,24 @@ }); function calculateExcess() { - const totBandwidth = usage?.bandwidth?.length > 0 ? usage.bandwidth[0].value : 0; - const totUsers = usage?.users?.length > 0 ? usage.users[0].value : 0; + const totBandwidth = usage?.bandwidth?.length > 0 ? last(usage.bandwidth).value : 0; + const totUsers = usage?.users?.length > 0 ? last(usage.users).value : 0; + excess = { bandwidth: totBandwidth > plan.bandwidth ? totBandwidth - plan.bandwidth : 0, storage: - usage?.storage[0] > sizeToBytes(plan.storage, 'GB') - ? usage.storage[0] - plan.storage + usage?.storage > sizeToBytes(plan.storage, 'GB') + ? usage.storage - sizeToBytes(plan.storage, 'GB') : 0, - users: totUsers > plan.users ? totUsers - plan.users : 0, + users: totUsers > (plan.users || Infinity) ? totUsers - plan.users : 0, executions: - usage?.executions[0] > plan.executions ? usage.executions[0] - plan.executions : 0, - members: members?.total > plan.members ? members.total - (plan.members || Infinity) : 0 + usage?.executions > sizeToBytes(plan.executions, 'GB') + ? usage.executions - sizeToBytes(plan.executions, 'GB') + : 0, + members: + members?.total > (plan.members || Infinity) + ? members.total - (plan.members || Infinity) + : 0 }; } diff --git a/src/routes/console/wizard/cloudOrganizationChangeTier/planExcess.svelte b/src/routes/console/wizard/cloudOrganizationChangeTier/planExcess.svelte index c582d03f4..9f84a9db2 100644 --- a/src/routes/console/wizard/cloudOrganizationChangeTier/planExcess.svelte +++ b/src/routes/console/wizard/cloudOrganizationChangeTier/planExcess.svelte @@ -15,6 +15,7 @@ import { Button } from '$lib/elements/forms'; import { humanFileSize } from '$lib/helpers/sizeConvertion'; import { abbreviateNumber } from '$lib/helpers/numbers'; + import { formatNum } from '$lib/helpers/string'; export let excess: { bandwidth?: number; @@ -27,6 +28,8 @@ const plan = $plansInfo.plans.find((p) => p.$id === currentTier); const collaboratorPrice = plan?.addons.member?.price ?? 0; + + $: console.log(excess); @@ -48,24 +51,25 @@ {/if} {/if} {#if excess?.bandwidth > 0 || excess?.executions > 0 || excess?.storage > 0 || excess?.users} - The Starter plan has a limit of one organization member. By proceeding, all but the creator - of the organization admin will be removed. Until you reduce your usage, you will be unable - to add to the resources listed below in all projects within your organization. The current - billing cycle will end on {toLocaleDate($organization.billingCurrentInvoiceDate)}. Any - executions, bandwidth, or messaging usage will be reset at that time. + Until you reduce your usage, you will be unable to add to the resources listed below in all + projects within your organization. The current billing cycle will end on {toLocaleDate( + $organization.billingCurrentInvoiceDate + )}. Any executions, bandwidth, or messaging usage will be reset at that time. {/if} {#if currentTier === 'tier-0'} + href="https://appwrite.io/docs/advanced/platform/starter#reaching-resource-limits"> + Learn more + {:else if currentTier === 'tier-1'} + href="https://appwrite.io/docs/advanced/platform/pro#reaching-resource-limits"> + Learn more + {/if} @@ -110,7 +114,12 @@

- {excess?.executions} executions + + {formatNum(excess?.executions)} executions +

@@ -124,7 +133,9 @@

- {excess?.users} users + + {formatNum(excess?.users)} users +