From b819f1f2cb05e0971baf590a9e12271de2e6836a Mon Sep 17 00:00:00 2001
From: Arman
Date: Wed, 5 Jul 2023 04:02:19 +0200
Subject: [PATCH] fix: add billingPlan variable, some refactor and clean up
---
src/lib/elements/table/body.svelte | 18 ++++++++++
src/lib/stores/billing.ts | 36 -------------------
src/lib/stores/organization.ts | 13 ++++---
src/lib/system.ts | 18 ----------
.../console/createOrganizationCloud.svelte | 5 ++-
.../billing/+page.svelte | 2 +-
.../billing/budgetCap.svelte | 2 +-
.../createProjectCloud.svelte | 3 +-
.../organization-[organization]/header.svelte | 9 ++++-
.../wizard/store.ts | 3 --
.../project-[project]/settings/+page.svelte | 35 ------------------
src/routes/console/wizard/step1.svelte | 8 ++---
src/routes/console/wizard/step3.svelte | 4 +--
src/routes/console/wizard/store.ts | 7 ++--
src/routes/console/wizard/usageRates.svelte | 2 +-
15 files changed, 51 insertions(+), 114 deletions(-)
diff --git a/src/lib/elements/table/body.svelte b/src/lib/elements/table/body.svelte
index 635b587f2..f784e8587 100644
--- a/src/lib/elements/table/body.svelte
+++ b/src/lib/elements/table/body.svelte
@@ -1,3 +1,21 @@
+
+
+{#if isCloud && limitReached && name}
+
+ |
+
+ Upgrade your plan to add {name} to your organization
+
+
+ |
+
+{/if}
diff --git a/src/lib/stores/billing.ts b/src/lib/stores/billing.ts
index 32edebbe6..36a325e84 100644
--- a/src/lib/stores/billing.ts
+++ b/src/lib/stores/billing.ts
@@ -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 = {
diff --git a/src/lib/stores/organization.ts b/src/lib/stores/organization.ts
index 82fc5aae8..80de45ac3 100644
--- a/src/lib/stores/organization.ts
+++ b/src/lib/stores/organization.ts
@@ -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> & {
+ billingBudget: number;
+ billingPlan: string;
+ budgetAlert: number[];
+ paymentMethodId: string;
+ backupPaymentMethodId: string;
+};
+
export const newOrgModal = writable(false);
export const newMemberModal = writable(false);
export const organizationList = derived(
page,
($page) => $page.data.organizations as Models.TeamList>
);
-export const organization = derived(
- page,
- ($page) => $page.data?.organization as Models.Team>
-);
+export const organization = derived(page, ($page) => $page.data?.organization as Team);
export const members = derived(page, ($page) => $page.data.members as Models.MembershipList);
diff --git a/src/lib/system.ts b/src/lib/system.ts
index 02f4ea13e..69bd7d2cc 100644
--- a/src/lib/system.ts
+++ b/src/lib/system.ts
@@ -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;
diff --git a/src/routes/console/createOrganizationCloud.svelte b/src/routes/console/createOrganizationCloud.svelte
index a3d5fa66f..3017e63a4 100644
--- a/src/routes/console/createOrganizationCloud.svelte
+++ b/src/routes/console/createOrganizationCloud.svelte
@@ -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: []
};
diff --git a/src/routes/console/organization-[organization]/billing/+page.svelte b/src/routes/console/organization-[organization]/billing/+page.svelte
index 8717b98c3..a4514b15a 100644
--- a/src/routes/console/organization-[organization]/billing/+page.svelte
+++ b/src/routes/console/organization-[organization]/billing/+page.svelte
@@ -20,7 +20,7 @@
-->
- {#if $organization?.tier !== 'pro'}
+ {#if $organization?.billingPlan !== 'tier-2'}
{/if}
diff --git a/src/routes/console/organization-[organization]/billing/budgetCap.svelte b/src/routes/console/organization-[organization]/billing/budgetCap.svelte
index d00353ff9..d09af29f0 100644
--- a/src/routes/console/organization-[organization]/billing/budgetCap.svelte
+++ b/src/routes/console/organization-[organization]/billing/budgetCap.svelte
@@ -43,7 +43,7 @@
class="link">Learn more about usage rates.
- {#if $organization?.tier !== 'pro'}
+ {#if $organization?.billingPlan !== 'tier-2'}
Budget caps are a Pro plan feature
diff --git a/src/routes/console/organization-[organization]/createProjectCloud.svelte b/src/routes/console/organization-[organization]/createProjectCloud.svelte
index 9152fdbc7..689d865ec 100644
--- a/src/routes/console/organization-[organization]/createProjectCloud.svelte
+++ b/src/routes/console/organization-[organization]/createProjectCloud.svelte
@@ -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'
};
});
diff --git a/src/routes/console/organization-[organization]/header.svelte b/src/routes/console/organization-[organization]/header.svelte
index 892ed1f2d..a4510c7cc 100644
--- a/src/routes/console/organization-[organization]/header.svelte
+++ b/src/routes/console/organization-[organization]/header.svelte
@@ -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)}>
- {$organization.name}
+
+ {$organization.name}
+ {#if isCloud && $organization?.billingPlan === 'tier-0'}
+ FREE
+ {/if}
+
diff --git a/src/routes/console/organization-[organization]/wizard/store.ts b/src/routes/console/organization-[organization]/wizard/store.ts
index 3e099b019..2dbcdfb8d 100644
--- a/src/routes/console/organization-[organization]/wizard/store.ts
+++ b/src/routes/console/organization-[organization]/wizard/store.ts
@@ -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'
});
diff --git a/src/routes/console/project-[project]/settings/+page.svelte b/src/routes/console/project-[project]/settings/+page.svelte
index e0027f9af..cf8659329 100644
--- a/src/routes/console/project-[project]/settings/+page.svelte
+++ b/src/routes/console/project-[project]/settings/+page.svelte
@@ -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 @@
{#if $project}
- {#if isCloud}
-
- Plan Summary
-
- Your current project plan. For more information on Appwrite plans,
- view our pricing guide.
-
-
-
-
-
- {TIER} plan
-
-
REGION
-
- {#if !isFree}
-
PRICE
- {/if}
-
-
-
- {#if isFree}
-
- {:else}
-
-
- {/if}
-
-
- {/if}