PromucFlow_constructor/app/client/src/pages/common/AppRoute.tsx

71 lines
1.8 KiB
TypeScript
Raw Normal View History

import React from "react";
2019-12-16 08:49:10 +00:00
import { Route } from "react-router-dom";
2020-03-11 13:59:46 +00:00
import AnalyticsUtil from "utils/AnalyticsUtil";
import * as Sentry from "@sentry/react";
import { connect } from "react-redux";
import { getThemeDetails } from "selectors/themeSelectors";
2020-09-21 13:08:57 +00:00
import { AppState } from "reducers";
import { ThemeMode } from "reducers/uiReducers/themeReducer";
import { setThemeMode } from "actions/themeActions";
const SentryRoute = Sentry.withSentryRouting(Route);
2020-09-21 13:08:57 +00:00
class AppRouteWithoutProps extends React.Component<{
currentTheme: any;
2020-03-11 13:59:46 +00:00
path?: string;
2020-09-21 13:25:58 +00:00
component: React.ReactType;
exact?: boolean;
2020-03-11 13:59:46 +00:00
logDisable?: boolean;
name: string;
location?: any;
2020-09-21 13:08:57 +00:00
setTheme: Function;
}> {
componentDidUpdate() {
if (!this.props.logDisable) {
2020-03-11 13:59:46 +00:00
AnalyticsUtil.logEvent("NAVIGATE_EDITOR", {
2020-09-21 13:08:57 +00:00
page: this.props.name,
path: this.props.location.pathname,
2020-03-11 13:59:46 +00:00
});
}
2020-09-21 13:08:57 +00:00
}
render() {
const { component: Component, currentTheme, ...rest } = this.props;
2020-09-21 13:08:57 +00:00
if (
window.location.pathname === "/applications" ||
window.location.pathname.indexOf("/settings/") !== -1
) {
document.body.style.backgroundColor =
currentTheme.colors.homepageBackground;
} else {
2020-09-21 13:25:58 +00:00
document.body.style.backgroundColor = currentTheme.colors.appBackground;
2020-09-21 13:08:57 +00:00
}
return (
<SentryRoute
{...rest}
render={props => {
return <Component {...props} />;
}}
/>
);
}
2020-09-21 13:08:57 +00:00
}
const mapStateToProps = (state: AppState) => ({
currentTheme: getThemeDetails(state).theme,
});
const mapDispatchToProps = (dispatch: any) => ({
setTheme: (mode: ThemeMode) => {
dispatch(setThemeMode(mode));
},
});
const AppRoute = connect(
mapStateToProps,
mapDispatchToProps,
)(AppRouteWithoutProps);
2019-09-02 14:50:01 +00:00
2020-09-21 13:08:57 +00:00
(AppRoute as any).whyDidYouRender = {
logOnDifferentValues: false,
};
2020-03-11 13:59:46 +00:00
export default AppRoute;