2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-11-27 10:51:33 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2018-11-05 15:26:18 +00:00
|
|
|
import Vue from 'vue';
|
2019-09-09 11:33:39 +01:00
|
|
|
import Router, { RouteRecord } from 'vue-router';
|
|
|
|
|
2019-01-09 15:40:21 +00:00
|
|
|
import AccountArea from '@/components/account/AccountArea.vue';
|
2019-09-09 11:33:39 +01:00
|
|
|
import AccountBilling from '@/components/account/billing/BillingArea.vue';
|
2019-11-25 12:59:41 +00:00
|
|
|
import BillingHistory from '@/components/account/billing/billingHistory/BillingHistory.vue';
|
2020-03-16 12:08:38 +00:00
|
|
|
import SettingsArea from '@/components/account/SettingsArea.vue';
|
2019-01-02 13:46:55 +00:00
|
|
|
import ApiKeysArea from '@/components/apiKeys/ApiKeysArea.vue';
|
2019-08-19 12:20:38 +01:00
|
|
|
import Page404 from '@/components/errors/Page404.vue';
|
2020-04-22 17:21:12 +01:00
|
|
|
import OnboardingTourArea from '@/components/onboardingTour/OnboardingTourArea.vue';
|
2020-03-16 12:08:38 +00:00
|
|
|
import ProjectDashboard from '@/components/project/ProjectDashboard.vue';
|
2019-09-09 11:33:39 +01:00
|
|
|
import ProjectMembersArea from '@/components/team/ProjectMembersArea.vue';
|
|
|
|
|
2019-11-06 12:27:26 +00:00
|
|
|
import store from '@/store';
|
2019-08-22 11:44:08 +01:00
|
|
|
import { NavigationLink } from '@/types/navigation';
|
2019-11-05 10:32:34 +00:00
|
|
|
const DashboardArea = () => import('@/views/DashboardArea.vue');
|
|
|
|
const ForgotPassword = () => import('@/views/forgotPassword/ForgotPassword.vue');
|
|
|
|
const LoginArea = () => import('@/views/login/LoginArea.vue');
|
|
|
|
const RegisterArea = () => import('@/views/register/RegisterArea.vue');
|
2018-11-05 15:26:18 +00:00
|
|
|
|
|
|
|
Vue.use(Router);
|
|
|
|
|
2019-09-27 15:41:04 +01:00
|
|
|
/**
|
|
|
|
* RouteConfig contains information about all routes and subroutes
|
|
|
|
*/
|
2019-08-22 11:44:08 +01:00
|
|
|
export abstract class RouteConfig {
|
|
|
|
// root paths
|
|
|
|
public static Root = new NavigationLink('/', 'Root');
|
|
|
|
public static Login = new NavigationLink('/login', 'Login');
|
|
|
|
public static Register = new NavigationLink('/register', 'Register');
|
|
|
|
public static ForgotPassword = new NavigationLink('/forgot-password', 'Forgot Password');
|
|
|
|
public static Account = new NavigationLink('/account', 'Account');
|
2020-03-16 12:08:38 +00:00
|
|
|
public static ProjectDashboard = new NavigationLink('/project-dashboard', 'Dashboard');
|
2019-08-22 11:44:08 +01:00
|
|
|
public static Team = new NavigationLink('/project-members', 'Team');
|
|
|
|
public static ApiKeys = new NavigationLink('/api-keys', 'API Keys');
|
2020-04-22 17:21:12 +01:00
|
|
|
public static OnboardingTour = new NavigationLink('/onboarding-tour', 'Onboarding Tour');
|
2019-08-22 11:44:08 +01:00
|
|
|
|
|
|
|
// child paths
|
2020-03-16 12:08:38 +00:00
|
|
|
public static Settings = new NavigationLink('settings', 'Settings');
|
2019-09-04 15:33:26 +01:00
|
|
|
public static Billing = new NavigationLink('billing', 'Billing');
|
2019-09-11 11:21:45 +01:00
|
|
|
public static BillingHistory = new NavigationLink('billing-history', 'Billing History');
|
2020-01-22 11:16:27 +00:00
|
|
|
// TODO: disabled until implementation
|
|
|
|
// public static Referral = new NavigationLink('referral', 'Referral');
|
2019-08-22 11:44:08 +01:00
|
|
|
|
|
|
|
// not in project yet
|
|
|
|
// public static Referral = new NavigationLink('//ref/:ids', 'Referral');
|
|
|
|
}
|
|
|
|
|
2019-11-06 12:27:26 +00:00
|
|
|
export const notProjectRelatedRoutes = [
|
|
|
|
RouteConfig.Login.name,
|
|
|
|
RouteConfig.Register.name,
|
2020-03-17 11:44:47 +00:00
|
|
|
RouteConfig.ForgotPassword.name,
|
2019-11-06 12:27:26 +00:00
|
|
|
RouteConfig.Billing.name,
|
|
|
|
RouteConfig.BillingHistory.name,
|
2020-03-16 12:08:38 +00:00
|
|
|
RouteConfig.Settings.name,
|
2020-01-22 11:16:27 +00:00
|
|
|
// RouteConfig.Referral.name,
|
2019-11-06 12:27:26 +00:00
|
|
|
];
|
|
|
|
|
2019-10-28 13:27:12 +00:00
|
|
|
export const router = new Router({
|
2019-02-20 13:33:56 +00:00
|
|
|
mode: 'history',
|
|
|
|
routes: [
|
|
|
|
{
|
2019-08-22 11:44:08 +01:00
|
|
|
path: RouteConfig.Login.path,
|
|
|
|
name: RouteConfig.Login.name,
|
2019-09-26 14:36:12 +01:00
|
|
|
component: LoginArea,
|
2019-02-20 13:33:56 +00:00
|
|
|
},
|
|
|
|
{
|
2019-08-22 11:44:08 +01:00
|
|
|
path: RouteConfig.Register.path,
|
|
|
|
name: RouteConfig.Register.name,
|
2019-09-26 14:36:12 +01:00
|
|
|
component: RegisterArea,
|
2019-07-19 19:22:10 +01:00
|
|
|
},
|
2019-04-02 14:38:57 +01:00
|
|
|
{
|
2019-08-22 11:44:08 +01:00
|
|
|
path: RouteConfig.ForgotPassword.path,
|
|
|
|
name: RouteConfig.ForgotPassword.name,
|
2019-09-13 15:58:18 +01:00
|
|
|
component: ForgotPassword,
|
2019-04-02 14:38:57 +01:00
|
|
|
},
|
2019-02-20 13:33:56 +00:00
|
|
|
{
|
2019-08-22 11:44:08 +01:00
|
|
|
path: RouteConfig.Root.path,
|
2019-02-20 13:33:56 +00:00
|
|
|
meta: {
|
2019-09-13 15:58:18 +01:00
|
|
|
requiresAuth: true,
|
2019-02-20 13:33:56 +00:00
|
|
|
},
|
2019-09-26 14:36:12 +01:00
|
|
|
component: DashboardArea,
|
2019-02-20 13:33:56 +00:00
|
|
|
children: [
|
|
|
|
{
|
2019-08-22 11:44:08 +01:00
|
|
|
path: RouteConfig.Account.path,
|
|
|
|
name: RouteConfig.Account.name,
|
2019-06-03 13:19:48 +01:00
|
|
|
component: AccountArea,
|
|
|
|
children: [
|
|
|
|
{
|
2020-03-16 12:08:38 +00:00
|
|
|
path: RouteConfig.Settings.path,
|
|
|
|
name: RouteConfig.Settings.name,
|
|
|
|
component: SettingsArea,
|
2019-06-03 13:19:48 +01:00
|
|
|
},
|
2019-09-04 15:33:26 +01:00
|
|
|
{
|
|
|
|
path: RouteConfig.Billing.path,
|
|
|
|
name: RouteConfig.Billing.name,
|
|
|
|
component: AccountBilling,
|
|
|
|
},
|
2019-09-11 11:21:45 +01:00
|
|
|
{
|
|
|
|
path: RouteConfig.BillingHistory.path,
|
|
|
|
name: RouteConfig.BillingHistory.name,
|
|
|
|
component: BillingHistory,
|
|
|
|
},
|
2020-01-22 11:16:27 +00:00
|
|
|
// {
|
|
|
|
// path: RouteConfig.Referral.path,
|
|
|
|
// name: RouteConfig.Referral.name,
|
|
|
|
// component: ReferralArea,
|
|
|
|
// },
|
2019-09-13 15:58:18 +01:00
|
|
|
],
|
2019-02-20 13:33:56 +00:00
|
|
|
},
|
|
|
|
{
|
2020-03-16 12:08:38 +00:00
|
|
|
path: RouteConfig.ProjectDashboard.path,
|
|
|
|
name: RouteConfig.ProjectDashboard.name,
|
|
|
|
component: ProjectDashboard,
|
2019-04-05 16:08:14 +01:00
|
|
|
},
|
|
|
|
{
|
2019-08-22 11:44:08 +01:00
|
|
|
path: RouteConfig.Root.path,
|
2019-04-05 16:08:14 +01:00
|
|
|
name: 'default',
|
2020-03-16 12:08:38 +00:00
|
|
|
component: ProjectDashboard,
|
2019-02-20 13:33:56 +00:00
|
|
|
},
|
|
|
|
{
|
2019-08-22 11:44:08 +01:00
|
|
|
path: RouteConfig.Team.path,
|
|
|
|
name: RouteConfig.Team.name,
|
2019-09-13 15:58:18 +01:00
|
|
|
component: ProjectMembersArea,
|
2019-02-20 13:33:56 +00:00
|
|
|
},
|
|
|
|
{
|
2019-08-22 11:44:08 +01:00
|
|
|
path: RouteConfig.ApiKeys.path,
|
|
|
|
name: RouteConfig.ApiKeys.name,
|
2019-09-13 15:58:18 +01:00
|
|
|
component: ApiKeysArea,
|
2019-02-20 13:33:56 +00:00
|
|
|
},
|
2020-02-18 15:48:19 +00:00
|
|
|
{
|
2020-04-22 17:21:12 +01:00
|
|
|
path: RouteConfig.OnboardingTour.path,
|
|
|
|
name: RouteConfig.OnboardingTour.name,
|
|
|
|
component: OnboardingTourArea,
|
2020-02-18 15:48:19 +00:00
|
|
|
},
|
2019-09-13 15:58:18 +01:00
|
|
|
],
|
2019-02-20 13:33:56 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '*',
|
|
|
|
name: '404',
|
2019-09-13 15:58:18 +01:00
|
|
|
component: Page404,
|
2019-03-14 12:48:43 +00:00
|
|
|
},
|
2019-09-13 15:58:18 +01:00
|
|
|
],
|
2018-11-05 15:26:18 +00:00
|
|
|
});
|
2018-11-28 09:16:35 +00:00
|
|
|
|
|
|
|
router.beforeEach((to, from, next) => {
|
2019-09-27 15:41:04 +01:00
|
|
|
if (navigateToDefaultSubTab(to.matched, RouteConfig.Account)) {
|
2020-03-18 17:07:29 +00:00
|
|
|
next(RouteConfig.Account.with(RouteConfig.Billing).path);
|
2018-11-28 09:16:35 +00:00
|
|
|
|
2019-08-22 11:44:08 +01:00
|
|
|
return;
|
|
|
|
}
|
2019-04-05 16:08:14 +01:00
|
|
|
|
2019-08-28 14:08:19 +01:00
|
|
|
if (to.name === 'default') {
|
2020-03-18 17:07:29 +00:00
|
|
|
next(RouteConfig.ProjectDashboard.path);
|
2019-09-27 15:41:04 +01:00
|
|
|
|
|
|
|
return;
|
2019-08-28 14:08:19 +01:00
|
|
|
}
|
|
|
|
|
2019-08-22 11:44:08 +01:00
|
|
|
next();
|
|
|
|
});
|
2019-04-05 16:08:14 +01:00
|
|
|
|
2019-11-06 12:27:26 +00:00
|
|
|
router.afterEach(({name}, from) => {
|
|
|
|
if (!name) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (notProjectRelatedRoutes.includes(name)) {
|
|
|
|
document.title = `${router.currentRoute.name} | ${store.state.appStateModule.satelliteName}`;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const selectedProjectName = store.state.projectsModule.selectedProject.name ?
|
|
|
|
`${store.state.projectsModule.selectedProject.name} | ` : '';
|
|
|
|
|
|
|
|
document.title = `${selectedProjectName + router.currentRoute.name} | ${store.state.appStateModule.satelliteName}`;
|
|
|
|
});
|
|
|
|
|
2019-08-22 11:44:08 +01:00
|
|
|
/**
|
|
|
|
* if our route is a tab and has no sub tab route - we will navigate to default subtab.
|
2020-03-18 17:07:29 +00:00
|
|
|
* F.E. /account/ -> /account/billing/;
|
2019-08-22 11:44:08 +01:00
|
|
|
* @param routes - array of RouteRecord from vue-router
|
|
|
|
* @param next - callback to process next route
|
|
|
|
* @param tabRoute - tabNavigator route
|
|
|
|
*/
|
2019-09-27 15:41:04 +01:00
|
|
|
function navigateToDefaultSubTab(routes: RouteRecord[], tabRoute: NavigationLink): boolean {
|
2019-09-09 11:33:39 +01:00
|
|
|
return routes.length === 2 && (routes[1].name as string) === tabRoute.name;
|
2019-04-05 16:08:14 +01:00
|
|
|
}
|