From a6cce4efd5232267f37509ebcc995bdecba7b489 Mon Sep 17 00:00:00 2001 From: Arman Date: Mon, 11 Dec 2023 10:51:47 +0100 Subject: [PATCH] reafacton: container header --- src/lib/layout/containerHeader.svelte | 113 ++++++++++++++++---------- src/lib/stores/billing.ts | 17 +++- 2 files changed, 84 insertions(+), 46 deletions(-) diff --git a/src/lib/layout/containerHeader.svelte b/src/lib/layout/containerHeader.svelte index 542302595..2ee62cb3a 100644 --- a/src/lib/layout/containerHeader.svelte +++ b/src/lib/layout/containerHeader.svelte @@ -4,7 +4,9 @@ getServiceLimit, type PlanServices, showUsageRatesModal, - checkForUsageFees + checkForUsageFees, + readOnly, + checkForProjectLimitation } from '$lib/stores/billing'; import { Alert, DropList, Heading } from '$lib/components'; import { Pill } from '$lib/elements'; @@ -14,6 +16,7 @@ import { wizard } from '$lib/stores/wizard'; import ChangeOrganizationTierCloud from '$routes/console/changeOrganizationTierCloud.svelte'; import { ContainerButton } from '.'; + import { Button } from '$lib/elements/forms'; export let isFlex = true; export let title: string; @@ -31,6 +34,15 @@ let showDropdown = false; + const { bandwidth, documents, storage, users, executions } = $organization?.billingLimits; + const limitedServices = [ + { name: 'bandwidth', value: bandwidth }, + { name: 'documents', value: documents }, + { name: 'storage', value: storage }, + { name: 'users', value: users }, + { name: 'executions', value: executions } + ]; + const limit = getServiceLimit(serviceId) || Infinity; const upgradeMethod = () => { showDropdown = false; @@ -39,8 +51,13 @@ const dispatch = createEventDispatcher(); $: tier = tierToPlan($organization?.billingPlan)?.name; + $: hasProjectLimitation = + checkForProjectLimitation(serviceId) && $organization?.billingPlan === 'tier-0'; + $: hasUsageFees = hasProjectLimitation + ? checkForUsageFees($organization?.billingPlan, serviceId) + : false; $: isLimited = limit !== 0 && limit < Infinity; - $: hasUsageFees = checkForUsageFees($organization?.billingPlan, serviceId); + $: overflowingServices = limitedServices.filter((service) => service.value >= 0); $: isButtonDisabled = buttonDisabled || (isLimited && total >= limit && !hasUsageFees); onMount(() => { @@ -48,32 +65,35 @@ }); -{#if isCloud && showAlert && total && limit !== 0 && total >= limit} + +{#if isCloud && showAlert && !hasProjectLimitation} - {#if hasUsageFees} - - - You've reached the {title.toLocaleLowerCase()} limit for the {tier} plan. - . - - - {:else} - - - You've reached the {title.toLowerCase()} limit for the {tier} plan. + {#if $readOnly && hasUsageFees} + {#if $organization?.billingPlan !== 'tier-0'} + + + You've reached the {overflowingServices.forEach((s) => { + s.name.toLocaleLowerCase() + ', '; + })} limit for the {tier} plan. + . + + + {:else} + + + You've reached the {overflowingServices.forEach((s) => { + s.name.toLocaleLowerCase() + ', '; + })} limit for the {tier} plan. - {#if $organization?.billingPlan === 'tier-0'} - - for additional {title.toLocaleLowerCase()}. - {/if} - - + {#if $organization?.billingPlan === 'tier-0'} + + for additional {title.toLocaleLowerCase()}. + {/if} + + + {/if} {/if} {/if} @@ -83,33 +103,36 @@ {title} {#if isCloud && isLimited} - (showDropdown = !showDropdown)}> - {title} limited - + {#if hasProjectLimitation} + (showDropdown = !showDropdown)}> + {total}/{limit} + {title} used + + {:else} + (showDropdown = !showDropdown)}> + {title} limited + + {/if} - {#if hasUsageFees} -

- You are limited to {limit} - {title.toLocaleLowerCase()} per project on the {tier} plan. - . -

- {:else} + {#if hasProjectLimitation}

Your are limited to {limit} {title.toLocaleLowerCase()} per project on the {tier} plan. - {#if $organization?.billingPlan === 'tier-0'} + {#if $organization?.billingPlan === 'tier-0'} for addtional {title.toLocaleLowerCase()}. {/if}

+ {:else if hasUsageFees} +

+ You are limited to {limit} + {title.toLocaleLowerCase()} per project on the {tier} plan. + . +

{/if}
diff --git a/src/lib/stores/billing.ts b/src/lib/stores/billing.ts index 3337dca45..1207aede3 100644 --- a/src/lib/stores/billing.ts +++ b/src/lib/stores/billing.ts @@ -126,11 +126,26 @@ export function checkForUsageFees(plan: Tier, id: PlanServices) { } else return false; } +export function checkForProjectLimitation(id: PlanServices) { + switch (id) { + case 'databases': + case 'functions': + case 'buckets': + case 'members': + case 'platforms': + case 'webhooks': + case 'teams': + return true; + + default: + return false; + } +} + export function isServiceLimited(serviceId: PlanServices, plan: Tier, total: number) { if (!total) return false; const limit = getServiceLimit(serviceId) || Infinity; const isLimited = limit !== 0 && limit < Infinity; const hasUsageFees = checkForUsageFees(plan, serviceId); - console.log(serviceId, plan, total, limit, isLimited, hasUsageFees); return isLimited && total >= limit && !hasUsageFees; }