Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/lib/stores/billing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,24 @@ export function checkForTrialEnding(org: Organization) {
}
}

export function checkForUsageLimit(org: Organization) {
export async function checkForUsageLimit(org: Organization) {
if (!org?.billingLimits) {
readOnly.set(false);
return;
}
const { bandwidth, documents, executions, storage, users } = org.billingLimits;
const { bandwidth, documents, executions, storage, users } = org?.billingLimits ?? {};
const members = await sdk.forConsole.teams.listMemberships(org.$id);
const plan = get(plansInfo).plans.find((plan) => plan.$id === org.billingPlan);
const membersOverflow =
members?.total > plan.members ? members.total - (plan.members || members.total) : 0;

if (
bandwidth >= 100 ||
documents >= 100 ||
executions >= 100 ||
storage >= 100 ||
users >= 100
users >= 100 ||
membersOverflow > 0
) {
readOnly.set(true);
} else readOnly.set(false);
Expand Down
2 changes: 1 addition & 1 deletion src/routes/console/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@
calculateTrialDay(org);
checkForTrialEnding(org);
await paymentExpired(org);
checkForUsageLimit(org);
await checkForUsageLimit(org);
checkForMarkedForDeletion(org);
await checkPaymentAuthorizationRequired(org);
}
Expand Down
3 changes: 0 additions & 3 deletions src/routes/console/changeOrganizationTierCloud.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
wizard.hide();

trackEvent(Submit.OrganizationDowngrade, {
customId: !!$changeOrganizationTier.id,
plan: tierToPlan($changeOrganizationTier.billingPlan)?.name
});
} catch (e) {
Expand Down Expand Up @@ -144,7 +143,6 @@
});
}
trackEvent($isUpgrade ? Submit.OrganizationUpgrade : Submit.OrganizationDowngrade, {
customId: !!$changeOrganizationTier.id,
plan: tierToPlan($changeOrganizationTier.billingPlan)?.name
});
wizard.hide();
Expand All @@ -164,7 +162,6 @@

onDestroy(() => {
$changeOrganizationTier = {
id: null,
billingPlan: 'tier-1',
paymentMethodId: null,
collaborators: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@
members: members.total > plan.members ? members.total - (plan.members || Infinity) : 0
};
if (
$changeOrganizationTier.limitOverflow.bandwidth > 0 ||
$changeOrganizationTier.limitOverflow.storage > 0 ||
$changeOrganizationTier.limitOverflow.users > 0 ||
$changeOrganizationTier.limitOverflow.executions > 0 ||
$changeOrganizationTier.limitOverflow.members > 0
($changeOrganizationTier.limitOverflow.bandwidth > 0 ||
$changeOrganizationTier.limitOverflow.storage > 0 ||
$changeOrganizationTier.limitOverflow.users > 0 ||
$changeOrganizationTier.limitOverflow.executions > 0 ||
$changeOrganizationTier.limitOverflow.members > 0) &&
$changeOrganizationTier.billingPlan === 'tier-0'
) {
$changeOrganizationTier.isOverLimit = true;
$changeTierSteps = updateStepStatus($changeTierSteps, 5, false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<script lang="ts">
import { Box, CreditCardBrandImage } from '$lib/components';
import { CouponInput } from '$lib/components/billing';
import { Pill } from '$lib/elements';
import { FormList, InputTextarea } from '$lib/elements/forms';
import { toLocaleDate } from '$lib/helpers/date';
import { WizardStep } from '$lib/layout';
Expand Down Expand Up @@ -72,9 +71,6 @@
<p class="body-text-1 u-bold">Organization name</p>
<div class="u-flex u-gap-8 u-cross-center u-margin-block-start-8">
<p class="text">{$organization.name}</p>
{#if $changeOrganizationTier?.id}
<Pill>{$changeOrganizationTier.id}</Pill>
{/if}
</div>

{#if $changeOrganizationTier.billingPlan !== 'tier-0'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
import { changeOrganizationTier } from './store';
import { sdk } from '$lib/stores/sdk';
import { user } from '$lib/stores/user';
import { organization } from '$lib/stores/organization';

const plan = $plansInfo.plans.find((p) => p.$id === $changeOrganizationTier.billingPlan);

let email: string;

onMount(async () => {
const members = await sdk.forConsole.teams.listMemberships($changeOrganizationTier.id);
const members = await sdk.forConsole.teams.listMemberships($organization.$id);
if (members.total) {
$changeOrganizationTier.collaborators = members.memberships
.map((m) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@
{#if currentTier === 'tier-0'}
<Button
text
external
href="https://appwrite.io/docs/advanced/platform/starter#reaching-resource-limits">
Learn more
</Button>
{:else if currentTier === 'tier-1'}
<Button
text
external
href="https://appwrite.io/docs/advanced/platform/pro#reaching-resource-limits">
Learn more
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export const isUpgrade = writable<boolean>(false);
export const changeOrganizationFinalAction = writable<string>('Start trial');

export const changeOrganizationTier = writable<{
id?: string;
billingPlan: Tier;
paymentMethodId: string;
billingAddressId: string;
Expand All @@ -25,7 +24,6 @@ export const changeOrganizationTier = writable<{
feedbackMessage?: string;
couponCode?: string;
}>({
id: null,
billingPlan: 'tier-1',
paymentMethodId: null,
collaborators: [],
Expand Down