From c36dd1d0b0d9fa4d117aea84351bcd405e7403b1 Mon Sep 17 00:00:00 2001 From: Darshan Date: Mon, 30 Jun 2025 10:48:25 +0530 Subject: [PATCH] fix: invalidation issue causing null organization on project's first creation. --- .../billing/selectPaymentMethod.svelte | 2 +- src/lib/components/breadcrumbs.svelte | 3 ++- src/routes/(console)/+layout.svelte | 22 +++++++++++-------- .../(console)/create-organization/+page.ts | 3 ++- .../create-organization/+page.svelte | 8 +++++-- src/routes/+layout.ts | 1 + 6 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/lib/components/billing/selectPaymentMethod.svelte b/src/lib/components/billing/selectPaymentMethod.svelte index d036db8ee..30e5ea254 100644 --- a/src/lib/components/billing/selectPaymentMethod.svelte +++ b/src/lib/components/billing/selectPaymentMethod.svelte @@ -31,7 +31,7 @@ await Promise.all([ invalidate(Dependencies.UPGRADE_PLAN), - invalidate(Dependencies.CREATE_ORGANIZATION) + invalidate(Dependencies.ORGANIZATION) ]); } diff --git a/src/lib/components/breadcrumbs.svelte b/src/lib/components/breadcrumbs.svelte index cbe0799c3..e29c4c8d0 100644 --- a/src/lib/components/breadcrumbs.svelte +++ b/src/lib/components/breadcrumbs.svelte @@ -101,7 +101,8 @@ async function createProjectsBottomSheet(organization: Organization): Promise { isLoadingProjects = true; - loadedProjects = await projects; + // null on non-org/project path like `onboarding`. + loadedProjects = (await projects) ?? loadedProjects; isLoadingProjects = false; const createProjectItem = { diff --git a/src/routes/(console)/+layout.svelte b/src/routes/(console)/+layout.svelte index 4a6d3ac3b..452847d49 100644 --- a/src/routes/(console)/+layout.svelte +++ b/src/routes/(console)/+layout.svelte @@ -316,15 +316,19 @@ $: checkForUsageLimits($organization); - $: projects = sdk.forConsole.projects.list([ - Query.equal( - 'teamId', - // id from page params ?? id from store ?? id from preferences - page.params.organization ?? currentOrganizationId ?? data.currentOrgId - ), - Query.limit(5), - Query.orderDesc('$updatedAt') - ]); + $: isOnOnboarding = page.route?.id?.includes('/(console)/onboarding'); + + $: projects = isOnOnboarding + ? null + : sdk.forConsole.projects.list([ + Query.equal( + 'teamId', + // id from page params ?? id from store ?? id from preferences + page.params.organization ?? currentOrganizationId ?? data.currentOrgId + ), + Query.limit(5), + Query.orderDesc('$updatedAt') + ]); $: if ($requestedMigration) { openMigrationWizard(); diff --git a/src/routes/(console)/create-organization/+page.ts b/src/routes/(console)/create-organization/+page.ts index f6f9eeb7f..9aba3aefd 100644 --- a/src/routes/(console)/create-organization/+page.ts +++ b/src/routes/(console)/create-organization/+page.ts @@ -5,8 +5,9 @@ import type { Coupon } from '$lib/sdk/billing'; import type { Organization } from '$lib/stores/organization'; export const load: PageLoad = async ({ url, parent, depends }) => { - depends(Dependencies.CREATE_ORGANIZATION); const { organizations } = await parent(); + depends(Dependencies.CREATE_ORGANIZATION); + const [coupon, paymentMethods] = await Promise.all([ getCoupon(url), sdk.forConsole.billing.listPaymentMethods() diff --git a/src/routes/(console)/onboarding/create-organization/+page.svelte b/src/routes/(console)/onboarding/create-organization/+page.svelte index 0118c0e3c..73524af47 100644 --- a/src/routes/(console)/onboarding/create-organization/+page.svelte +++ b/src/routes/(console)/onboarding/create-organization/+page.svelte @@ -2,14 +2,14 @@ import { isCloud } from '$lib/system'; import { sdk } from '$lib/stores/sdk'; import { ID } from '@appwrite.io/console'; - import { BillingPlan } from '$lib/constants'; + import { BillingPlan, Dependencies } from '$lib/constants'; import { tierToPlan } from '$lib/stores/billing'; import { addNotification } from '$lib/stores/notifications'; import { loadAvailableRegions } from '$routes/(console)/regions'; import { Submit, trackError, trackEvent } from '$lib/actions/analytics'; import { Button, Card, Layout, Input, Typography, Spinner } from '@appwrite.io/pink-svelte'; import { Form } from '$lib/elements/forms/index.js'; - import { goto } from '$app/navigation'; + import { goto, invalidate } from '$app/navigation'; import { base } from '$app/paths'; let isLoading = false; @@ -47,6 +47,10 @@ if (organization) { loadAvailableRegions(organization?.$id).then(); await goto(`${base}/organization-${organization.$id}`); + + // fixes an edge case where + // the org is not available for some reason! + await invalidate(Dependencies.CREATE_ORGANIZATION); } isLoading = false; } diff --git a/src/routes/+layout.ts b/src/routes/+layout.ts index 78d86d2e4..21fe42dde 100644 --- a/src/routes/+layout.ts +++ b/src/routes/+layout.ts @@ -16,6 +16,7 @@ export const ssr = false; export const load: LayoutLoad = async ({ depends, url, route }) => { depends(Dependencies.ACCOUNT); + depends(Dependencies.CREATE_ORGANIZATION); const [account, error] = (await sdk.forConsole.account .get()