diff --git a/packages/editor-ui/src/App.vue b/packages/editor-ui/src/App.vue index aab8297a9a427..925a50b2de912 100644 --- a/packages/editor-ui/src/App.vue +++ b/packages/editor-ui/src/App.vue @@ -144,8 +144,9 @@ export default defineComponent({ console.log(HIRING_BANNER); } }, - async checkForCloudPlanData() { - return this.cloudPlanStore.checkForCloudPlanData(); + async checkForCloudData() { + await this.cloudPlanStore.checkForCloudPlanData(); + await this.cloudPlanStore.fetchUserCloudAccount(); }, async initialize(): Promise { await this.initSettings(); @@ -237,7 +238,7 @@ export default defineComponent({ await this.authenticate(); await this.redirectIfNecessary(); void this.checkForNewVersions(); - await this.checkForCloudPlanData(); + await this.checkForCloudData(); void this.postAuthenticate(); this.loading = false; diff --git a/packages/editor-ui/src/stores/__tests__/ui.test.ts b/packages/editor-ui/src/stores/__tests__/ui.test.ts index 898f02000be22..91365a36d999c 100644 --- a/packages/editor-ui/src/stores/__tests__/ui.test.ts +++ b/packages/editor-ui/src/stores/__tests__/ui.test.ts @@ -123,7 +123,8 @@ describe('UI store', () => { .spyOn(cloudPlanApi, 'getCloudUserInfo') .mockResolvedValue(getUserCloudInfo(true)); setupOwnerAndCloudDeployment(); - await cloudPlanStore.getOwnerCurrentPlan(); + await cloudPlanStore.checkForCloudPlanData(); + await cloudPlanStore.fetchUserCloudAccount(); expect(fetchCloudSpy).toHaveBeenCalled(); expect(fetchUserCloudAccountSpy).toHaveBeenCalled(); expect(uiStore.bannerStack).toContain('TRIAL'); @@ -137,7 +138,8 @@ describe('UI store', () => { .spyOn(cloudPlanApi, 'getCloudUserInfo') .mockResolvedValue(getUserCloudInfo(true)); setupOwnerAndCloudDeployment(); - await cloudPlanStore.getOwnerCurrentPlan(); + await cloudPlanStore.checkForCloudPlanData(); + await cloudPlanStore.fetchUserCloudAccount(); expect(fetchCloudSpy).toHaveBeenCalled(); expect(fetchUserCloudAccountSpy).toHaveBeenCalled(); expect(uiStore.bannerStack).toContain('TRIAL_OVER'); @@ -151,7 +153,8 @@ describe('UI store', () => { .spyOn(cloudPlanApi, 'getCloudUserInfo') .mockResolvedValue(getUserCloudInfo(false)); setupOwnerAndCloudDeployment(); - await cloudPlanStore.getOwnerCurrentPlan(); + await cloudPlanStore.checkForCloudPlanData(); + await cloudPlanStore.fetchUserCloudAccount(); expect(fetchCloudSpy).toHaveBeenCalled(); expect(fetchUserCloudAccountSpy).toHaveBeenCalled(); expect(uiStore.bannerStack).toContain('TRIAL_OVER'); diff --git a/packages/editor-ui/src/stores/cloudPlan.store.ts b/packages/editor-ui/src/stores/cloudPlan.store.ts index f736aa8bba7a2..f6cdecdb39267 100644 --- a/packages/editor-ui/src/stores/cloudPlan.store.ts +++ b/packages/editor-ui/src/stores/cloudPlan.store.ts @@ -52,11 +52,27 @@ export const useCloudPlanStore = defineStore(STORES.CLOUD_PLAN, () => { return state.usage?.executions >= state.data?.monthlyExecutionsLimit; }); - const getOwnerCurrentPlan = async () => { + const hasCloudPlan = computed(() => { const cloudUserId = settingsStore.settings.n8nMetadata?.userId; - const hasCloudPlan = - usersStore.currentUser?.isOwner && settingsStore.isCloudDeployment && cloudUserId; - if (!hasCloudPlan) throw new Error('User does not have a cloud plan'); + return usersStore.currentUser?.isOwner && settingsStore.isCloudDeployment && cloudUserId; + }); + + const getUserCloudAccount = async () => { + if (!hasCloudPlan.value) throw new Error('User does not have a cloud plan'); + try { + if (useUsersStore().isInstanceOwner) { + await usersStore.fetchUserCloudAccount(); + if (!usersStore.currentUserCloudInfo?.confirmed) { + useUIStore().pushBannerToStack('EMAIL_CONFIRMATION'); + } + } + } catch (error) { + throw new Error(error); + } + }; + + const getOwnerCurrentPlan = async () => { + if (!hasCloudPlan.value) throw new Error('User does not have a cloud plan'); state.loadingPlan = true; let plan; try { @@ -71,13 +87,6 @@ export const useCloudPlanStore = defineStore(STORES.CLOUD_PLAN, () => { useUIStore().pushBannerToStack('TRIAL'); } } - - if (useUsersStore().isInstanceOwner) { - await usersStore.fetchUserCloudAccount(); - if (!usersStore.currentUserCloudInfo?.confirmed) { - useUIStore().pushBannerToStack('EMAIL_CONFIRMATION'); - } - } } catch (error) { state.loadingPlan = false; throw new Error(error); @@ -132,6 +141,12 @@ export const useCloudPlanStore = defineStore(STORES.CLOUD_PLAN, () => { } catch {} }; + const fetchUserCloudAccount = async () => { + try { + await getUserCloudAccount(); + } catch {} + }; + return { state, getOwnerCurrentPlan, @@ -145,5 +160,6 @@ export const useCloudPlanStore = defineStore(STORES.CLOUD_PLAN, () => { allExecutionsUsed, reset, checkForCloudPlanData, + fetchUserCloudAccount, }; });