mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
feat: adding new design chnages
This commit is contained in:
1 parent
0f0c76b1cd
commit
ad77b4ecff
8 files changed
+314
-260
No files matched your search
@@ -0,0 +1,11 @@
|
||||
<script lang="ts">
|
||||
import { Layout, Card } from '@appwrite.io/pink-svelte';
|
||||
|
||||
export let gap: 'none' | 'xxxs' | 'xxs' | 'xs' | 's' | 'm' | 'l' | 'xl' | 'xxl' | 'xxxl' = 'l';
|
||||
</script>
|
||||
|
||||
<Card.Base>
|
||||
<Layout.Stack {gap}>
|
||||
<slot />
|
||||
</Layout.Stack>
|
||||
</Card.Base>
|
||||
@@ -84,3 +84,4 @@ export { default as UsageCard } from './usageCard.svelte';
|
||||
export { default as ViewToggle } from './viewToggle.svelte';
|
||||
export { default as RegionEndpoint } from './regionEndpoint.svelte';
|
||||
export { default as ExpirationInput } from './expirationInput.svelte';
|
||||
export { default as EstimatedCard } from './estimatedCard.svelte';
|
||||
@@ -207,7 +207,7 @@ export type AggregationTeam = {
|
||||
* Aggregation billing plan
|
||||
*/
|
||||
plan: string;
|
||||
projectBreakdown: ProjectBreakdown[]
|
||||
projectBreakdown: ProjectBreakdown[];
|
||||
};
|
||||
|
||||
export type ProjectBreakdown = {
|
||||
@@ -215,13 +215,13 @@ export type ProjectBreakdown = {
|
||||
name: string;
|
||||
amount: number;
|
||||
resources: InvoiceUsage[];
|
||||
}
|
||||
};
|
||||
|
||||
export type InvoiceUsage = {
|
||||
resourceId: string;
|
||||
value: number;
|
||||
amount: number;
|
||||
}
|
||||
};
|
||||
|
||||
export type AvailableCredit = {
|
||||
available: number;
|
||||
|
||||
@@ -132,7 +132,9 @@
|
||||
availableCredit={data?.availableCredit}
|
||||
currentPlan={data?.currentPlan}
|
||||
currentAggregation={data?.billingAggregation}
|
||||
currentInvoice={data?.billingInvoice} />
|
||||
currentInvoice={data?.billingInvoice}
|
||||
organizationUsage={data?.organizationUsage}
|
||||
usageProjects={data?.usageProjects} />
|
||||
<PaymentHistory />
|
||||
<PaymentMethods organization={data?.organization} methods={data?.paymentMethods} />
|
||||
<BillingAddress
|
||||
|
||||
@@ -5,6 +5,9 @@ import { sdk } from '$lib/stores/sdk';
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
import type { PageLoad } from './$types';
|
||||
import { isCloud } from '$lib/system';
|
||||
import { Query } from '@appwrite.io/console';
|
||||
import type { UsageProjectInfo } from '../store';
|
||||
import type { OrganizationUsage } from '$lib/sdk/billing';
|
||||
|
||||
export const load: PageLoad = async ({ parent, depends }) => {
|
||||
const { organization, scopes, currentPlan, countryList, locale } = await parent();
|
||||
@@ -57,16 +60,27 @@ export const load: PageLoad = async ({ parent, depends }) => {
|
||||
organization?.billingPlan !== BillingPlan.GITHUB_EDUCATION))
|
||||
: false;
|
||||
|
||||
const [paymentMethods, addressList, billingAddress, availableCredit] = await Promise.all([
|
||||
sdk.forConsole.billing.listPaymentMethods(),
|
||||
sdk.forConsole.billing.listAddresses(),
|
||||
billingAddressPromise,
|
||||
areCreditsSupported ? sdk.forConsole.billing.getAvailableCredit(organization.$id) : null
|
||||
]);
|
||||
const [paymentMethods, addressList, billingAddress, availableCredit, organizationUsage] =
|
||||
await Promise.all([
|
||||
sdk.forConsole.billing.listPaymentMethods(),
|
||||
sdk.forConsole.billing.listAddresses(),
|
||||
billingAddressPromise,
|
||||
areCreditsSupported
|
||||
? sdk.forConsole.billing.getAvailableCredit(organization.$id)
|
||||
: null,
|
||||
sdk.forConsole.billing.listUsage(
|
||||
organization.$id,
|
||||
organization.billingCurrentInvoiceDate,
|
||||
organization.billingNextInvoiceDate
|
||||
)
|
||||
]);
|
||||
|
||||
// make number
|
||||
const credits = availableCredit ? availableCredit.available : null;
|
||||
|
||||
// Get project information for usage display
|
||||
const usageProjects = organizationUsage ? await getUsageProjects(organizationUsage) : {};
|
||||
|
||||
return {
|
||||
paymentMethods,
|
||||
addressList,
|
||||
@@ -76,6 +90,36 @@ export const load: PageLoad = async ({ parent, depends }) => {
|
||||
billingInvoice,
|
||||
areCreditsSupported,
|
||||
countryList,
|
||||
locale
|
||||
locale,
|
||||
organizationUsage,
|
||||
usageProjects
|
||||
};
|
||||
};
|
||||
|
||||
// Get project names and regions for usage display
|
||||
async function getUsageProjects(
|
||||
usage: OrganizationUsage
|
||||
): Promise<Record<string, UsageProjectInfo>> {
|
||||
const projects: Record<string, UsageProjectInfo> = {};
|
||||
const limit = 100;
|
||||
const requests = [];
|
||||
|
||||
for (let index = 0; index < usage.projects.length; index += limit) {
|
||||
const chunkIds = usage.projects.slice(index, index + limit).map((p) => p.projectId);
|
||||
requests.push(
|
||||
sdk.forConsole.projects.list([Query.limit(limit), Query.equal('$id', chunkIds)])
|
||||
);
|
||||
}
|
||||
|
||||
const responses = await Promise.all(requests);
|
||||
for (const response of responses) {
|
||||
for (const project of response.projects) {
|
||||
projects[project.$id] = {
|
||||
name: project.name,
|
||||
region: project.region
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return projects;
|
||||
}
|
||||
@@ -1,31 +1,25 @@
|
||||
<script lang="ts">
|
||||
import { base } from '$app/paths';
|
||||
import { CardGrid } from '$lib/components';
|
||||
import { EstimatedCard } 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 { AggregationTeam, Invoice, Plan } from '$lib/sdk/billing';
|
||||
import { abbreviateNumber, formatCurrency, formatNumberWithCommas } from '$lib/helpers/numbers';
|
||||
import { formatCurrency } from '$lib/helpers/numbers';
|
||||
import { BillingPlan } from '$lib/constants';
|
||||
import { Click, trackEvent } from '$lib/actions/analytics';
|
||||
import {
|
||||
Accordion,
|
||||
Card,
|
||||
Divider,
|
||||
Icon,
|
||||
Layout,
|
||||
Table,
|
||||
Tooltip,
|
||||
Typography
|
||||
} from '@appwrite.io/pink-svelte';
|
||||
import { IconInfo, IconTag } from '@appwrite.io/pink-icons-svelte';
|
||||
import { Card, Divider, Icon, Layout, Typography } from '@appwrite.io/pink-svelte';
|
||||
import { IconTag } from '@appwrite.io/pink-icons-svelte';
|
||||
import CancelDowngradeModel from './cancelDowngradeModal.svelte';
|
||||
import ProjectUsageAccordion from './projectUsageAccordion.svelte';
|
||||
|
||||
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> = {};
|
||||
|
||||
let showCancel: boolean = false;
|
||||
|
||||
@@ -37,250 +31,148 @@
|
||||
</script>
|
||||
|
||||
{#if $organization}
|
||||
{#if currentPlan.usagePerProject}
|
||||
<Card.Base variant="primary" padding="s" radius="s">
|
||||
<EstimatedCard>
|
||||
<Typography.Title size="s">{currentPlan.name} plan</Typography.Title>
|
||||
|
||||
<Typography.Text color="--fgcolor-neutral-primary">
|
||||
Next payment of <span class="text u-bold"
|
||||
>{formatCurrency(currentInvoice?.amount || currentPlan?.price || 0)}</span>
|
||||
will occur on
|
||||
<span class="text u-bold">{toLocaleDate($organization?.billingNextInvoiceDate)}</span>.
|
||||
</Typography.Text>
|
||||
|
||||
<Divider />
|
||||
|
||||
<div class="billing-cycle-header">
|
||||
<Typography.Text color="--fgcolor-neutral-primary" variant="m-500">
|
||||
Current billing cycle ({new Date(
|
||||
$organization?.billingCurrentInvoiceDate
|
||||
).toLocaleDateString('en', { day: 'numeric', month: 'short' })}-{new Date(
|
||||
$organization?.billingNextInvoiceDate
|
||||
).toLocaleDateString('en', { day: 'numeric', month: 'short' })})
|
||||
</Typography.Text>
|
||||
<Typography.Text color="--fgcolor-neutral-tertiary" variant="m-400">
|
||||
Estimate, subject to change based on usage.
|
||||
</Typography.Text>
|
||||
</div>
|
||||
|
||||
<!-- Billing breakdown table -->
|
||||
<Card.Base variant="secondary" padding="s">
|
||||
<Layout.Stack>
|
||||
<Typography.Text color="--fgcolor-neutral-primary">
|
||||
{currentPlan.name} plan
|
||||
</Typography.Text>
|
||||
<Typography.Text color="--fgcolor-neutral-primary">
|
||||
Next payment of <span class="text u-bold">${currentAggregation.amount}</span>
|
||||
will occur on
|
||||
<span class="text u-bold"
|
||||
>{toLocaleDate($organization?.billingNextInvoiceDate)}</span>
|
||||
</Typography.Text>
|
||||
</Layout.Stack>
|
||||
<Divider />
|
||||
<Table.Root let:root columns={[{ id: 'project' }]}>
|
||||
<Table.Row.Base {root}>
|
||||
<Table.Cell column="project" {root}>
|
||||
<Layout.Stack direction="row" justifyContent="space-between">
|
||||
<!-- Base Plan -->
|
||||
<div class="billing-row">
|
||||
<Typography.Text color="--fgcolor-neutral-primary">Base plan</Typography.Text>
|
||||
<Typography.Text class="price">
|
||||
{formatCurrency(
|
||||
isTrial || $organization?.billingPlan === BillingPlan.GITHUB_EDUCATION
|
||||
? 0
|
||||
: currentPlan?.price || 0
|
||||
)}
|
||||
</Typography.Text>
|
||||
</div>
|
||||
|
||||
<!-- Project Usage Accordion -->
|
||||
{#if organizationUsage?.projects && organizationUsage.projects.length > 0}
|
||||
<ProjectUsageAccordion
|
||||
projects={organizationUsage.projects}
|
||||
{usageProjects}
|
||||
{currentPlan}
|
||||
{currentAggregation} />
|
||||
{/if}
|
||||
|
||||
<!-- Add-ons -->
|
||||
{#if currentPlan.budgeting && extraUsage > 0}
|
||||
{#each currentAggregation.resources.filter((r) => r.amount && r.amount > 0) as excess}
|
||||
<div class="billing-row">
|
||||
<Typography.Text color="--fgcolor-neutral-primary"
|
||||
>Base plan</Typography.Text>
|
||||
<Typography.Text>
|
||||
{isTrial ||
|
||||
$organization?.billingPlan === BillingPlan.GITHUB_EDUCATION
|
||||
? formatCurrency(0)
|
||||
: currentPlan
|
||||
? formatCurrency(currentPlan?.price)
|
||||
: ''}
|
||||
</Typography.Text>
|
||||
</Layout.Stack>
|
||||
</Table.Cell>
|
||||
</Table.Row.Base>
|
||||
{#each currentAggregation.resources.filter((r) => r.amount && r.amount > 0 && Object.keys(currentPlan.addons).includes(r.resourceId) && currentPlan.addons[r.resourceId].price > 0) as excess, i}
|
||||
{#if i > 0}
|
||||
<Divider />
|
||||
{/if}
|
||||
<Table.Row.Base {root}>
|
||||
<Table.Cell column="project" {root}>
|
||||
<Layout.Stack direction="row" justifyContent="space-between">
|
||||
<Typography.Text color="--fgcolor-neutral-primary"
|
||||
>{excess.resourceId}</Typography.Text>
|
||||
<Typography.Text>
|
||||
{formatCurrency(excess.amount)}
|
||||
</Typography.Text>
|
||||
</Layout.Stack>
|
||||
</Table.Cell>
|
||||
</Table.Row.Base>
|
||||
{/each}
|
||||
{#each currentAggregation.projectBreakdown as projectBreakdown}
|
||||
<Accordion title="{projectBreakdown.name}">
|
||||
<svelte:fragment slot="end">
|
||||
{formatCurrency(projectBreakdown.amount)}
|
||||
</svelte:fragment>
|
||||
<Layout.Stack gap="xs">
|
||||
{#each projectBreakdown.resources as resource, i}
|
||||
{#if i > 0}
|
||||
<Divider />
|
||||
{/if}
|
||||
>{excess.resourceId}</Typography.Text>
|
||||
<Typography.Text class="price"
|
||||
>{formatCurrency(excess.amount)}</Typography.Text>
|
||||
</div>
|
||||
{/each}
|
||||
{/if}
|
||||
|
||||
<Layout.Stack gap="xxxs">
|
||||
<Layout.Stack
|
||||
direction="row"
|
||||
justifyContent="space-between">
|
||||
<Typography.Text color="--fgcolor-neutral-primary">
|
||||
{resource.resourceId}
|
||||
</Typography.Text>
|
||||
<Typography.Text>
|
||||
{formatCurrency(resource.amount)}
|
||||
</Typography.Text>
|
||||
</Layout.Stack>
|
||||
<Layout.Stack direction="row">
|
||||
<Tooltip
|
||||
placement="bottom"
|
||||
disabled={resource.value <= 1000}>
|
||||
<svelte:fragment slot="tooltip">
|
||||
{formatNumberWithCommas(resource.value)}
|
||||
</svelte:fragment>
|
||||
<span>{abbreviateNumber(resource.value)}</span>
|
||||
</Tooltip>
|
||||
</Layout.Stack>
|
||||
</Layout.Stack>
|
||||
{/each}
|
||||
</Layout.Stack>
|
||||
</Accordion>
|
||||
{/each}
|
||||
</Table.Root>
|
||||
{#if currentPlan.supportsCredits && availableCredit > 0}
|
||||
<div class="billing-row">
|
||||
<div class="credits-content">
|
||||
<Icon size="s" icon={IconTag} color="--fgcolor-success" />
|
||||
<Typography.Text color="--fgcolor-neutral-primary"
|
||||
>Credits to be applied</Typography.Text>
|
||||
</div>
|
||||
<Typography.Text class="price" color="--fgcolor-success">
|
||||
-{formatCurrency(
|
||||
Math.min(availableCredit, currentInvoice?.amount ?? 0)
|
||||
)}
|
||||
</Typography.Text>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<Divider />
|
||||
|
||||
<!-- Total -->
|
||||
<div class="billing-row total">
|
||||
<Typography.Text color="--fgcolor-neutral-primary" variant="m-500"
|
||||
>Total</Typography.Text>
|
||||
<Typography.Text
|
||||
class="price"
|
||||
color="--fgcolor-neutral-primary"
|
||||
variant="m-500">
|
||||
{formatCurrency(
|
||||
Math.max(
|
||||
(currentInvoice?.amount ?? 0) -
|
||||
Math.min(availableCredit, currentInvoice?.amount ?? 0),
|
||||
0
|
||||
)
|
||||
)}
|
||||
</Typography.Text>
|
||||
</div>
|
||||
</Layout.Stack>
|
||||
</Card.Base>
|
||||
{:else}
|
||||
<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
|
||||
title="Add-ons"
|
||||
badge={currentAggregation.resources
|
||||
.filter((r) => r.amount && r.amount > 0)
|
||||
.length.toString()}>
|
||||
<svelte:fragment slot="end">
|
||||
{formatCurrency(extraUsage >= 0 ? extraUsage : 0)}
|
||||
</svelte:fragment>
|
||||
<Layout.Stack gap="xs">
|
||||
{#each currentAggregation.resources.filter((r) => r.amount && r.amount > 0) as excess, i}
|
||||
{#if i > 0}
|
||||
<Divider />
|
||||
{/if}
|
||||
|
||||
<Layout.Stack gap="xxxs">
|
||||
<Layout.Stack
|
||||
direction="row"
|
||||
justifyContent="space-between">
|
||||
<Typography.Text color="--fgcolor-neutral-primary">
|
||||
{excess.resourceId}
|
||||
</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}
|
||||
</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>
|
||||
<!-- Actions -->
|
||||
<div class="actions-container">
|
||||
{#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.OrganizationClickUpgrade, {
|
||||
trackEvent('click_organization_plan_update', {
|
||||
from: 'button',
|
||||
source: 'billing_tab'
|
||||
})}>
|
||||
Upgrade
|
||||
Change plan
|
||||
</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}
|
||||
{/if}
|
||||
<Button secondary href={`${base}/organization-${$organization?.$id}/usage`}>
|
||||
View estimated usage
|
||||
</Button>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</EstimatedCard>
|
||||
{/if}
|
||||
|
||||
<CancelDowngradeModel bind:showCancel />
|
||||
@@ -290,6 +182,44 @@
|
||||
--billing-card-border-color: hsl(var(--color-neutral-10));
|
||||
}
|
||||
|
||||
.billing-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 0.75rem 0;
|
||||
border-bottom: 1px solid var(--bgcolor-neutral-invert);
|
||||
}
|
||||
|
||||
.billing-row:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.billing-row.total {
|
||||
border-top: 1px solid var(--bgcolor-neutral-invert);
|
||||
border-bottom: none;
|
||||
padding-top: 1rem;
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
|
||||
.price {
|
||||
text-align: right;
|
||||
min-width: 80px;
|
||||
}
|
||||
|
||||
.credits-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.billing-cycle-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
margin-bottom: 1rem;
|
||||
margin-top: 1.5rem;
|
||||
}
|
||||
|
||||
:global(.card-only-on-desktop) {
|
||||
background: hsl(var(--color-neutral-5));
|
||||
border-radius: var(--corner-radius-medium, 8px);
|
||||
@@ -307,12 +237,15 @@
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.billing-cycle-header {
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
: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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
<script lang="ts">
|
||||
import { Layout, Typography, Accordion } from '@appwrite.io/pink-svelte';
|
||||
import { formatCurrency } from '$lib/helpers/numbers';
|
||||
import type { OrganizationUsage } from '$lib/sdk/billing';
|
||||
import type { Models } from '@appwrite.io/console';
|
||||
|
||||
type UsageProjectInfo = Pick<Models.Project, 'name' | 'region'>;
|
||||
|
||||
export let projects: OrganizationUsage['projects'];
|
||||
export let usageProjects: Record<string, UsageProjectInfo> = {};
|
||||
export let currentPlan: any;
|
||||
export let currentAggregation: any;
|
||||
|
||||
function getUsageCost(projectId: string): number {
|
||||
const projectBreakdown = currentAggregation?.projectBreakdown?.find(
|
||||
(p: any) => p.projectId === projectId
|
||||
);
|
||||
return projectBreakdown?.amount || 0;
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if projects && projects.length > 0}
|
||||
<Layout.Stack gap="none">
|
||||
{#each projects as project, index}
|
||||
{@const projectInfo = usageProjects[project.projectId]}
|
||||
{@const projectCost = getUsageCost(project.projectId)}
|
||||
{@const projectName = projectInfo?.name || 'Unknown Project'}
|
||||
{@const isLastItem = index === projects.length - 1}
|
||||
|
||||
<Accordion title={projectName} hideDivider={isLastItem}>
|
||||
<svelte:fragment slot="end">
|
||||
<Typography.Text class="price">{formatCurrency(projectCost)}</Typography.Text>
|
||||
</svelte:fragment>
|
||||
<Layout.Stack>
|
||||
<div class="accordion-child">
|
||||
<Typography.Text color="--fgcolor-neutral-primary"
|
||||
>{projectName}</Typography.Text>
|
||||
<Typography.Text class="price"
|
||||
>{formatCurrency(projectCost)}</Typography.Text>
|
||||
</div>
|
||||
</Layout.Stack>
|
||||
</Accordion>
|
||||
{/each}
|
||||
</Layout.Stack>
|
||||
{:else}
|
||||
<Layout.Stack gap="s" alignItems="center" justifyContent="center">
|
||||
<Typography.Text variant="m-400" color="--fgcolor-neutral-tertiary">
|
||||
No projects with usage data found
|
||||
</Typography.Text>
|
||||
</Layout.Stack>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.price {
|
||||
text-align: right;
|
||||
min-width: 80px;
|
||||
}
|
||||
|
||||
.accordion-child {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 0.75rem 0 0.75rem 2rem;
|
||||
}
|
||||
</style>
|
||||
@@ -7,9 +7,7 @@ export const load: PageLoad = async ({ depends, parent }) => {
|
||||
const { members, currentPlan, organizations } = await parent();
|
||||
depends(Dependencies.UPGRADE_PLAN);
|
||||
|
||||
const [plans] = await Promise.all([
|
||||
sdk.forConsole.billing.listPlans()
|
||||
]);
|
||||
const [plans] = await Promise.all([sdk.forConsole.billing.listPlans()]);
|
||||
let plan: BillingPlan;
|
||||
|
||||
if (currentPlan?.$id === BillingPlan.SCALE) {
|
||||
|
||||
Reference in new issue
Block a user