web: people: Added restricted prop to PrivateRoute (to prevent direct movement to Admin's functional)
This commit is contained in:
parent
d6e09f19e4
commit
1ecb618bfb
@ -8,6 +8,8 @@ import PrivateRoute from "./helpers/privateRoute";
|
|||||||
import Profile from './components/pages/Profile';
|
import Profile from './components/pages/Profile';
|
||||||
import ProfileAction from './components/pages/ProfileAction';
|
import ProfileAction from './components/pages/ProfileAction';
|
||||||
import GroupAction from './components/pages/GroupAction';
|
import GroupAction from './components/pages/GroupAction';
|
||||||
|
import { isAdmin } from "./store/auth/selectors";
|
||||||
|
import { Error404 } from "./components/pages/Error";
|
||||||
|
|
||||||
/*const Profile = lazy(() => import("./components/pages/Profile"));
|
/*const Profile = lazy(() => import("./components/pages/Profile"));
|
||||||
const ProfileAction = lazy(() => import("./components/pages/ProfileAction"));
|
const ProfileAction = lazy(() => import("./components/pages/ProfileAction"));
|
||||||
@ -30,26 +32,24 @@ const App = ({ settings }) => {
|
|||||||
<PrivateRoute
|
<PrivateRoute
|
||||||
path={`${homepage}/edit/:userId`}
|
path={`${homepage}/edit/:userId`}
|
||||||
component={ProfileAction}
|
component={ProfileAction}
|
||||||
|
restricted
|
||||||
/>
|
/>
|
||||||
<PrivateRoute
|
<PrivateRoute
|
||||||
path={`${homepage}/create/:type`}
|
path={`${homepage}/create/:type`}
|
||||||
component={ProfileAction}
|
component={ProfileAction}
|
||||||
|
restricted
|
||||||
/>
|
/>
|
||||||
<PrivateRoute
|
<PrivateRoute
|
||||||
path={`${homepage}/group/edit/:groupId`}
|
path={`${homepage}/group/edit/:groupId`}
|
||||||
component={GroupAction}
|
component={GroupAction}
|
||||||
|
restricted
|
||||||
/>
|
/>
|
||||||
<PrivateRoute
|
<PrivateRoute
|
||||||
path={`${homepage}/group/create`}
|
path={`${homepage}/group/create`}
|
||||||
component={GroupAction}
|
component={GroupAction}
|
||||||
|
restricted
|
||||||
/>
|
/>
|
||||||
<PrivateRoute
|
<PrivateRoute component={Error404} />
|
||||||
component={() => (
|
|
||||||
<ErrorContainer>
|
|
||||||
Sorry, the resource cannot be found.
|
|
||||||
</ErrorContainer>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</Switch>
|
</Switch>
|
||||||
</Suspense>
|
</Suspense>
|
||||||
</PeopleLayout>
|
</PeopleLayout>
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { ErrorContainer } from 'asc-web-components';
|
||||||
|
|
||||||
|
export const Error404 = () => (
|
||||||
|
<ErrorContainer>
|
||||||
|
Sorry, the resource cannot be found.
|
||||||
|
</ErrorContainer>
|
||||||
|
);
|
@ -4,9 +4,11 @@ import PropTypes from "prop-types";
|
|||||||
import { Route } from "react-router-dom";
|
import { Route } from "react-router-dom";
|
||||||
import ExternalRedirect from '../helpers/externalRedirect';
|
import ExternalRedirect from '../helpers/externalRedirect';
|
||||||
import { PageLayout, Loader } from "asc-web-components";
|
import { PageLayout, Loader } from "asc-web-components";
|
||||||
|
import { isAdmin } from "../store/auth/selectors";
|
||||||
|
import { Error404 } from "../components/pages/Error";
|
||||||
|
|
||||||
const PrivateRoute = ({ component: Component, ...rest }) => {
|
const PrivateRoute = ({ component: Component, ...rest }) => {
|
||||||
const { isAuthenticated, isLoaded } = rest;
|
const { isAuthenticated, isLoaded, isAdmin, restricted } = rest;
|
||||||
return (
|
return (
|
||||||
<Route
|
<Route
|
||||||
{...rest}
|
{...rest}
|
||||||
@ -18,7 +20,12 @@ const PrivateRoute = ({ component: Component, ...rest }) => {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
) : isAuthenticated ? (
|
) : isAuthenticated ? (
|
||||||
<Component {...props} />
|
restricted
|
||||||
|
? (isAdmin
|
||||||
|
? <Component {...props} />
|
||||||
|
: <Error404 />
|
||||||
|
)
|
||||||
|
: <Component {...props} />
|
||||||
) : (
|
) : (
|
||||||
<ExternalRedirect to="/login" />
|
<ExternalRedirect to="/login" />
|
||||||
)
|
)
|
||||||
@ -34,7 +41,8 @@ PrivateRoute.propTypes = {
|
|||||||
function mapStateToProps(state) {
|
function mapStateToProps(state) {
|
||||||
return {
|
return {
|
||||||
isAuthenticated: state.auth.isAuthenticated,
|
isAuthenticated: state.auth.isAuthenticated,
|
||||||
isLoaded: state.auth.isLoaded
|
isLoaded: state.auth.isLoaded,
|
||||||
|
isAdmin: isAdmin(state.auth.user)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user