diff --git a/src/routes/(console)/+layout.svelte b/src/routes/(console)/+layout.svelte index ea0830ac0c..5b3072210c 100644 --- a/src/routes/(console)/+layout.svelte +++ b/src/routes/(console)/+layout.svelte @@ -8,7 +8,7 @@ import { database, checkForDatabaseBackupPolicies } from '$lib/stores/database'; import { newOrgModal, organization } from '$lib/stores/organization'; import { wizard } from '$lib/stores/wizard'; - import { afterUpdate, onMount } from 'svelte'; + import { onMount } from 'svelte'; import { loading } from '$routes/store'; import { requestedMigration } from '../store'; import Create from './createOrganization.svelte'; @@ -280,10 +280,12 @@ } } - database.subscribe(async (database) => { - if (!database || !page.params.region || !page.params.project) return; - // the component checks `isCloud` internally. - await checkForDatabaseBackupPolicies(page.params.region, page.params.project, database); + onMount(() => { + return database.subscribe(async (database) => { + if (!database || !page.params.region || !page.params.project) return; + // the component checks `isCloud` internally. + await checkForDatabaseBackupPolicies(page.params.region, page.params.project, database); + }); }); let currentOrganizationId = null; @@ -293,18 +295,21 @@ if (isCloud) { currentOrganizationId = org.$id; checkForEnterpriseTrial(org); - await checkForUsageLimit(org); checkForMarkedForDeletion(org); - await checkForNewDevUpgradePro(org); - if (org?.billingPlanDetails.requiresPaymentMethod) { - await paymentExpired(org); - await checkPaymentAuthorizationRequired(org); + const billingChecks: Promise[] = [ + checkForUsageLimit(org), + checkForNewDevUpgradePro(org) + ]; + if (org?.billingPlanDetails.requiresPaymentMethod) { + billingChecks.push(paymentExpired(org), checkPaymentAuthorizationRequired(org)); if (org?.billingTrialDays) { calculateTrialDay(org); } } + + await Promise.all(billingChecks); $activeHeaderAlert = headerAlert.getExcluding('impersonation'); } } @@ -317,9 +322,7 @@ $registerSearchers(orgSearcher, projectsSearcher); - afterUpdate(() => { - $activeHeaderAlert = headerAlert.getExcluding('impersonation'); - }); + $: (void $headerAlert, ($activeHeaderAlert = headerAlert.getExcluding('impersonation'))); diff --git a/src/routes/(console)/+layout.ts b/src/routes/(console)/+layout.ts index f40123b438..b191a64364 100644 --- a/src/routes/(console)/+layout.ts +++ b/src/routes/(console)/+layout.ts @@ -3,7 +3,7 @@ import { isCloud } from '$lib/system'; import type { LayoutLoad } from './$types'; import type { Account } from '$lib/stores/user'; import { Dependencies } from '$lib/constants'; -import { Platform, Query, type Models } from '@appwrite.io/console'; +import { Platform, type Models } from '@appwrite.io/console'; import { makePlansMap } from '$lib/helpers/billing'; import { plansInfo as plansInfoStore } from '$lib/stores/billing'; import { normalizeConsoleVariables } from '$lib/helpers/domains'; @@ -54,7 +54,6 @@ export const load: LayoutLoad = async ({ depends, parent, url }) => { currentOrgId: undefined, organizations, consoleVariables, - allProjectsCount: 0, plansInfo: plansInfo ?? null, version: versionData?.version ?? null }; @@ -107,28 +106,6 @@ export const load: LayoutLoad = async ({ depends, parent, url }) => { preferences.organization ?? (organizations.teams.length > 0 ? organizations.teams[0].$id : undefined); - // Load projects for the current organization if one is selected - let projectsCount = 0; - if (currentOrgId) { - try { - projectsCount = ( - await sdk.forConsole.projects.list({ - queries: [ - Query.equal('teamId', currentOrgId), - Query.limit(1), - Query.select(['$id']) - ] - }) - ).total; - } catch (e) { - if (shouldRedirectToVerifyEmail(e)) { - redirect(303, verifyEmailUrl); - } - - projectsCount = 0; - } - } - // just in case! plansInfoStore.set(fallbackPlansInfoArray); @@ -139,7 +116,6 @@ export const load: LayoutLoad = async ({ depends, parent, url }) => { currentOrgId, organizations, consoleVariables, - allProjectsCount: projectsCount, plansInfo: fallbackPlansInfoArray, version: versionData?.version ?? null };