From bc7a5eeb5e0c5e1bae3b80958d783d18aab91d87 Mon Sep 17 00:00:00 2001 From: Darshan Date: Tue, 15 Apr 2025 15:07:03 +0530 Subject: [PATCH 1/3] fix: cached/incorrect regions. --- .../(console)/organization-[organization]/+page.svelte | 3 +-- src/routes/(console)/organization-[organization]/store.ts | 7 +++---- .../organization-[organization]/wizard/step1.svelte | 8 ++++---- .../organization-[organization]/wizard/step2.svelte | 2 +- .../(console)/project-[region]-[project]/+layout.ts | 7 +++---- 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/routes/(console)/organization-[organization]/+page.svelte b/src/routes/(console)/organization-[organization]/+page.svelte index 55e8fa1c6..1e678f51c 100644 --- a/src/routes/(console)/organization-[organization]/+page.svelte +++ b/src/routes/(console)/organization-[organization]/+page.svelte @@ -29,10 +29,9 @@ import { openImportWizard } from '../project-[region]-[project]/settings/migrations/(import)'; import { readOnly } from '$lib/stores/billing'; import { onMount } from 'svelte'; - import { organization } from '$lib/stores/organization'; import { canWriteProjects } from '$lib/stores/roles'; import { checkPricingRefAndRedirect } from '$lib/helpers/pricingRedirect'; - import { regions as regionsStore } from '$routes/(console)/organization-[organization]/store'; + import { organization, regions as regionsStore } from '$lib/stores/organization'; export let data; diff --git a/src/routes/(console)/organization-[organization]/store.ts b/src/routes/(console)/organization-[organization]/store.ts index aae6830f4..56ea1a018 100644 --- a/src/routes/(console)/organization-[organization]/store.ts +++ b/src/routes/(console)/organization-[organization]/store.ts @@ -1,10 +1,9 @@ import { page } from '$app/stores'; -import type { Models } from '@appwrite.io/console'; -import { derived, writable } from 'svelte/store'; -import type { RegionList } from '$lib/sdk/billing'; +import { derived } from 'svelte/store'; import { sdk } from '$lib/stores/sdk'; +import type { Models } from '@appwrite.io/console'; +import { regions } from '$lib/stores/organization'; -export const regions = writable(undefined); export const regionFlagUrls = derived(regions, ($regions) => { if (!$regions?.regions?.length) return []; diff --git a/src/routes/(console)/organization-[organization]/wizard/step1.svelte b/src/routes/(console)/organization-[organization]/wizard/step1.svelte index a448331fb..f76557a35 100644 --- a/src/routes/(console)/organization-[organization]/wizard/step1.svelte +++ b/src/routes/(console)/organization-[organization]/wizard/step1.svelte @@ -3,15 +3,15 @@ import { Pill } from '$lib/elements'; import { InputText, FormList } from '$lib/elements/forms'; import { WizardStep } from '$lib/layout'; - import { sdk } from '$lib/stores/sdk'; import { createProject } from './store'; - import { regionFlagUrls, regions } from '../store'; - import { organization } from '$lib/stores/organization'; + import { regionFlagUrls } from '../store'; + import { organization, regions } from '$lib/stores/organization'; + import { loadAvailableRegions } from '$routes/(console)/regions'; let showCustomId = false; if (!$regions?.regions) { - sdk.forConsole.billing.listRegions($organization.$id).then(regions.set); + loadAvailableRegions($organization.$id); } diff --git a/src/routes/(console)/organization-[organization]/wizard/step2.svelte b/src/routes/(console)/organization-[organization]/wizard/step2.svelte index 38adb71f3..362380752 100644 --- a/src/routes/(console)/organization-[organization]/wizard/step2.svelte +++ b/src/routes/(console)/organization-[organization]/wizard/step2.svelte @@ -9,7 +9,7 @@ import { addNotification } from '$lib/stores/notifications'; import type { Models } from '@appwrite.io/console'; import { page } from '$app/stores'; - import { regions } from '$routes/(console)/organization-[organization]/store'; + import { regions } from '$lib/stores/organization'; let prefs: Models.Preferences; diff --git a/src/routes/(console)/project-[region]-[project]/+layout.ts b/src/routes/(console)/project-[region]-[project]/+layout.ts index 3e74290d1..4aaa4d636 100644 --- a/src/routes/(console)/project-[region]-[project]/+layout.ts +++ b/src/routes/(console)/project-[region]-[project]/+layout.ts @@ -5,7 +5,6 @@ import type { LayoutLoad } from './$types'; import { preferences } from '$lib/stores/preferences'; 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'; import { get } from 'svelte/store'; @@ -20,17 +19,17 @@ export const load: LayoutLoad = async ({ params, depends }) => { try { const project = await sdk.forConsole.projects.get(params.project); const [organization, prefs, _] = await Promise.all([ - sdk.forConsole.teams.get(project.teamId) as Promise, + sdk.forConsole.teams.get(project.teamId), sdk.forConsole.account.getPrefs(), loadAvailableRegions(project.teamId) ]); if (prefs?.organization !== project.teamId) { - sdk.forConsole.account.updatePrefs({ + await sdk.forConsole.account.updatePrefs({ ...prefs, organization: project.teamId }); } - preferences.loadTeamPrefs(project.teamId); + await preferences.loadTeamPrefs(project.teamId); let roles = isCloud ? [] : defaultRoles; let scopes = isCloud ? [] : defaultScopes; if (isCloud) { From 78d55b5a641315d3b2d9e75c568379af680cf326 Mon Sep 17 00:00:00 2001 From: Darshan Date: Tue, 15 Apr 2025 15:11:16 +0530 Subject: [PATCH 2/3] fix: type check. --- src/routes/(console)/project-[region]-[project]/+layout.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/routes/(console)/project-[region]-[project]/+layout.ts b/src/routes/(console)/project-[region]-[project]/+layout.ts index 4aaa4d636..aab8ce84c 100644 --- a/src/routes/(console)/project-[region]-[project]/+layout.ts +++ b/src/routes/(console)/project-[region]-[project]/+layout.ts @@ -11,6 +11,7 @@ import { get } from 'svelte/store'; import { headerAlert } from '$lib/stores/headerAlert'; import PaymentFailed from '$lib/components/billing/alerts/paymentFailed.svelte'; import { loadAvailableRegions } from '$routes/(console)/regions'; +import type { Organization } from '$lib/stores/organization'; export const load: LayoutLoad = async ({ params, depends }) => { depends(Dependencies.PROJECT); @@ -19,7 +20,7 @@ export const load: LayoutLoad = async ({ params, depends }) => { try { const project = await sdk.forConsole.projects.get(params.project); const [organization, prefs, _] = await Promise.all([ - sdk.forConsole.teams.get(project.teamId), + sdk.forConsole.teams.get(project.teamId) as Promise, sdk.forConsole.account.getPrefs(), loadAvailableRegions(project.teamId) ]); From 7658ede005f3e8c48efbaf3bc7defa15622ca553 Mon Sep 17 00:00:00 2001 From: Darshan Date: Tue, 15 Apr 2025 15:37:45 +0530 Subject: [PATCH 3/3] address comment. --- src/routes/(console)/project-[region]-[project]/+layout.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/(console)/project-[region]-[project]/+layout.ts b/src/routes/(console)/project-[region]-[project]/+layout.ts index aab8ce84c..f90abed15 100644 --- a/src/routes/(console)/project-[region]-[project]/+layout.ts +++ b/src/routes/(console)/project-[region]-[project]/+layout.ts @@ -25,7 +25,7 @@ export const load: LayoutLoad = async ({ params, depends }) => { loadAvailableRegions(project.teamId) ]); if (prefs?.organization !== project.teamId) { - await sdk.forConsole.account.updatePrefs({ + sdk.forConsole.account.updatePrefs({ ...prefs, organization: project.teamId });