Skip to content

Commit b3d447a

Browse files
Switch to isFreePlan for free plan checks
Replace direct BillingPlan.FREE checks with isFreePlan throughout UI and routes to determine the Free tier.
1 parent b3ae2c2 commit b3d447a

43 files changed

Lines changed: 126 additions & 76 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/lib/components/archiveProject.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import { getPlatformInfo } from '$lib/helpers/platform';
3030
import { Status, type Models } from '@appwrite.io/console';
3131
import type { ComponentType } from 'svelte';
32-
import { BillingPlan } from '$lib/constants';
3332
import { goto } from '$app/navigation';
3433
import { base } from '$app/paths';
3534
import { sdk } from '$lib/stores/sdk';
@@ -97,7 +96,7 @@
9796
function isUnarchiveDisabled(): boolean {
9897
if (!organization || !currentPlan) return true;
9998
100-
if (organization.billingPlan === BillingPlan.FREE) {
99+
if (isFreePlan(organization.billingPlan)) {
101100
const currentProjectCount = organization.projects?.length || 0;
102101
const projectLimit = currentPlan.projects || 0;
103102
@@ -189,6 +188,7 @@
189188
}
190189
191190
import { formatName as formatNameHelper } from '$lib/helpers/string';
191+
import { isFreePlan } from '$lib/helpers/billing';
192192
function formatName(name: string, limit: number = 19) {
193193
return formatNameHelper(name, limit, $isSmallViewport);
194194
}

src/lib/components/backupDatabaseAlert.svelte

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import { backupsBannerId, showPolicyAlert } from '$lib/stores/database';
1111
import { IconX } from '@appwrite.io/pink-icons-svelte';
1212
import { Icon } from '@appwrite.io/pink-svelte';
13+
import { isFreePlan } from '$lib/helpers/billing';
1314
1415
function handleClose() {
1516
showPolicyAlert.set(false);
@@ -18,14 +19,14 @@
1819
</script>
1920

2021
{#if $showPolicyAlert && isCloud && $organization?.$id && page.url.pathname.match(/\/databases\/database-[^/]+$/)}
21-
{@const isFreePlan = $organization?.billingPlan === BillingPlan.FREE}
22+
{@const isFree = isFreePlan($organization?.billingPlan)}
2223

23-
{@const subtitle = isFreePlan
24+
{@const subtitle = isFree
2425
? 'Upgrade your plan to ensure your data stays safe and backed up'
2526
: 'Protect your data by quickly adding a backup policy'}
2627

27-
{@const ctaText = isFreePlan ? 'Upgrade plan' : 'Create policy'}
28-
{@const ctaURL = isFreePlan ? $upgradeURL : `${page.url.pathname}/backups`}
28+
{@const ctaText = isFree ? 'Upgrade plan' : 'Create policy'}
29+
{@const ctaURL = isFree ? $upgradeURL : `${page.url.pathname}/backups`}
2930

3031
<HeaderAlert type="warning" title="Your database has no backup policy">
3132
<svelte:fragment>{subtitle}</svelte:fragment>
@@ -35,7 +36,7 @@
3536
href={ctaURL}
3637
secondary
3738
fullWidthMobile
38-
event={isFreePlan ? 'backup_banner_upgrade' : 'backup_banner_add'}>
39+
event={isFree ? 'backup_banner_upgrade' : 'backup_banner_add'}>
3940
<span class="text">{ctaText}</span>
4041
</Button>
4142

src/lib/components/backupRestoreBox.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import { getProjectId } from '$lib/helpers/project';
1414
import { toLocaleDate } from '$lib/helpers/date';
1515
import { Typography } from '@appwrite.io/pink-svelte';
16+
import { isFreePlan } from '$lib/helpers/billing';
1617
1718
const backupRestoreItems: {
1819
archives: Map<string, BackupArchive>;
@@ -125,7 +126,7 @@
125126
126127
onMount(() => {
127128
// fast path: don't subscribe if org is on a free plan or is self-hosted.
128-
if (isSelfHosted || (isCloud && $organization?.billingPlan === BillingPlan.FREE)) return;
129+
if (isSelfHosted || (isCloud && isFreePlan($organization?.billingPlan))) return;
129130
130131
return realtime.forProject(page.params.region, 'console', (response) => {
131132
if (!response.channels.includes(`projects.${getProjectId()}`)) return;

src/lib/components/billing/alerts/limitReached.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
import { Click, trackEvent } from '$lib/actions/analytics';
55
import { BillingPlan } from '$lib/constants';
66
import { Button } from '$lib/elements/forms';
7+
import { isFreePlan } from '$lib/helpers/billing';
78
import { HeaderAlert } from '$lib/layout';
89
import { hideBillingHeaderRoutes, readOnly, tierToPlan, upgradeURL } from '$lib/stores/billing';
910
import { organization } from '$lib/stores/organization';
1011
</script>
1112

12-
{#if $organization?.$id && $organization?.billingPlan === BillingPlan.FREE && $readOnly && !hideBillingHeaderRoutes.includes(page.url.pathname)}
13+
{#if $organization?.$id && isFreePlan($organization?.billingPlan) && $readOnly && !hideBillingHeaderRoutes.includes(page.url.pathname)}
1314
<HeaderAlert
1415
type="error"
1516
title={`${$organization.name} usage has reached the ${tierToPlan($organization.billingPlan).name} plan limit`}>

src/lib/components/billing/alerts/newDevUpgradePro.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import { isSmallViewport } from '$lib/stores/viewport';
1111
import { Layout, Typography } from '@appwrite.io/pink-svelte';
1212
import { resolvedProfile } from '$lib/profiles/index.svelte';
13+
import { isFreePlan } from '$lib/helpers/billing';
1314
1415
let show = true;
1516
@@ -24,7 +25,7 @@
2425
}
2526
</script>
2627

27-
{#if show && $organization?.$id && $organization?.billingPlan === BillingPlan.FREE && !page.url.pathname.includes(base + '/account')}
28+
{#if show && $organization?.$id && isFreePlan($organization?.billingPlan) && !page.url.pathname.includes(base + '/account')}
2829
<GradientBanner on:close={handleClose}>
2930
<Layout.Stack
3031
gap="m"

src/lib/components/billing/usageRates.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import { abbreviateNumber, formatCurrency, isWithinSafeRange } from '$lib/helpers/numbers';
88
import { BillingPlan } from '$lib/constants';
99
import { Table, Typography } from '@appwrite.io/pink-svelte';
10+
import { isFreePlan } from '$lib/helpers/billing';
1011
1112
export let show = false;
1213
export let org: Organization;
@@ -17,7 +18,7 @@
1718
? new Date(new Date().getFullYear(), new Date().getMonth() + 1, 1).toString()
1819
: org?.billingNextInvoiceDate;
1920
20-
$: isFree = org.billingPlan === BillingPlan.FREE;
21+
$: isFree = isFreePlan(org.billingPlan);
2122
2223
// equal or above means unlimited!
2324
const getCorrectSeatsCountValue = (count: number): string | number => {

src/lib/components/roles/upgrade.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
import { BillingPlan } from '$lib/constants';
77
import Button from '$lib/elements/forms/button.svelte';
88
import { Badge, Layout, Link, Typography } from '@appwrite.io/pink-svelte';
9+
import { isFreePlan } from '$lib/helpers/billing';
910
</script>
1011

1112
<Base>
1213
<Layout.Stack gap="s">
1314
{#if isCloud}
14-
{#if $organization?.billingPlan !== BillingPlan.FREE}
15+
{#if !isFreePlan($organization?.billingPlan)}
1516
<Typography.Text variant="m-600">Roles</Typography.Text>
1617
<Typography.Text>Owner, Developer, Editor, Analyst and Billing.</Typography.Text>
1718
<Typography.Text>

src/lib/helpers/billing.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { BillingPlan } from '@appwrite.io/console';
2+
3+
export function isFreePlan(plan: BillingPlan | string): boolean {
4+
switch (plan) {
5+
case BillingPlan.Imaginebasic:
6+
case BillingPlan.Tier0:
7+
return true;
8+
default:
9+
return false;
10+
}
11+
}

src/lib/layout/containerButton.svelte

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<script lang="ts">
22
import { BillingPlan } from '$lib/constants';
33
import { Button } from '$lib/elements/forms';
4+
import { isFreePlan } from '$lib/helpers/billing';
45
import { tierToPlan } from '$lib/stores/billing';
56
import { organization } from '$lib/stores/organization';
67
import { Tooltip } from '@appwrite.io/pink-svelte';
78
89
export let title: string;
9-
export let tooltipContent =
10-
$organization?.billingPlan === BillingPlan.FREE
11-
? `Upgrade to add more ${title.toLocaleLowerCase()}`
12-
: `You've reached the ${title.toLocaleLowerCase()} limit for the ${
13-
tierToPlan($organization?.billingPlan)?.name
14-
} plan`;
10+
export let tooltipContent = isFreePlan($organization?.billingPlan)
11+
? `Upgrade to add more ${title.toLocaleLowerCase()}`
12+
: `You've reached the ${title.toLocaleLowerCase()} limit for the ${
13+
tierToPlan($organization?.billingPlan)?.name
14+
} plan`;
1515
export let disabled: boolean;
1616
export let buttonText: string;
1717
export let buttonMethod: () => void | Promise<void> = () => {};

src/lib/layout/containerHeader.svelte

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import { ContainerButton } from '.';
2222
import { goto } from '$app/navigation';
2323
import { Layout, Typography } from '@appwrite.io/pink-svelte';
24+
import { isFreePlan } from '$lib/helpers/billing';
2425
2526
export let title: string;
2627
export let serviceId = title.toLocaleLowerCase() as PlanServices;
@@ -68,7 +69,7 @@
6869
// these can be organization level limitations as well.
6970
// we need to migrate this sometime later, but soon!
7071
$: hasProjectLimitation =
71-
checkForProjectLimitation(serviceId) && $organization?.billingPlan === BillingPlan.FREE;
72+
checkForProjectLimitation(serviceId) && isFreePlan($organization?.billingPlan);
7273
$: hasUsageFees = hasProjectLimitation
7374
? checkForUsageFees($organization?.billingPlan, serviceId)
7475
: false;
@@ -99,7 +100,7 @@
99100

100101
{#if services.length}
101102
<slot name="alert" {limit} {tier} {title} {upgradeMethod} {hasUsageFees} {services}>
102-
{#if $organization?.billingPlan !== BillingPlan.FREE && hasUsageFees}
103+
{#if !isFreePlan($organization?.billingPlan) && hasUsageFees}
103104
<Alert.Inline status="info">
104105
<span class="text">
105106
You've reached the {services} limit for the {tier} plan.
@@ -149,7 +150,7 @@
149150
<p class="text">
150151
You are limited to {limit}
151152
{title.toLocaleLowerCase()} per project on the {tier} plan.
152-
{#if $organization?.billingPlan === BillingPlan.FREE}<Link
153+
{#if isFreePlan($organization?.billingPlan)}<Link
153154
href={$upgradeURL}
154155
event="organization_upgrade"
155156
eventData={{ from: 'button', source: 'resource_limit_tag' }}
@@ -169,7 +170,7 @@
169170
<p class="text">
170171
You are limited to {limit}
171172
{title.toLocaleLowerCase()} per organization on the {tier} plan.
172-
{#if $organization?.billingPlan === BillingPlan.FREE}
173+
{#if isFreePlan($organization?.billingPlan)}
173174
<Link href={$upgradeURL}>Upgrade</Link>
174175
for additional {title.toLocaleLowerCase()}.
175176
{/if}

0 commit comments

Comments
 (0)