mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
fix: add billingPlan variable, some refactor and clean up
This commit is contained in:
1 parent
fef57fae07
commit
b819f1f2cb
15 files changed
+51
-114
No files matched your search
@@ -1,3 +1,21 @@
|
||||
<script lang="ts">
|
||||
import { isCloud } from '$lib/system';
|
||||
import { Button } from '../forms';
|
||||
|
||||
export let limitReached = true;
|
||||
export let name: string = null;
|
||||
</script>
|
||||
|
||||
<div class="table-tbody" role="rowgroup">
|
||||
<slot />
|
||||
</div>
|
||||
{#if isCloud && limitReached && name}
|
||||
<tr class="table-row">
|
||||
<td class="table-col" colspan="100%">
|
||||
<span class="u-flex u-gap-24 u-main-center u-cross-center">
|
||||
<span class="text">Upgrade your plan to add {name} to your organization</span>
|
||||
<Button secondary on:click={() => console.log('test')}>Change plan</Button>
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
{/if}
|
||||
@@ -210,42 +210,6 @@ export class Billing {
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
async updatePaymentMethodOld(
|
||||
teamId: string,
|
||||
paymentMethodId: string,
|
||||
providerMethodId: string
|
||||
) {
|
||||
const path = `/teams/${teamId}/payment-methods/${paymentMethodId}`;
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'PUT',
|
||||
uri,
|
||||
{ 'content-type': 'application/json' },
|
||||
{
|
||||
providerMethodId
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
async updateProjectPlan(projectId: string, billingPlan: string) {
|
||||
const path = `/project/${projectId}/plan`;
|
||||
const params: Payload = {
|
||||
billingPlan
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call('patch', uri, { 'content-type': 'application/json' }, params);
|
||||
}
|
||||
|
||||
async updateProjectBudget(projectId: string, budget: number, alertLimit: number) {
|
||||
const path = `/project/${projectId}/budget`;
|
||||
const params: Payload = {
|
||||
budget,
|
||||
alertLimit
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call('patch', uri, { 'content-type': 'application/json' }, params);
|
||||
}
|
||||
}
|
||||
|
||||
export const tierFree = {
|
||||
|
||||
@@ -2,14 +2,19 @@ import { page } from '$app/stores';
|
||||
import { derived, writable } from 'svelte/store';
|
||||
import type { Models } from '@appwrite.io/console';
|
||||
|
||||
export type Team = Models.Team<Record<string, unknown>> & {
|
||||
billingBudget: number;
|
||||
billingPlan: string;
|
||||
budgetAlert: number[];
|
||||
paymentMethodId: string;
|
||||
backupPaymentMethodId: string;
|
||||
};
|
||||
|
||||
export const newOrgModal = writable<boolean>(false);
|
||||
export const newMemberModal = writable<boolean>(false);
|
||||
export const organizationList = derived(
|
||||
page,
|
||||
($page) => $page.data.organizations as Models.TeamList<Record<string, unknown>>
|
||||
);
|
||||
export const organization = derived(
|
||||
page,
|
||||
($page) => $page.data?.organization as Models.Team<Record<string, unknown>>
|
||||
);
|
||||
export const organization = derived(page, ($page) => $page.data?.organization as Team);
|
||||
export const members = derived(page, ($page) => $page.data.members as Models.MembershipList);
|
||||
@@ -3,13 +3,6 @@ export enum Mode {
|
||||
SELF_HOSTED = 'self-hosted'
|
||||
}
|
||||
|
||||
export enum Tier {
|
||||
BASE = 'base',
|
||||
STARTER = 'starter',
|
||||
PRO = 'pro',
|
||||
ENTERPRISE = 'enterprise'
|
||||
}
|
||||
|
||||
export const VARS = {
|
||||
APPWRITE_ENDPOINT: import.meta.env?.VITE_APPWRITE_ENDPOINT?.toString() as string | undefined,
|
||||
GROWTH_ENDPOINT: import.meta.env?.VITE_APPWRITE_GROWTH_ENDPOINT?.toString() as
|
||||
@@ -31,14 +24,3 @@ export const ENV = {
|
||||
export const MODE = VARS.CONSOLE_MODE === Mode.CLOUD ? Mode.CLOUD : Mode.SELF_HOSTED;
|
||||
export const isCloud = MODE === Mode.CLOUD;
|
||||
export const isSelfHosted = MODE === Mode.SELF_HOSTED;
|
||||
export const TIER =
|
||||
VARS.CONSOLE_TIER === Tier.BASE
|
||||
? Tier.BASE
|
||||
: VARS.CONSOLE_TIER === Tier.PRO
|
||||
? Tier.PRO
|
||||
: Tier.ENTERPRISE;
|
||||
export const isFree = VARS.CONSOLE_TIER === Tier.BASE;
|
||||
export const isStarter = VARS.CONSOLE_TIER === Tier.STARTER;
|
||||
export const isPro = VARS.CONSOLE_TIER === Tier.PRO;
|
||||
export const isEnterprise = VARS.CONSOLE_TIER === Tier.ENTERPRISE;
|
||||
export const isPaid = VARS.CONSOLE_TIER === Tier.STARTER || VARS.CONSOLE_TIER === Tier.PRO;
|
||||
@@ -13,7 +13,6 @@
|
||||
import { Dependencies } from '$lib/constants';
|
||||
import { Submit, trackEvent, trackError } from '$lib/actions/analytics';
|
||||
import { ID } from '@appwrite.io/console';
|
||||
import { Tier } from '$lib/system';
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
@@ -26,7 +25,7 @@
|
||||
const org = await sdk.forConsole.billing.createOrganization(
|
||||
$createOrganization.id ?? ID.unique(),
|
||||
$createOrganization.name,
|
||||
$createOrganization.tier,
|
||||
$createOrganization.billingPlan,
|
||||
$createOrganization.payment
|
||||
);
|
||||
await invalidate(Dependencies.ACCOUNT);
|
||||
@@ -51,7 +50,7 @@
|
||||
$createOrganization = {
|
||||
id: null,
|
||||
name: null,
|
||||
tier: Tier['PRO'],
|
||||
billingPlan: 'tier-2',
|
||||
payment: null,
|
||||
collaborators: []
|
||||
};
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
<BillingAddress />
|
||||
<AvailableCredit /> -->
|
||||
<BudgetCap />
|
||||
{#if $organization?.tier !== 'pro'}
|
||||
{#if $organization?.billingPlan !== 'tier-2'}
|
||||
<BudgetAlert />
|
||||
{/if}
|
||||
</Container>
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
class="link">Learn more about usage rates.</a>
|
||||
</p>
|
||||
<svelte:fragment slot="aside">
|
||||
{#if $organization?.tier !== 'pro'}
|
||||
{#if $organization?.billingPlan !== 'tier-2'}
|
||||
<Alert type="info">
|
||||
<svelte:fragment slot="title">
|
||||
Budget caps are a Pro plan feature
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
import { page } from '$app/stores';
|
||||
import { Submit, trackEvent, trackError } from '$lib/actions/analytics';
|
||||
import { ID } from '@appwrite.io/console';
|
||||
import { Tier } from '$lib/system';
|
||||
import { createProject } from './wizard/store';
|
||||
|
||||
const teamId = $page.params.organization;
|
||||
@@ -52,7 +51,7 @@
|
||||
$createProject = {
|
||||
id: null,
|
||||
name: null,
|
||||
tier: Tier['PRO']
|
||||
region: 'eu-central-1'
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { base } from '$app/paths';
|
||||
import { page } from '$app/stores';
|
||||
import { AvatarGroup, DropList, DropListItem, DropListLink, Tab, Tabs } from '$lib/components';
|
||||
import { Pill } from '$lib/elements';
|
||||
import { Button } from '$lib/elements/forms';
|
||||
import { isTabSelected } from '$lib/helpers/load';
|
||||
import { Cover } from '$lib/layout';
|
||||
@@ -15,6 +16,7 @@
|
||||
import { wizard } from '$lib/stores/wizard';
|
||||
import { isCloud } from '$lib/system';
|
||||
import CreateOrganizationCloud from '../createOrganizationCloud.svelte';
|
||||
import Android from '../project-[project]/overview/platforms/[platform]/android.svelte';
|
||||
|
||||
let showDropdown = false;
|
||||
|
||||
@@ -72,7 +74,12 @@
|
||||
class="button is-text u-padding-inline-0"
|
||||
on:click={() => (showDropdown = !showDropdown)}>
|
||||
<h1 class="heading-level-4 u-flex u-cross-center u-gap-8">
|
||||
<span class="text"> {$organization.name}</span>
|
||||
<span class="u-flex u-cross-center u-gap-8">
|
||||
{$organization.name}
|
||||
{#if isCloud && $organization?.billingPlan === 'tier-0'}
|
||||
<Pill>FREE</Pill>
|
||||
{/if}
|
||||
</span>
|
||||
<span
|
||||
class={`icon-cheveron-${showDropdown ? 'up' : 'down'}`}
|
||||
aria-hidden="true" />
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
import { Tier } from '$lib/system';
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
export const createProject = writable<{
|
||||
id?: string;
|
||||
name: string;
|
||||
tier: Tier;
|
||||
region: string;
|
||||
}>({
|
||||
id: null,
|
||||
name: null,
|
||||
tier: Tier['PRO'],
|
||||
region: 'eu-central-1'
|
||||
});
|
||||
@@ -14,7 +14,6 @@
|
||||
import { base } from '$app/paths';
|
||||
import { page } from '$app/stores';
|
||||
import { Submit, trackEvent, trackError } from '$lib/actions/analytics';
|
||||
import { TIER, isCloud, isFree } from '$lib/system';
|
||||
|
||||
let name: string = null;
|
||||
let showDelete = false;
|
||||
@@ -75,40 +74,6 @@
|
||||
|
||||
<Container>
|
||||
{#if $project}
|
||||
{#if isCloud}
|
||||
<CardGrid>
|
||||
<Heading tag="h6" size="7">Plan Summary</Heading>
|
||||
<p class="text">
|
||||
Your current project plan. For more information on Appwrite plans, <a
|
||||
href="http://appwrite.io/pricing"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
class="link">
|
||||
view our pricing guide.</a>
|
||||
</p>
|
||||
<svelte:fragment slot="aside">
|
||||
<div class="box u-flex u-main-space-between">
|
||||
<div>
|
||||
<h6 class="u-bold u-trim-1">
|
||||
<span class="u-capitalize">{TIER}</span> plan
|
||||
</h6>
|
||||
<p class="text">REGION</p>
|
||||
</div>
|
||||
{#if !isFree}
|
||||
<p>PRICE</p>
|
||||
{/if}
|
||||
</div>
|
||||
</svelte:fragment>
|
||||
<svelte:fragment slot="actions">
|
||||
{#if isFree}
|
||||
<Button event="change_plan">Upgrade to Pro</Button>
|
||||
{:else}
|
||||
<Button text event="change_plan">Change plan</Button>
|
||||
<Button secondary event="change_plan">View payment details</Button>
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
</CardGrid>
|
||||
{/if}
|
||||
<Form onSubmit={updateName}>
|
||||
<CardGrid>
|
||||
<Heading tag="h6" size="7">API Credentials</Heading>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
let showCustomId = false;
|
||||
|
||||
$: anyOrgFree = $organizationList.teams?.find((org) => org?.tier === 'free');
|
||||
$: anyOrgFree = $organizationList.teams?.find((org) => org?.billingPlan === 'tier-0');
|
||||
</script>
|
||||
|
||||
<WizardStep>
|
||||
@@ -51,7 +51,7 @@
|
||||
style="--p-grid-item-size:16em; --p-grid-item-size-small-screens:16rem; --grid-gap: 1rem;">
|
||||
{#if !anyOrgFree}
|
||||
<li>
|
||||
<LabelCard name="plan" bind:group={$createOrganization.tier} value="free">
|
||||
<LabelCard name="plan" bind:group={$createOrganization.tier} value="tier-0">
|
||||
<svelte:fragment slot="custom">
|
||||
<div class="u-flex u-flex-vertical u-gap-4 u-width-full-line">
|
||||
<h4 class="body-text-2 u-bold">
|
||||
@@ -64,7 +64,7 @@
|
||||
</li>
|
||||
{/if}
|
||||
<li>
|
||||
<LabelCard name="plan" bind:group={$createOrganization.tier} value="starter">
|
||||
<LabelCard name="plan" bind:group={$createOrganization.tier} value="tier-1">
|
||||
<svelte:fragment slot="custom">
|
||||
<div class="u-flex u-flex-vertical u-gap-4 u-width-full-line">
|
||||
<h4 class="body-text-2 u-bold">
|
||||
@@ -79,7 +79,7 @@
|
||||
</LabelCard>
|
||||
</li>
|
||||
<li>
|
||||
<LabelCard name="plan" bind:group={$createOrganization.tier} value="pro">
|
||||
<LabelCard name="plan" bind:group={$createOrganization.tier} value="tier-2">
|
||||
<svelte:fragment slot="custom">
|
||||
<div class="u-flex u-flex-vertical u-gap-4 u-width-full-line">
|
||||
<h4 class="body-text-2 u-bold">
|
||||
|
||||
@@ -43,10 +43,10 @@
|
||||
</svelte:fragment>
|
||||
|
||||
<Alert type="info">
|
||||
{#if $createOrganization.tier === 'pro'}
|
||||
{#if $createOrganization.tier === 'tier-2'}
|
||||
You can add unlimited organization members on the Pro plan for $20 each. Each member
|
||||
added will receive an email invite to your organization on completion.
|
||||
{:else if $createOrganization.tier === 'starter'}
|
||||
{:else if $createOrganization.tier === 'tier-1'}
|
||||
You can add up to three organization members with the Starter plan for $10 each. Each
|
||||
member added will receive an email invite to your organization on completion.
|
||||
{:else}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { Tier } from '$lib/system';
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
export type Collborator = {
|
||||
@@ -6,17 +5,19 @@ export type Collborator = {
|
||||
role: string;
|
||||
};
|
||||
|
||||
export type Tier = 'tier-0' | 'tier-1' | 'tier-2';
|
||||
|
||||
export const createOrganization = writable<{
|
||||
id?: string;
|
||||
name: string;
|
||||
tier: Tier;
|
||||
billingPlan: Tier;
|
||||
payment: string;
|
||||
budget?: number;
|
||||
collaborators?: Collborator[];
|
||||
}>({
|
||||
id: null,
|
||||
name: null,
|
||||
tier: Tier['PRO'],
|
||||
billingPlan: 'tier-2',
|
||||
payment: null,
|
||||
collaborators: []
|
||||
});
|
||||
@@ -29,7 +29,7 @@
|
||||
<TableCellHead>Rate</TableCellHead>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{#each usageRates[$createOrganization.tier] as usage}
|
||||
{#each usageRates[$createOrganization.billingPlan] as usage}
|
||||
<TableRow>
|
||||
<TableCellText title="resource">{usage.resource}</TableCellText>
|
||||
<TableCellText title="limit">{usage.limit}</TableCellText>
|
||||
|
||||
Reference in new issue
Block a user