diff --git a/src/lib/components/billing/usageRates.svelte b/src/lib/components/billing/usageRates.svelte index 653b9c154..b58df6f3a 100644 --- a/src/lib/components/billing/usageRates.svelte +++ b/src/lib/components/billing/usageRates.svelte @@ -17,31 +17,6 @@ ? new Date(new Date().getFullYear(), new Date().getMonth() + 1, 1).toString() : org?.billingNextInvoiceDate; - const planData = [ - { - id: 'members', - resource: 'Organization members', - unit: 'member' - }, - { id: 'bandwidth', resource: 'Bandwidth', unit: 'GB' }, - { id: 'storage', resource: 'Storage', unit: 'GB' }, - { - id: 'executions', - resource: 'Function executions', - unit: ' executions' - }, - { - id: 'users', - resource: 'Users', - unit: ' Users' - }, - { - id: 'realtime', - resource: 'Concurrent connections', - unit: ' connections' - } - ]; - $: isFree = org.billingPlan === BillingPlan.FREE; // equal or above means unlimited! @@ -50,6 +25,10 @@ const exceedsSafeLimit = count >= Number.MAX_SAFE_INTEGER; return exceedsSafeLimit ? 'Unlimited' : count || 0; }; + + function getPlanLimit(key: string): number | false { + return plan[key] || false; + } @@ -77,29 +56,33 @@ Limit Rate - {#each planData as usage} - {#if usage['id'] === 'members'} - - {usage.resource} - - {getCorrectSeatsCountValue(plan.addons.seats.limit)} - + {#each Object.values(plan.addons) as addon} + + {addon.invoiceDesc} + + {getCorrectSeatsCountValue(addon.limit)} + + {#if !isFree} - {formatCurrency(plan.addons?.seats?.price)}/{usage?.unit} + {formatCurrency(addon.price)}/member - - {:else} - {@const addon = plan.addons[usage.id]} + {/if} + + {/each} + {#each Object.entries(plan.usage) as [key, usage]} + {@const limit = getPlanLimit(key)} + {@const show = limit !== false} + {#if show} - {usage.resource} + {usage.name} - {abbreviateNumber(plan[usage.id])}{usage?.unit} + {abbreviateNumber(limit)}{usage.unit} {#if !isFree} - {formatCurrency(addon?.price)}/{['MB', 'GB', 'TB'].includes(addon?.unit) - ? addon?.value - : abbreviateNumber(addon?.value, 0)}{usage?.unit} + {formatCurrency(usage.price)}/{abbreviateNumber( + usage.value + )}{usage.unit} {/if} diff --git a/src/lib/sdk/billing.ts b/src/lib/sdk/billing.ts index aab3ffe59..9a4cdfe4f 100644 --- a/src/lib/sdk/billing.ts +++ b/src/lib/sdk/billing.ts @@ -278,6 +278,7 @@ export type AddressesList = { }; export type AdditionalResource = { + name: string; currency: string; invoiceDesc: string; price: number;