Skip to content

Commit

Permalink
remove redirectTodashboard method from cloudPlan.store.ts
Browse files Browse the repository at this point in the history
This helps consolidate all logic to redirect to owner to the cloud dashboard in one place, the uiStore.
  • Loading branch information
RicardoE105 committed Oct 29, 2024
1 parent 8d98046 commit abb68a6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/editor-ui/src/components/MainSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ const handleSelect = (key: string) => {
break;
}
case 'cloud-admin': {
void cloudPlanStore.redirectToDashboard();
void uiStore.goToDashboard();
break;
}
case 'quickstart':
Expand Down
7 changes: 0 additions & 7 deletions packages/editor-ui/src/stores/cloudPlan.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,6 @@ export const useCloudPlanStore = defineStore(STORES.CLOUD_PLAN, () => {
}
};

const redirectToDashboard = async () => {
const adminPanelHost = new URL(window.location.href).host.split('.').slice(1).join('.');
const { code } = await getAutoLoginCode();
window.location.href = `https://${adminPanelHost}/login?code=${code}`;
};

const initialize = async () => {
if (state.initialized) {
return;
Expand Down Expand Up @@ -189,6 +183,5 @@ export const useCloudPlanStore = defineStore(STORES.CLOUD_PLAN, () => {
checkForCloudPlanData,
fetchUserCloudAccount,
getAutoLoginCode,
redirectToDashboard,
};
});
26 changes: 24 additions & 2 deletions packages/editor-ui/src/stores/ui.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,11 +630,20 @@ export const useUIStore = defineStore(STORES.UI, () => {
lastCancelledConnectionPosition.value = undefined;
}

const goToVersions = async () => {
const isInstanceOwnerInCloud = () => {
const deploymentType = settingsStore.deploymentType;
return hasPermission(['instanceOwner']) && deploymentType === 'cloud';
};

/**
* If the user is an instance owner in the cloud, it generates an auto-login link to the
* cloud dashboard that redirects the user to the manage page where they can upgrade to a new n8n version.
* Otherwise, it redirect them to our docs.
*/
const goToVersions = async () => {
let versionsLink = versionsStore.infoUrl;

if (deploymentType === 'cloud' && hasPermission(['instanceOwner'])) {
if (isInstanceOwnerInCloud()) {
versionsLink = await generateCloudDashboardAutoLoginLink({
redirectionPath: '/manage',
});
Expand All @@ -643,6 +652,18 @@ export const useUIStore = defineStore(STORES.UI, () => {
location.href = versionsLink;
};

const goToDashboard = async () => {
if (isInstanceOwnerInCloud()) {
const dashboardLink = await generateCloudDashboardAutoLoginLink({
redirectionPath: '/dashboard',
});

location.href = dashboardLink;
}

return;
};

return {
appGridWidth,
appliedTheme,
Expand Down Expand Up @@ -686,6 +707,7 @@ export const useUIStore = defineStore(STORES.UI, () => {
pendingNotificationsForViews,
activeModals,
goToVersions,
goToDashboard,
setTheme,
setMode,
setActiveId,
Expand Down

0 comments on commit abb68a6

Please sign in to comment.