diff --git a/frontend/app/components/Client/Users/components/UserForm/UserForm.tsx b/frontend/app/components/Client/Users/components/UserForm/UserForm.tsx index eb25b069e..d2df0431d 100644 --- a/frontend/app/components/Client/Users/components/UserForm/UserForm.tsx +++ b/frontend/app/components/Client/Users/components/UserForm/UserForm.tsx @@ -107,7 +107,7 @@ function UserForm(props: Props) { options={ roles } name="roleId" defaultValue={ user.roleId } - onChange={({ value }) => user.updateKey('roleId', value)} + onChange={({ value }) => user.updateKey('roleId', value.value)} className="block" isDisabled={user.isSuperAdmin} /> diff --git a/frontend/app/components/Dashboard/NewDashboard.tsx b/frontend/app/components/Dashboard/NewDashboard.tsx index 106852923..89af30897 100644 --- a/frontend/app/components/Dashboard/NewDashboard.tsx +++ b/frontend/app/components/Dashboard/NewDashboard.tsx @@ -7,6 +7,7 @@ import { Loader } from 'UI'; import DashboardRouter from './components/DashboardRouter'; import cn from 'classnames'; import { withSiteId } from 'App/routes'; +import withPermissions from 'HOCs/withPermissions' function NewDashboard(props: RouteComponentProps<{}>) { const { history, match: { params: { siteId, dashboardId, metricId } } } = props; @@ -27,7 +28,6 @@ function NewDashboard(props: RouteComponentProps<{}>) { props.history.push(withSiteId('/dashboard', siteId)); }) } - }, [siteId]); return useObserver(() => ( @@ -49,4 +49,4 @@ function NewDashboard(props: RouteComponentProps<{}>) { )); } -export default withRouter(NewDashboard); +export default withRouter(withPermissions(['METRICS'])(NewDashboard)); diff --git a/frontend/app/components/hocs/withPermissions.js b/frontend/app/components/hocs/withPermissions.js index b1c368712..1f4e6ade8 100644 --- a/frontend/app/components/hocs/withPermissions.js +++ b/frontend/app/components/hocs/withPermissions.js @@ -1,22 +1,34 @@ -import React from 'react'; -import { connect } from 'react-redux'; -import { NoPermission, NoSessionPermission } from 'UI'; +import React from "react"; +import { connect } from "react-redux"; +import { NoPermission, NoSessionPermission } from "UI"; -export default (requiredPermissions, className, isReplay = false) => BaseComponent => -@connect((state, props) => ({ - permissions: state.getIn([ 'user', 'account', 'permissions' ]) || [], - isEnterprise: state.getIn([ 'user', 'account', 'edition' ]) === 'ee', -})) -class extends React.PureComponent { - render() { - const hasPermission = requiredPermissions.every(permission => this.props.permissions.includes(permission)); +export default (requiredPermissions, className, isReplay = false) => + (BaseComponent) => + ( + @connect((state, props) => ({ + permissions: + state.getIn(["user", "account", "permissions"]) || [], + isEnterprise: + state.getIn(["user", "account", "edition"]) === "ee", + })) + class extends React.PureComponent { + render() { + const hasPermission = requiredPermissions.every( + (permission) => + this.props.permissions.includes(permission) + ); - return ( - (!this.props.isEnterprise || hasPermission) ? - : -
- { isReplay ? : } -
- ) - } -} \ No newline at end of file + return !this.props.isEnterprise || hasPermission ? ( + + ) : ( +
+ {isReplay ? ( + + ) : ( + + )} +
+ ); + } + } + ); diff --git a/frontend/app/components/ui/NoSessionPermission/NoSessionPermission.tsx b/frontend/app/components/ui/NoSessionPermission/NoSessionPermission.tsx index 7b50ab4c3..4d66e3f2e 100644 --- a/frontend/app/components/ui/NoSessionPermission/NoSessionPermission.tsx +++ b/frontend/app/components/ui/NoSessionPermission/NoSessionPermission.tsx @@ -1,27 +1,77 @@ -import React from 'react'; -import stl from './NoSessionPermission.module.css' -import { Icon, Button, Link } from 'UI'; -import { connect } from 'react-redux'; +import React from "react"; +import stl from "./NoSessionPermission.module.css"; +import { Icon, Button, Link } from "UI"; +import { connect } from "react-redux"; +import { + sessions as sessionsRoute, + assist as assistRoute, + withSiteId, +} from "App/routes"; +import { withRouter, RouteComponentProps } from "react-router-dom"; +const SESSIONS_ROUTE = sessionsRoute(); +const ASSIST_ROUTE = assistRoute(); -interface Props { - session: any +interface Props extends RouteComponentProps { + session: any; + siteId: string; + history: any; + sessionPath: any; + isAssist: boolean; } -function NoSessionPermission({ session }: Props) { - return ( -
- -
Not allowed
- { session.isLive ? - This session is still live, and you don’t have the necessary permissions to access this feature. Please check with your admin. : - You don’t have the necessary permissions to access this feature. Please check with your admin. - } - - - -
- ); +function NoSessionPermission(props: Props) { + const { session, history, siteId, sessionPath, isAssist } = props; + + const backHandler = () => { + if ( + sessionPath.pathname === history.location.pathname || + sessionPath.pathname.includes("/session/") || + isAssist + ) { + history.push( + withSiteId(isAssist ? ASSIST_ROUTE : SESSIONS_ROUTE, siteId) + ); + } else { + history.push( + sessionPath + ? sessionPath.pathname + sessionPath.search + : withSiteId(SESSIONS_ROUTE, siteId) + ); + } + }; + + return ( +
+ +
Not allowed
+ {session.isLive ? ( + + This session is still live, and you don’t have the necessary + permissions to access this feature. Please check with your + admin. + + ) : ( + + You don’t have the necessary permissions to access this + feature. Please check with your admin. + + )} + {/* */} + + {/* */} +
+ ); } -export default connect(state => ({ - session: state.getIn([ 'sessions', 'current' ]), -}))(NoSessionPermission); \ No newline at end of file +export default withRouter( + connect((state: any) => { + const isAssist = window.location.pathname.includes("/assist/"); + return { + isAssist, + session: state.getIn(["sessions", "current"]), + siteId: state.getIn(["site", "siteId"]), + sessionPath: state.getIn(["sessions", "sessionPath"]), + }; + })(NoSessionPermission) +); diff --git a/frontend/app/player/MessageDistributor/MessageDistributor.ts b/frontend/app/player/MessageDistributor/MessageDistributor.ts index 456dcb6dd..936f7409f 100644 --- a/frontend/app/player/MessageDistributor/MessageDistributor.ts +++ b/frontend/app/player/MessageDistributor/MessageDistributor.ts @@ -115,7 +115,7 @@ export default class MessageDistributor extends StatedScreen { eventList.forEach(e => { if (e.type === EVENT_TYPES.LOCATION) { //TODO type system - this.locationEventManager.append(e); + this.locationEventManager.append(e); } }); this.session.errors.forEach(e => {