mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
gate new pricing UI by plan flag; optimize billing loads
Add billingPlan prop to createProject.svelte; derive isProPlan from prop Introduce useNewPricingModal derived from currentPlan.usagePerProject Wire pricing modal triggers to use new modal only when usagePerProject is true Add planSummaryOld.svelte and conditionally render based on useNewPricingModal Optimize billing/+page.ts to fetch only needed projects by from usage/aggregation Remove no-op reactive block in planSummary.svelte; resolve unused prop warning
This commit is contained in:
1 parent
475e24a723
commit
aa56721563
10 files changed
+313
-36
No files matched your search
@@ -11,6 +11,7 @@
|
||||
getServiceLimit,
|
||||
readOnly,
|
||||
showUsageRatesModal,
|
||||
useNewPricingModal,
|
||||
tierToPlan,
|
||||
upgradeURL,
|
||||
type PlanServices
|
||||
@@ -101,7 +102,7 @@
|
||||
<Alert.Inline status="info">
|
||||
<span class="text">
|
||||
You've reached the {services} limit for the {tier} plan.
|
||||
<Link on:mousedown={() => ($showUsageRatesModal = true)}
|
||||
<Link on:mousedown={() => ($showUsageRatesModal = $useNewPricingModal)}
|
||||
>Excess usage fees will apply</Link
|
||||
>.
|
||||
</span>
|
||||
@@ -159,7 +160,9 @@
|
||||
<p class="text">
|
||||
You are limited to {limit}
|
||||
{title.toLocaleLowerCase()} per organization on the {tier} plan.
|
||||
<Link on:mousedown={() => ($showUsageRatesModal = true)}
|
||||
<Link
|
||||
on:mousedown={() =>
|
||||
($showUsageRatesModal = $useNewPricingModal)}
|
||||
>Excess usage fees will apply</Link
|
||||
>.
|
||||
</p>
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
regions = [],
|
||||
region = $bindable(''),
|
||||
showTitle = true,
|
||||
billingPlan = undefined,
|
||||
projects = undefined,
|
||||
submit
|
||||
}: {
|
||||
@@ -27,12 +28,13 @@
|
||||
regions: Array<Models.ConsoleRegion>;
|
||||
region: string;
|
||||
showTitle: boolean;
|
||||
billingPlan?: BillingPlan;
|
||||
projects?: number;
|
||||
submit?: Snippet;
|
||||
} = $props();
|
||||
|
||||
let showCustomId = $state(false);
|
||||
let isProPlan = $derived($organization?.billingPlan === BillingPlan.PRO);
|
||||
let isProPlan = $derived((billingPlan ?? $organization?.billingPlan) === BillingPlan.PRO);
|
||||
let projectsLimited = $derived(
|
||||
isProPlan
|
||||
? projects && projects >= 2
|
||||
|
||||
@@ -235,6 +235,7 @@ export const tierEnterprise: TierData = {
|
||||
};
|
||||
|
||||
export const showUsageRatesModal = writable<boolean>(false);
|
||||
export const useNewPricingModal = derived(currentPlan, ($plan) => $plan?.usagePerProject === true);
|
||||
|
||||
export function checkForUsageFees(plan: Tier, id: PlanServices) {
|
||||
if (plan === BillingPlan.PRO || plan === BillingPlan.SCALE) {
|
||||
|
||||
@@ -2,12 +2,13 @@
|
||||
import { Container } from '$lib/layout';
|
||||
import BudgetCap from './budgetCap.svelte';
|
||||
import PlanSummary from './planSummary.svelte';
|
||||
import PlanSummaryOld from './planSummaryOld.svelte';
|
||||
import BillingAddress from './billingAddress.svelte';
|
||||
import PaymentMethods from './paymentMethods.svelte';
|
||||
import AvailableCredit from './availableCredit.svelte';
|
||||
import PaymentHistory from './paymentHistory.svelte';
|
||||
import TaxId from './taxId.svelte';
|
||||
import { failedInvoice, tierToPlan, upgradeURL } from '$lib/stores/billing';
|
||||
import { failedInvoice, tierToPlan, upgradeURL, useNewPricingModal } from '$lib/stores/billing';
|
||||
import type { PaymentMethodData } from '$lib/sdk/billing';
|
||||
import { onMount } from 'svelte';
|
||||
import { page } from '$app/state';
|
||||
@@ -127,13 +128,21 @@
|
||||
until your billing period ends on {toLocaleDate(organization.billingNextInvoiceDate)}.
|
||||
</Alert.Inline>
|
||||
{/if}
|
||||
<PlanSummary
|
||||
availableCredit={data?.availableCredit}
|
||||
currentPlan={data?.currentPlan}
|
||||
currentAggregation={data?.billingAggregation}
|
||||
currentInvoice={data?.billingInvoice}
|
||||
organizationUsage={data?.organizationUsage}
|
||||
usageProjects={data?.usageProjects} />
|
||||
{#if $useNewPricingModal}
|
||||
<PlanSummary
|
||||
availableCredit={data?.availableCredit}
|
||||
currentPlan={data?.currentPlan}
|
||||
currentAggregation={data?.billingAggregation}
|
||||
currentInvoice={data?.billingInvoice}
|
||||
organizationUsage={data?.organizationUsage}
|
||||
usageProjects={data?.usageProjects} />
|
||||
{:else}
|
||||
<PlanSummaryOld
|
||||
availableCredit={data?.availableCredit}
|
||||
currentPlan={data?.currentPlan}
|
||||
currentAggregation={data?.billingAggregation}
|
||||
currentInvoice={data?.billingInvoice} />
|
||||
{/if}
|
||||
<PaymentHistory />
|
||||
<PaymentMethods organization={data?.organization} methods={data?.paymentMethods} />
|
||||
<BillingAddress
|
||||
|
||||
@@ -70,15 +70,27 @@ export const load: PageLoad = async ({ parent, depends }) => {
|
||||
}
|
||||
|
||||
try {
|
||||
const projectsResponse = await sdk.forConsole.projects.list([
|
||||
Query.equal('teamId', organization.$id),
|
||||
Query.limit(1000)
|
||||
]);
|
||||
for (const project of projectsResponse.projects) {
|
||||
usageProjects[project.$id] = {
|
||||
name: project.name,
|
||||
region: project.region
|
||||
};
|
||||
const neededIds = new Set<string>();
|
||||
const addId = (id?: string) => id && neededIds.add(id);
|
||||
|
||||
if (organizationUsage?.projects?.length) {
|
||||
for (const p of organizationUsage.projects) addId(p.projectId);
|
||||
} else if (billingAggregation?.projectBreakdown?.length) {
|
||||
for (const p of billingAggregation.projectBreakdown) addId(p.$id);
|
||||
}
|
||||
|
||||
if (neededIds.size > 0) {
|
||||
const ids = Array.from(neededIds);
|
||||
const projectsResponse = await sdk.forConsole.projects.list([
|
||||
Query.equal('$id', ids),
|
||||
Query.limit(ids.length)
|
||||
]);
|
||||
for (const project of projectsResponse.projects) {
|
||||
usageProjects[project.$id] = {
|
||||
name: project.name,
|
||||
region: project.region
|
||||
};
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore error
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import { CardGrid } from '$lib/components';
|
||||
import { BillingPlan, Dependencies } from '$lib/constants';
|
||||
import { Button, Form, InputNumber, InputSwitch } from '$lib/elements/forms';
|
||||
import { showUsageRatesModal, upgradeURL } from '$lib/stores/billing';
|
||||
import { showUsageRatesModal, upgradeURL, useNewPricingModal } from '$lib/stores/billing';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
import { type Organization } from '$lib/stores/organization';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
@@ -72,7 +72,7 @@
|
||||
Budget cap limits do not include the base amount of your plan. <button
|
||||
class="link"
|
||||
type="button"
|
||||
on:click={() => ($showUsageRatesModal = true)}
|
||||
on:click={() => ($showUsageRatesModal = $useNewPricingModal)}
|
||||
>Learn more about usage rates.
|
||||
</button>
|
||||
</svelte:fragment>
|
||||
|
||||
@@ -19,17 +19,9 @@
|
||||
export let currentPlan: Plan;
|
||||
export let currentInvoice: Invoice | undefined = undefined;
|
||||
export let currentAggregation: AggregationTeam | undefined = undefined;
|
||||
export let availableCredit: number | undefined = undefined;
|
||||
export let organizationUsage: any = undefined;
|
||||
export let usageProjects: Record<string, any> = {};
|
||||
|
||||
$: {
|
||||
currentAggregation;
|
||||
availableCredit;
|
||||
organizationUsage;
|
||||
usageProjects;
|
||||
}
|
||||
|
||||
let showCancel: boolean = false;
|
||||
|
||||
// define columns for the expandable table
|
||||
|
||||
@@ -0,0 +1,250 @@
|
||||
<script lang="ts">
|
||||
import { base } from '$app/paths';
|
||||
import { CardGrid } from '$lib/components';
|
||||
import { Button } from '$lib/elements/forms';
|
||||
import { toLocaleDate } from '$lib/helpers/date';
|
||||
import { plansInfo, upgradeURL } from '$lib/stores/billing';
|
||||
import { organization } from '$lib/stores/organization';
|
||||
import type { Aggregation, Invoice, Plan } from '$lib/sdk/billing';
|
||||
import { abbreviateNumber, formatCurrency, formatNumberWithCommas } from '$lib/helpers/numbers';
|
||||
import { BillingPlan } from '$lib/constants';
|
||||
import { Click, trackEvent } from '$lib/actions/analytics';
|
||||
import {
|
||||
Accordion,
|
||||
Card,
|
||||
Divider,
|
||||
Icon,
|
||||
Layout,
|
||||
Tooltip,
|
||||
Typography
|
||||
} from '@appwrite.io/pink-svelte';
|
||||
import { IconInfo, IconTag } from '@appwrite.io/pink-icons-svelte';
|
||||
import CancelDowngradeModel from './cancelDowngradeModal.svelte';
|
||||
|
||||
export let currentPlan: Plan;
|
||||
export let currentInvoice: Invoice | undefined = undefined;
|
||||
export let availableCredit: number | undefined = undefined;
|
||||
export let currentAggregation: Aggregation | undefined = undefined;
|
||||
|
||||
let showCancel: boolean = false;
|
||||
|
||||
const today = new Date();
|
||||
const isTrial =
|
||||
new Date($organization?.billingStartDate).getTime() - today.getTime() > 0 &&
|
||||
$plansInfo.get($organization.billingPlan)?.trialDays;
|
||||
const extraUsage = currentInvoice ? currentInvoice.amount - currentPlan?.price : 0;
|
||||
</script>
|
||||
|
||||
{#if $organization}
|
||||
<CardGrid>
|
||||
<svelte:fragment slot="title">Payment estimates</svelte:fragment>
|
||||
A breakdown of your estimated upcoming payment for the current billing period. Totals displayed
|
||||
exclude accumulated credits and applicable taxes.
|
||||
<svelte:fragment slot="aside">
|
||||
<p class="text u-bold">
|
||||
Due at: {toLocaleDate($organization?.billingNextInvoiceDate)}
|
||||
</p>
|
||||
<Card.Base variant="secondary" padding="s">
|
||||
<Layout.Stack>
|
||||
<Layout.Stack direction="row" justifyContent="space-between">
|
||||
<Typography.Text color="--fgcolor-neutral-primary">
|
||||
{currentPlan.name} plan
|
||||
</Typography.Text>
|
||||
<Typography.Text>
|
||||
{isTrial || $organization?.billingPlan === BillingPlan.GITHUB_EDUCATION
|
||||
? formatCurrency(0)
|
||||
: currentPlan
|
||||
? formatCurrency(currentPlan?.price)
|
||||
: ''}
|
||||
</Typography.Text>
|
||||
</Layout.Stack>
|
||||
|
||||
{#if currentPlan.budgeting && extraUsage > 0}
|
||||
<Accordion
|
||||
hideDivider
|
||||
title="Add-ons"
|
||||
badge={(currentAggregation.additionalMembers > 0
|
||||
? currentInvoice.usage.length + 1
|
||||
: currentInvoice.usage.length
|
||||
).toString()}>
|
||||
<svelte:fragment slot="end">
|
||||
{formatCurrency(extraUsage >= 0 ? extraUsage : 0)}
|
||||
</svelte:fragment>
|
||||
<Layout.Stack gap="xs">
|
||||
{#if currentAggregation.additionalMembers}
|
||||
<Layout.Stack gap="xxxs">
|
||||
<Layout.Stack
|
||||
direction="row"
|
||||
justifyContent="space-between">
|
||||
<Typography.Text color="--fgcolor-neutral-primary"
|
||||
>Additional members</Typography.Text>
|
||||
<Typography.Text>
|
||||
{formatCurrency(
|
||||
currentAggregation.additionalMemberAmount
|
||||
)}
|
||||
</Typography.Text>
|
||||
</Layout.Stack>
|
||||
<Layout.Stack direction="row">
|
||||
<Typography.Text
|
||||
>{currentAggregation.additionalMembers}</Typography.Text>
|
||||
</Layout.Stack>
|
||||
</Layout.Stack>
|
||||
{/if}
|
||||
{#if currentInvoice?.usage}
|
||||
{#each currentInvoice.usage as excess, i}
|
||||
{#if i > 0 || currentAggregation.additionalMembers}
|
||||
<Divider />
|
||||
{/if}
|
||||
|
||||
<Layout.Stack gap="xxxs">
|
||||
<Layout.Stack
|
||||
direction="row"
|
||||
justifyContent="space-between">
|
||||
<Typography.Text color="--fgcolor-neutral-primary">
|
||||
{excess.name}
|
||||
</Typography.Text>
|
||||
<Typography.Text>
|
||||
{formatCurrency(excess.amount)}
|
||||
</Typography.Text>
|
||||
</Layout.Stack>
|
||||
<Layout.Stack direction="row">
|
||||
<Tooltip
|
||||
placement="bottom"
|
||||
disabled={excess.value <= 1000}>
|
||||
<svelte:fragment slot="tooltip">
|
||||
{formatNumberWithCommas(excess.value)}
|
||||
</svelte:fragment>
|
||||
<span>{abbreviateNumber(excess.value)}</span>
|
||||
</Tooltip>
|
||||
</Layout.Stack>
|
||||
</Layout.Stack>
|
||||
{/each}
|
||||
{/if}
|
||||
</Layout.Stack>
|
||||
</Accordion>
|
||||
{/if}
|
||||
|
||||
{#if currentPlan.supportsCredits && availableCredit > 0}
|
||||
<Layout.Stack direction="row" justifyContent="space-between">
|
||||
<Layout.Stack direction="row" alignItems="center" gap="xxs">
|
||||
<Icon size="s" icon={IconTag} color="--fgcolor-success" />
|
||||
<Typography.Text color="--fgcolor-neutral-primary"
|
||||
>Credits to be applied</Typography.Text>
|
||||
</Layout.Stack>
|
||||
<Typography.Text color="--fgcolor-success">
|
||||
-{formatCurrency(
|
||||
Math.min(availableCredit, currentInvoice?.amount ?? 0)
|
||||
)}
|
||||
</Typography.Text>
|
||||
</Layout.Stack>
|
||||
{/if}
|
||||
|
||||
{#if $organization?.billingPlan !== BillingPlan.FREE && $organization?.billingPlan !== BillingPlan.GITHUB_EDUCATION}
|
||||
<Divider />
|
||||
<Layout.Stack direction="row" justifyContent="space-between">
|
||||
<Typography.Text color="--fgcolor-neutral-primary" variant="m-500">
|
||||
<Layout.Stack direction="row" alignItems="center" gap="s">
|
||||
Current total (USD)
|
||||
<Tooltip>
|
||||
<Icon icon={IconInfo} />
|
||||
<svelte:fragment slot="tooltip">
|
||||
Estimates are updated daily and may differ from your
|
||||
final invoice.
|
||||
</svelte:fragment>
|
||||
</Tooltip>
|
||||
</Layout.Stack>
|
||||
</Typography.Text>
|
||||
<Typography.Text color="--fgcolor-neutral-primary" variant="m-500">
|
||||
{formatCurrency(
|
||||
Math.max(
|
||||
(currentInvoice?.amount ?? 0) -
|
||||
Math.min(availableCredit, currentInvoice?.amount ?? 0),
|
||||
0
|
||||
)
|
||||
)}
|
||||
</Typography.Text>
|
||||
</Layout.Stack>
|
||||
{/if}
|
||||
</Layout.Stack>
|
||||
</Card.Base>
|
||||
</svelte:fragment>
|
||||
<svelte:fragment slot="actions">
|
||||
{#if $organization?.billingPlan === BillingPlan.FREE || $organization?.billingPlan === BillingPlan.GITHUB_EDUCATION}
|
||||
<div
|
||||
class="u-flex u-flex-vertical-mobile u-cross-center u-gap-16 u-flex-wrap u-width-full-line u-main-end">
|
||||
<Button text href={`${base}/organization-${$organization?.$id}/usage`}>
|
||||
View estimated usage
|
||||
</Button>
|
||||
<Button
|
||||
disabled={$organization?.markedForDeletion}
|
||||
href={$upgradeURL}
|
||||
on:click={() =>
|
||||
trackEvent(Click.OrganizationClickUpgrade, {
|
||||
from: 'button',
|
||||
source: 'billing_tab'
|
||||
})}>
|
||||
Upgrade
|
||||
</Button>
|
||||
</div>
|
||||
{:else}
|
||||
<div
|
||||
class="u-flex u-flex-vertical-mobile u-cross-center u-gap-16 u-flex-wrap u-width-full-line u-main-end">
|
||||
{#if $organization?.billingPlanDowngrade !== null}
|
||||
<Button text on:click={() => (showCancel = true)}>Cancel change</Button>
|
||||
{:else}
|
||||
<Button
|
||||
text
|
||||
disabled={$organization?.markedForDeletion}
|
||||
href={$upgradeURL}
|
||||
on:click={() =>
|
||||
trackEvent('click_organization_plan_update', {
|
||||
from: 'button',
|
||||
source: 'billing_tab'
|
||||
})}>
|
||||
Change plan
|
||||
</Button>
|
||||
{/if}
|
||||
<Button secondary href={`${base}/organization-${$organization?.$id}/usage`}>
|
||||
View estimated usage
|
||||
</Button>
|
||||
</div>
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
</CardGrid>
|
||||
{/if}
|
||||
|
||||
<CancelDowngradeModel bind:showCancel />
|
||||
|
||||
<style>
|
||||
:root {
|
||||
--billing-card-border-color: hsl(var(--color-neutral-10));
|
||||
}
|
||||
|
||||
:global(.card-only-on-desktop) {
|
||||
background: hsl(var(--color-neutral-5));
|
||||
border-radius: var(--corner-radius-medium, 8px);
|
||||
border: 1px solid var(--billing-card-border-color);
|
||||
}
|
||||
|
||||
:global(.theme-dark .card-only-on-desktop) {
|
||||
background: #2c2c2f;
|
||||
--billing-card-border-color: #424248;
|
||||
}
|
||||
|
||||
:global(.card-only-on-desktop .collapsible-item:only-of-type) {
|
||||
margin-block-start: 0.5rem;
|
||||
border-block-start: solid 0.0625rem hsl(var(--p-toggle-border-color));
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
:global(.card-only-on-desktop) {
|
||||
padding: 0.5rem;
|
||||
box-shadow: unset;
|
||||
border-radius: unset;
|
||||
|
||||
/* yes, these `!important`s are needed */
|
||||
border: unset !important;
|
||||
background: unset !important;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -8,7 +8,8 @@
|
||||
getServiceLimit,
|
||||
showUsageRatesModal,
|
||||
type Tier,
|
||||
upgradeURL
|
||||
upgradeURL,
|
||||
useNewPricingModal
|
||||
} from '$lib/stores/billing';
|
||||
import { organization } from '$lib/stores/organization';
|
||||
import ProjectBreakdown from './ProjectBreakdown.svelte';
|
||||
@@ -76,13 +77,15 @@
|
||||
{#if $organization.billingPlan === BillingPlan.SCALE}
|
||||
<p class="text">
|
||||
On the Scale plan, you'll be charged only for any usage that exceeds the thresholds per
|
||||
resource listed below. <Link.Button on:click={() => ($showUsageRatesModal = true)}
|
||||
resource listed below. <Link.Button
|
||||
on:click={() => ($showUsageRatesModal = $useNewPricingModal)}
|
||||
>Learn more</Link.Button>
|
||||
</p>
|
||||
{:else if $organization.billingPlan === BillingPlan.PRO}
|
||||
<p class="text">
|
||||
On the Pro plan, you'll be charged only for any usage that exceeds the thresholds per
|
||||
resource listed below. <Link.Button on:click={() => ($showUsageRatesModal = true)}
|
||||
resource listed below. <Link.Button
|
||||
on:click={() => ($showUsageRatesModal = $useNewPricingModal)}
|
||||
>Learn more</Link.Button>
|
||||
</p>
|
||||
{:else if $organization.billingPlan === BillingPlan.FREE}
|
||||
|
||||
+8
-3
@@ -1,7 +1,12 @@
|
||||
<script lang="ts">
|
||||
import { Container } from '$lib/layout';
|
||||
import { CardGrid, Card, ProgressBarBig } from '$lib/components';
|
||||
import { showUsageRatesModal, tierToPlan, upgradeURL } from '$lib/stores/billing';
|
||||
import {
|
||||
showUsageRatesModal,
|
||||
tierToPlan,
|
||||
upgradeURL,
|
||||
useNewPricingModal
|
||||
} from '$lib/stores/billing';
|
||||
import { organization } from '$lib/stores/organization';
|
||||
import { Button } from '$lib/elements/forms';
|
||||
import { bytesToSize, humanFileSize, mbSecondsToGBHours } from '$lib/helpers/sizeConvertion';
|
||||
@@ -63,14 +68,14 @@
|
||||
<p class="text">
|
||||
On the Scale plan, you'll be charged only for any usage that exceeds the thresholds
|
||||
per resource listed below. <Link.Button
|
||||
on:click={() => ($showUsageRatesModal = true)}
|
||||
on:click={() => ($showUsageRatesModal = $useNewPricingModal)}
|
||||
>Learn more about plan usage limits.</Link.Button>
|
||||
</p>
|
||||
{:else if $organization.billingPlan === BillingPlan.PRO}
|
||||
<p class="text">
|
||||
On the Pro plan, you'll be charged only for any usage that exceeds the thresholds
|
||||
per resource listed below. <Link.Button
|
||||
on:click={() => ($showUsageRatesModal = true)}
|
||||
on:click={() => ($showUsageRatesModal = $useNewPricingModal)}
|
||||
>Learn more about plan usage limits.</Link.Button>
|
||||
</p>
|
||||
{:else if $organization.billingPlan === BillingPlan.FREE}
|
||||
|
||||
Reference in new issue
Block a user