Skip to content

Commit

Permalink
Merge pull request #1570 from appwrite/fix-use-plan-features-instead-…
Browse files Browse the repository at this point in the history
…of-tier-name

Check features based on plan details instead of plan name
  • Loading branch information
stnguyen90 authored Dec 22, 2024
2 parents 0c084db + 855bf18 commit 4145174
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 35 deletions.
5 changes: 5 additions & 0 deletions src/lib/sdk/billing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,11 @@ export type Plan = {
isAvailable: boolean;
selfService: boolean;
premiumSupport: boolean;
budgeting: boolean;
supportsMockNumbers: boolean;
backupsEnabled: boolean;
backupPolicies: number;
emailBranding: boolean;
};

export type PlansInfo = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { Button, Form, FormList, InputNumber, InputSwitch } from '$lib/elements/forms';
import { showUsageRatesModal, upgradeURL } from '$lib/stores/billing';
import { addNotification } from '$lib/stores/notifications';
import { organization } from '$lib/stores/organization';
import { organization, currentPlan } from '$lib/stores/organization';
import { sdk } from '$lib/stores/sdk';
import { onMount } from 'svelte';
Expand Down Expand Up @@ -59,7 +59,7 @@
class="link">Learn more about usage rates.</button>
</p>
<svelte:fragment slot="aside">
{#if $organization?.billingPlan === BillingPlan.FREE}
{#if !$currentPlan.budgeting}
<Alert type="info">
<svelte:fragment slot="title">
Budget caps are a Pro plan feature
Expand Down
6 changes: 5 additions & 1 deletion src/routes/(console)/project-[project]/+layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import { failedInvoice } from '$lib/stores/billing';
import { isCloud } from '$lib/system';
import type { Organization } from '$lib/stores/organization';
import { defaultRoles, defaultScopes } from '$lib/constants';
import type { Plan } from '$lib/sdk/billing';

export const load: LayoutLoad = async ({ params, depends }) => {
depends(Dependencies.PROJECT);
let currentPlan: Plan = null;

try {
const project = await sdk.forConsole.projects.get(params.project);
Expand All @@ -27,6 +29,7 @@ export const load: LayoutLoad = async ({ params, depends }) => {
let roles = isCloud ? [] : defaultRoles;
let scopes = isCloud ? [] : defaultScopes;
if (isCloud) {
currentPlan = await sdk.forConsole.billing.getPlan(project.teamId);
const res = await sdk.forConsole.billing.getRoles(project.teamId);
roles = res.roles;
scopes = res.scopes;
Expand All @@ -39,7 +42,8 @@ export const load: LayoutLoad = async ({ params, depends }) => {
project,
organization,
roles,
scopes
scopes,
currentPlan
};
} catch (e) {
error(e.code, e.message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
import { addNotification } from '$lib/stores/notifications';
import { invalidate } from '$app/navigation';
import { Dependencies } from '$lib/constants';
import { organization } from '$lib/stores/organization';
import { BillingPlan } from '$lib/constants';
import { currentPlan } from '$lib/stores/organization';
import { isCloud, isSelfHosted } from '$lib/system';
import MockNumbersLight from './mock-numbers-light.png';
import MockNumbersDark from './mock-numbers-dark.png';
Expand All @@ -27,7 +26,7 @@
$: isSubmitDisabled = JSON.stringify(numbers) === JSON.stringify(initialNumbers);
let isComponentDisabled: boolean =
isSelfHosted || (isCloud && $organization?.billingPlan === BillingPlan.FREE);
isSelfHosted || (isCloud && !$currentPlan.supportsMockNumbers);
let emptyStateTitle: string = isSelfHosted
? 'Available on Appwrite Cloud'
: 'Upgrade to add mock phone numbers';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@
// import { baseEmailTemplate, baseSmsTemplate, emailTemplate, smsTemplate } from './store';
import { baseEmailTemplate, emailTemplate } from './store';
import { Button } from '$lib/elements/forms';
import { organization } from '$lib/stores/organization';
import { BillingPlan } from '$lib/constants';
import { currentPlan } from '$lib/stores/organization';
import EmailSignature from './emailSignature.svelte';
import { isCloud } from '$lib/system';
import type {
Expand Down Expand Up @@ -268,7 +267,7 @@
</Collapsible>
</svelte:fragment>
</CardGrid>-->
{#if isCloud && $organization?.billingPlan === BillingPlan.FREE}
{#if isCloud && $currentPlan.emailBranding}
<EmailSignature />
{/if}
</Container>
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import { addNotification, dismissAllNotifications } from '$lib/stores/notifications';
import { sdk } from '$lib/stores/sdk';
import { invalidate } from '$app/navigation';
import { BillingPlan, Dependencies } from '$lib/constants';
import { Dependencies } from '$lib/constants';
import { isCloud, isSelfHosted } from '$lib/system';
import { organization } from '$lib/stores/organization';
import { currentPlan } from '$lib/stores/organization';
import { onMount } from 'svelte';
import { feedback } from '$lib/stores/feedback';
import { cronExpression, type UserBackupPolicy } from '$lib/helpers/backups';
Expand All @@ -24,19 +24,10 @@
let policyCreateError: string;
let totalPolicies: UserBackupPolicy[] = [];
let isDisabled = isSelfHosted || (isCloud && $organization?.billingPlan === BillingPlan.FREE);
let isDisabled = isSelfHosted || (isCloud && !$currentPlan.backupsEnabled);
export let data: PageData;
$: hasPolicyCreationLimitations = () => {
// allow when on Pro and no policy exists
if ($organization?.billingPlan === BillingPlan.PRO) {
return data.policies.total > 0;
} else if ($organization?.billingPlan === BillingPlan.SCALE) {
return false;
}
};
const showFeedbackNotification = () => {
let counter = localStorage.getItem('createBackupsCounter');
const parsedCounter = counter ? parseInt(counter, 10) : 0;
Expand Down Expand Up @@ -184,7 +175,8 @@
buttonEvent="create_backup"
buttonType="secondary"
buttonDisabled={isDisabled}
hasLimitations={hasPolicyCreationLimitations()}
maxPolicies={$currentPlan.backupPolicies}
policiesCreated={data.policies.total}
buttonMethod={() => {
$showCreatePolicy = true;
trackEvent('click_policy_create');
Expand All @@ -202,7 +194,6 @@
buttonText="Manual backup"
buttonEvent="create_backup"
buttonType="secondary"
hasLimitations={false}
buttonDisabled={isDisabled}
buttonMethod={() => {
$showCreateBackup = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
import { Pill } from '$lib/elements';
import { wizard } from '$lib/stores/wizard';
import SupportWizard from '$routes/(console)/supportWizard.svelte';
import { BillingPlan } from '$lib/constants';
import { organization } from '$lib/stores/organization';
export let isFlex = true;
export let title: string;
export let buttonText: string = null;
export let hasLimitations: boolean = true;
export let policiesCreated: number = 0;
export let maxPolicies: number = 0;
export let buttonMethod: () => void = null;
export let buttonEvent: string = buttonText?.toLocaleLowerCase();
export let buttonDisabled = false;
Expand All @@ -27,16 +26,16 @@
<div class="u-flex u-cross-child-center u-cross-center u-gap-12">
<div class="body-text-1 u-bold backups-title">{title}</div>

{#if hasLimitations && $organization.billingPlan === BillingPlan.PRO}
{#if title === 'Policies' && policiesCreated >= maxPolicies}
<div style="height: 40px; padding-block-start: 4px">
<DropList bind:show={showDropdown} width="16">
<Pill button on:click={() => (showDropdown = true)}>
<span class="icon-info" />1/1 created
<span class="icon-info" />{policiesCreated}/{maxPolicies} created
</Pill>
<svelte:fragment slot="list">
<slot name="tooltip">
<span>
You are limited to one policy on Pro plan.
You are limited to {maxPolicies} policy on your plan.
<button
class="u-underline"
on:click={() => {
Expand All @@ -52,14 +51,10 @@
{/if}
</div>

{#if !hasLimitations}
{#if title === 'Backups' || policiesCreated < maxPolicies}
<Button
event={buttonEvent}
on:click={hasLimitations
? () => {
showDropdown = true;
}
: buttonMethod}
on:click={buttonMethod}
disabled={buttonDisabled}
text={buttonType === 'text'}
secondary={buttonType === 'secondary'}>
Expand Down

0 comments on commit 4145174

Please sign in to comment.