fix(editor): Trial banner does not disappear after sign out (no-changelog) (#6930)

to test in staging use version
`PR-6930-ado-990-trial-banner-does-not-disappear-after-sign-out`

<img width="875" alt="image"
src="https://github.com/n8n-io/n8n/assets/16496553/dfffe60f-bec3-4c48-bd9c-5990c68afa52">
This commit is contained in:
Ricardo Espinoza
2023-08-17 07:57:40 -04:00
committed by GitHub
parent ad15d3eae9
commit d3f01270c7
10 changed files with 181 additions and 37 deletions

View File

@@ -6,6 +6,7 @@ import { useSettingsStore } from '@/stores/settings.store';
import { useUsersStore } from '@/stores/users.store';
import { getCurrentPlan, getCurrentUsage } from '@/api/cloudPlans';
import { DateTime } from 'luxon';
import { CLOUD_TRIAL_CHECK_INTERVAL } from '@/constants';
const DEFAULT_STATE: CloudPlanState = {
data: null,
@@ -28,6 +29,11 @@ export const useCloudPlanStore = defineStore('cloudPlan', () => {
state.usage = data;
};
const reset = () => {
state.data = null;
state.usage = null;
};
const userIsTrialing = computed(() => state.data?.metadata?.group === 'trial');
const currentPlanData = computed(() => state.data);
@@ -89,6 +95,27 @@ export const useCloudPlanStore = defineStore('cloudPlan', () => {
return Math.ceil(differenceInDays);
});
const startPollingInstanceUsageData = () => {
const interval = setInterval(async () => {
try {
await getInstanceCurrentUsage();
if (trialExpired.value || allExecutionsUsed.value) {
clearTimeout(interval);
return;
}
} catch {}
}, CLOUD_TRIAL_CHECK_INTERVAL);
};
const checkForCloudPlanData = async (): Promise<void> => {
try {
await getOwnerCurrentPlan();
if (!userIsTrialing.value) return;
await getInstanceCurrentUsage();
startPollingInstanceUsageData();
} catch {}
};
return {
state,
getOwnerCurrentPlan,
@@ -100,5 +127,7 @@ export const useCloudPlanStore = defineStore('cloudPlan', () => {
currentUsageData,
trialExpired,
allExecutionsUsed,
reset,
checkForCloudPlanData,
};
});

View File

@@ -49,8 +49,8 @@ import { defineStore } from 'pinia';
import { useRootStore } from './n8nRoot.store';
import { getCurlToJson } from '@/api/curlHelper';
import { useWorkflowsStore } from './workflows.store';
import { useSettingsStore } from './settings.store';
import { useCloudPlanStore } from './cloudPlan.store';
import { useSettingsStore } from '@/stores/settings.store';
import { useCloudPlanStore } from '@/stores/cloudPlan.store';
import type { BaseTextKey } from '@/plugins/i18n';
import { i18n as locale } from '@/plugins/i18n';
import { useTelemetryStore } from '@/stores/telemetry.store';
@@ -562,5 +562,23 @@ export const useUIStore = defineStore(STORES.UI, {
updateBannersHeight(newHeight: number): void {
this.bannersHeight = newHeight;
},
async initBanners(): Promise<void> {
const cloudPlanStore = useCloudPlanStore();
if (cloudPlanStore.userIsTrialing) {
await this.dismissBanner('V1', 'temporary');
if (cloudPlanStore.trialExpired) {
this.showBanner('TRIAL_OVER');
} else {
this.showBanner('TRIAL');
}
}
},
async dismissAllBanners() {
return Promise.all([
this.dismissBanner('TRIAL', 'temporary'),
this.dismissBanner('TRIAL_OVER', 'temporary'),
this.dismissBanner('V1', 'temporary'),
]);
},
},
});

View File

@@ -37,6 +37,7 @@ import { useRootStore } from './n8nRoot.store';
import { usePostHog } from './posthog.store';
import { useSettingsStore } from './settings.store';
import { useUIStore } from './ui.store';
import { useCloudPlanStore } from './cloudPlan.store';
const isDefaultUser = (user: IUserResponse | null) =>
Boolean(user && user.isPending && user.globalRole && user.globalRole.name === ROLE.Owner);
@@ -182,7 +183,9 @@ export const useUsersStore = defineStore(STORES.USERS, {
const rootStore = useRootStore();
await logout(rootStore.getRestApiContext);
this.currentUserId = null;
useCloudPlanStore().reset();
usePostHog().reset();
await useUIStore().dismissAllBanners();
},
async createOwner(params: {
firstName: string;