2020-08-03 14:18:48 +00:00
|
|
|
import React, { Suspense } from "react";
|
|
|
|
|
import history from "utils/history";
|
|
|
|
|
import AppHeader from "pages/common/AppHeader";
|
2020-09-24 16:05:18 +00:00
|
|
|
import { Redirect, Route, Router, Switch } from "react-router-dom";
|
2020-08-03 14:18:48 +00:00
|
|
|
import {
|
|
|
|
|
APPLICATIONS_URL,
|
|
|
|
|
AUTH_LOGIN_URL,
|
|
|
|
|
BASE_LOGIN_URL,
|
|
|
|
|
BASE_SIGNUP_URL,
|
|
|
|
|
BASE_URL,
|
|
|
|
|
BUILDER_URL,
|
|
|
|
|
ORG_URL,
|
|
|
|
|
SIGN_UP_URL,
|
2021-06-16 15:51:18 +00:00
|
|
|
SIGNUP_SUCCESS_URL,
|
2020-08-03 14:18:48 +00:00
|
|
|
USER_AUTH_URL,
|
|
|
|
|
USERS_URL,
|
2021-03-04 09:37:02 +00:00
|
|
|
PROFILE,
|
2021-07-19 18:14:38 +00:00
|
|
|
UNSUBSCRIBE_EMAIL_URL,
|
2021-09-12 16:36:43 +00:00
|
|
|
SETUP,
|
2021-10-18 14:03:44 +00:00
|
|
|
VIEWER_URL,
|
2021-10-18 07:47:55 +00:00
|
|
|
ADMIN_SETTINGS_URL,
|
|
|
|
|
ADMIN_SETTINGS_CATEGORY_URL,
|
|
|
|
|
ADMIN_SETTINGS_CATEGORY_DEFAULT_URL,
|
2022-03-03 10:56:53 +00:00
|
|
|
TEMPLATES_URL,
|
2020-08-03 14:18:48 +00:00
|
|
|
} from "constants/routes";
|
|
|
|
|
import OrganizationLoader from "pages/organization/loader";
|
|
|
|
|
import ApplicationListLoader from "pages/Applications/loader";
|
|
|
|
|
import EditorLoader from "pages/Editor/loader";
|
|
|
|
|
import AppViewerLoader from "pages/AppViewer/loader";
|
|
|
|
|
import LandingScreen from "./LandingScreen";
|
|
|
|
|
import UserAuth from "pages/UserAuth";
|
|
|
|
|
import Users from "pages/users";
|
2020-12-17 07:03:59 +00:00
|
|
|
import ErrorPage from "pages/common/ErrorPage";
|
2020-08-03 14:18:48 +00:00
|
|
|
import PageNotFound from "pages/common/PageNotFound";
|
2020-08-18 08:48:06 +00:00
|
|
|
import PageLoadingBar from "pages/common/PageLoadingBar";
|
2020-12-17 07:03:59 +00:00
|
|
|
import ErrorPageHeader from "pages/common/ErrorPageHeader";
|
2021-07-19 18:14:38 +00:00
|
|
|
import UnsubscribeEmail from "pages/common/UnsubscribeEmail";
|
2021-02-11 12:54:00 +00:00
|
|
|
import { getCurrentThemeDetails, ThemeMode } from "selectors/themeSelectors";
|
2020-09-24 16:05:18 +00:00
|
|
|
import { AppState } from "reducers";
|
|
|
|
|
import { setThemeMode } from "actions/themeActions";
|
|
|
|
|
import { connect } from "react-redux";
|
|
|
|
|
|
|
|
|
|
import * as Sentry from "@sentry/react";
|
2020-10-12 12:56:03 +00:00
|
|
|
import AnalyticsUtil from "utils/AnalyticsUtil";
|
2020-10-26 07:00:01 +00:00
|
|
|
import { trimTrailingSlash } from "utils/helpers";
|
2020-12-17 07:03:59 +00:00
|
|
|
import { getSafeCrash, getSafeCrashCode } from "selectors/errorSelectors";
|
2021-03-04 09:37:02 +00:00
|
|
|
import UserProfile from "pages/UserProfile";
|
2021-08-05 06:10:19 +00:00
|
|
|
import { getCurrentUser } from "actions/authActions";
|
|
|
|
|
import { getFeatureFlagsFetched } from "selectors/usersSelectors";
|
2021-09-12 16:36:43 +00:00
|
|
|
import Setup from "pages/setup";
|
2021-10-18 07:47:55 +00:00
|
|
|
import Settings from "pages/Settings";
|
2021-10-21 05:36:17 +00:00
|
|
|
import SignupSuccess from "pages/setup/SignupSuccess";
|
2022-03-03 10:56:53 +00:00
|
|
|
import TemplatesListLoader from "pages/Templates/loader";
|
|
|
|
|
import getFeatureFlags from "utils/featureFlags";
|
2020-10-26 07:00:01 +00:00
|
|
|
|
2020-09-24 16:05:18 +00:00
|
|
|
const SentryRoute = Sentry.withSentryRouting(Route);
|
2020-08-03 14:18:48 +00:00
|
|
|
|
2020-08-18 08:48:06 +00:00
|
|
|
const loadingIndicator = <PageLoadingBar />;
|
2020-08-03 14:18:48 +00:00
|
|
|
|
2020-09-24 16:05:18 +00:00
|
|
|
function changeAppBackground(currentTheme: any) {
|
|
|
|
|
if (
|
2020-10-26 07:00:01 +00:00
|
|
|
trimTrailingSlash(window.location.pathname) === "/applications" ||
|
2021-03-04 09:37:02 +00:00
|
|
|
window.location.pathname.indexOf("/settings/") !== -1 ||
|
2021-06-16 15:51:18 +00:00
|
|
|
trimTrailingSlash(window.location.pathname) === "/profile" ||
|
|
|
|
|
trimTrailingSlash(window.location.pathname) === "/signup-success"
|
2020-09-24 16:05:18 +00:00
|
|
|
) {
|
|
|
|
|
document.body.style.backgroundColor =
|
|
|
|
|
currentTheme.colors.homepageBackground;
|
|
|
|
|
} else {
|
|
|
|
|
document.body.style.backgroundColor = currentTheme.colors.appBackground;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-03 14:18:48 +00:00
|
|
|
class AppRouter extends React.Component<any, any> {
|
2020-10-12 12:56:03 +00:00
|
|
|
unlisten: any;
|
|
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
|
// This is needed for the route switch.
|
|
|
|
|
AnalyticsUtil.logEvent("ROUTE_CHANGE", { path: window.location.pathname });
|
|
|
|
|
this.unlisten = history.listen((location: any) => {
|
|
|
|
|
AnalyticsUtil.logEvent("ROUTE_CHANGE", { path: location.pathname });
|
|
|
|
|
changeAppBackground(this.props.currentTheme);
|
|
|
|
|
});
|
2021-08-05 06:10:19 +00:00
|
|
|
this.props.getCurrentUser();
|
2020-10-12 12:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
|
this.unlisten();
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-03 14:18:48 +00:00
|
|
|
render() {
|
2021-08-05 06:10:19 +00:00
|
|
|
const {
|
|
|
|
|
currentTheme,
|
|
|
|
|
featureFlagsFetched,
|
|
|
|
|
safeCrash,
|
|
|
|
|
safeCrashCode,
|
|
|
|
|
} = this.props;
|
2020-12-17 07:03:59 +00:00
|
|
|
|
2020-09-24 16:05:18 +00:00
|
|
|
// This is needed for the theme switch.
|
|
|
|
|
changeAppBackground(currentTheme);
|
2020-12-17 07:03:59 +00:00
|
|
|
|
2021-08-05 06:10:19 +00:00
|
|
|
// Render the app once the feature flags have been fetched
|
|
|
|
|
if (!featureFlagsFetched) return null;
|
|
|
|
|
|
2020-08-03 14:18:48 +00:00
|
|
|
return (
|
|
|
|
|
<Router history={history}>
|
|
|
|
|
<Suspense fallback={loadingIndicator}>
|
2020-12-08 19:13:48 +00:00
|
|
|
{safeCrash ? (
|
2020-12-17 07:03:59 +00:00
|
|
|
<>
|
|
|
|
|
<ErrorPageHeader />
|
|
|
|
|
<ErrorPage code={safeCrashCode} />
|
|
|
|
|
</>
|
2020-12-08 19:13:48 +00:00
|
|
|
) : (
|
2020-12-17 07:03:59 +00:00
|
|
|
<>
|
|
|
|
|
<AppHeader />
|
|
|
|
|
<Switch>
|
2021-04-28 10:28:39 +00:00
|
|
|
<SentryRoute component={LandingScreen} exact path={BASE_URL} />
|
2020-12-17 07:03:59 +00:00
|
|
|
<Redirect exact from={BASE_LOGIN_URL} to={AUTH_LOGIN_URL} />
|
|
|
|
|
<Redirect exact from={BASE_SIGNUP_URL} to={SIGN_UP_URL} />
|
2021-04-28 10:28:39 +00:00
|
|
|
<SentryRoute component={OrganizationLoader} path={ORG_URL} />
|
|
|
|
|
<SentryRoute component={Users} exact path={USERS_URL} />
|
|
|
|
|
<SentryRoute component={UserAuth} path={USER_AUTH_URL} />
|
2020-12-17 07:03:59 +00:00
|
|
|
<SentryRoute
|
2021-04-28 10:28:39 +00:00
|
|
|
component={ApplicationListLoader}
|
2020-12-17 07:03:59 +00:00
|
|
|
exact
|
|
|
|
|
path={APPLICATIONS_URL}
|
|
|
|
|
/>
|
2022-03-03 10:56:53 +00:00
|
|
|
{getFeatureFlags().APP_TEMPLATE && (
|
|
|
|
|
<SentryRoute
|
|
|
|
|
component={TemplatesListLoader}
|
|
|
|
|
path={TEMPLATES_URL}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2021-06-16 15:51:18 +00:00
|
|
|
<SentryRoute
|
2021-10-21 05:36:17 +00:00
|
|
|
component={SignupSuccess}
|
2021-06-16 15:51:18 +00:00
|
|
|
exact
|
|
|
|
|
path={SIGNUP_SUCCESS_URL}
|
|
|
|
|
/>
|
2021-10-20 07:38:17 +00:00
|
|
|
|
2021-12-07 07:59:32 +00:00
|
|
|
<SentryRoute component={UserProfile} path={PROFILE} />
|
2021-07-19 18:14:38 +00:00
|
|
|
<SentryRoute
|
|
|
|
|
component={UnsubscribeEmail}
|
|
|
|
|
path={UNSUBSCRIBE_EMAIL_URL}
|
|
|
|
|
/>
|
2021-09-14 16:55:29 +00:00
|
|
|
<SentryRoute component={Setup} exact path={SETUP} />
|
2021-10-18 14:03:44 +00:00
|
|
|
<SentryRoute component={EditorLoader} path={BUILDER_URL} />
|
|
|
|
|
<SentryRoute component={AppViewerLoader} path={VIEWER_URL} />
|
2021-10-18 07:47:55 +00:00
|
|
|
<Redirect
|
|
|
|
|
exact
|
|
|
|
|
from={ADMIN_SETTINGS_URL}
|
|
|
|
|
to={ADMIN_SETTINGS_CATEGORY_DEFAULT_URL}
|
|
|
|
|
/>
|
|
|
|
|
<SentryRoute
|
|
|
|
|
component={Settings}
|
|
|
|
|
exact
|
|
|
|
|
path={ADMIN_SETTINGS_CATEGORY_URL}
|
|
|
|
|
/>
|
2020-12-17 07:03:59 +00:00
|
|
|
<SentryRoute component={PageNotFound} />
|
|
|
|
|
</Switch>
|
|
|
|
|
</>
|
2020-12-08 19:13:48 +00:00
|
|
|
)}
|
2020-08-03 14:18:48 +00:00
|
|
|
</Suspense>
|
|
|
|
|
</Router>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-24 16:05:18 +00:00
|
|
|
const mapStateToProps = (state: AppState) => ({
|
2021-02-11 12:54:00 +00:00
|
|
|
currentTheme: getCurrentThemeDetails(state),
|
2020-12-17 07:03:59 +00:00
|
|
|
safeCrash: getSafeCrash(state),
|
|
|
|
|
safeCrashCode: getSafeCrashCode(state),
|
2021-08-05 06:10:19 +00:00
|
|
|
featureFlagsFetched: getFeatureFlagsFetched(state),
|
2020-09-24 16:05:18 +00:00
|
|
|
});
|
2020-12-17 07:03:59 +00:00
|
|
|
|
2020-09-24 16:05:18 +00:00
|
|
|
const mapDispatchToProps = (dispatch: any) => ({
|
|
|
|
|
setTheme: (mode: ThemeMode) => {
|
|
|
|
|
dispatch(setThemeMode(mode));
|
|
|
|
|
},
|
2021-08-05 06:10:19 +00:00
|
|
|
getCurrentUser: () => dispatch(getCurrentUser()),
|
2020-09-24 16:05:18 +00:00
|
|
|
});
|
2020-08-03 14:18:48 +00:00
|
|
|
|
2020-09-24 16:05:18 +00:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(AppRouter);
|