From e1ccdb7352fc1e3327a0c84f4cf56d1928edd5fa Mon Sep 17 00:00:00 2001 From: Arman Date: Mon, 22 Apr 2024 18:05:42 +0200 Subject: [PATCH] feat: add missing usage --- .../billing/planSummary.svelte | 107 +++++++++++------- 1 file changed, 64 insertions(+), 43 deletions(-) diff --git a/src/routes/console/organization-[organization]/billing/planSummary.svelte b/src/routes/console/organization-[organization]/billing/planSummary.svelte index 6e042b417..85573478b 100644 --- a/src/routes/console/organization-[organization]/billing/planSummary.svelte +++ b/src/routes/console/organization-[organization]/billing/planSummary.svelte @@ -28,6 +28,7 @@ let currentInvoice: Invoice; let showAddons = false; + let extraMembers = 0; const today = new Date(); onMount(async () => { const invoices = await sdk.forConsole.billing.listInvoices($organization.$id, [ @@ -35,7 +36,8 @@ Query.orderDesc('$createdAt') ]); currentInvoice = invoices.invoices[0]; - console.log(currentInvoice); + const members = await sdk.forConsole.teams.listMemberships($organization.$id, []); + extraMembers = members.total > 1 ? members.total - 1 : 0; }); $: currentPlan = $plansInfo?.get($organization?.billingPlan); @@ -74,7 +76,10 @@ on:click={() => (showAddons = !showAddons)} on:keyup={clickOnEnter}> - Add-ons number + Add-ons {extraMembers + ? currentInvoice?.usage?.length + 1 + : currentInvoice?.usage?.length} @@ -83,56 +88,72 @@ {#if extraUsage && showAddons && $organization?.billingPlan !== BillingPlan.STARTER && !isTrial} - {@const extraMembers = currentInvoice.usage.find((u) => u.name === 'members')}
  • {#if extraMembers}
  • - {extraMembers} + +
    + Additional members + + {extraMembers} + +
    +
    + + + {formatCurrency(extraMembers * 15)} +
  • {/if} -
  • - asde -
  • + {#if currentInvoice?.usage} + {#each currentInvoice.usage as excess} +
  • + {#if ['storage', 'bandwidth'].includes(excess.name)} + {@const excessValue = humanFileSize( + excess.value + )} + +
    +

    {excess.name}

    + + {excessValue.value ?? + 0}{excessValue.unit} + +
    +
    + + {formatCurrency(excess.amount)} + + {/if} + {#if ['users', 'executions'].includes(excess.name)} + +
    +

    + {excess.name} +

    + {abbreviateNumber( + excess.value + )} +
    +
    + + {formatCurrency(excess.amount)} + + {/if} +
  • + {/each} + {/if} - {#if currentInvoice?.usage} - {#each currentInvoice.usage as excess} - {#if ['storage', 'bandwidth'].includes(excess.name)} - {@const excessValue = humanFileSize(excess.value)} -
  • -

    - - {excessValue.value ?? 0}{excessValue.unit} - - {excess.name} -

    -

    - {formatCurrency(excess.amount)} -

    -
  • - {/if} - {#if ['users', 'executions'].includes(excess.name)} -
  • -

    - {abbreviateNumber(excess.value)} - {excess.name} -

    -

    - {formatCurrency(excess.amount)} -

    -
  • - {/if} - {/each} - {/if}