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

58 lines
1.3 KiB
TypeScript
Raw Normal View History

2020-03-11 13:59:46 +00:00
import React, { useEffect } from "react";
2019-12-16 08:49:10 +00:00
import { Route } from "react-router-dom";
import {
useShowPropertyPane,
useWidgetSelection,
} from "utils/hooks/dragResizeHooks";
2020-03-11 13:59:46 +00:00
import AnalyticsUtil from "utils/AnalyticsUtil";
export const WrappedComponent = (props: any) => {
2020-01-27 11:39:27 +00:00
const showPropertyPane = useShowPropertyPane();
showPropertyPane();
const { selectWidget, focusWidget } = useWidgetSelection();
selectWidget(undefined);
focusWidget(undefined);
2020-05-05 12:16:51 +00:00
return props.children;
};
2019-09-02 15:36:24 +00:00
2020-03-11 13:59:46 +00:00
const AppRoute = ({
component: Component,
...rest
}: {
2020-03-11 13:59:46 +00:00
path?: string;
component: React.ReactType;
exact?: boolean;
2020-03-11 13:59:46 +00:00
routeProtected?: boolean;
logDisable?: boolean;
name: string;
location?: any;
}) => {
2020-03-11 13:59:46 +00:00
useEffect(() => {
if (!rest.logDisable) {
AnalyticsUtil.logEvent("NAVIGATE_EDITOR", {
page: rest.name,
path: rest.location.pathname,
});
}
}, [rest.name, rest.logDisable, rest.location.pathname]);
return (
<Route
{...rest}
2020-03-11 13:59:46 +00:00
render={props => {
return rest.routeProtected ? (
<WrappedComponent {...props}>
<Component {...props} />
</WrappedComponent>
) : (
<Component {...props}></Component>
);
}}
/>
);
};
2019-09-02 14:50:01 +00:00
2020-03-11 13:59:46 +00:00
export default AppRoute;