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:
@@ -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,
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user