File tree Expand file tree Collapse file tree 3 files changed +27
-4
lines changed Expand file tree Collapse file tree 3 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,6 @@ import Loadable from 'react-loadable'
6
6
7
7
import Loading from './components/Loading/Loading'
8
8
import AuthActionCreator from './actions/auth'
9
- import CreateProjectForm from './components/CreateProjectForm/CreateProjectForm'
10
9
import ForgotPasswordForm from './components/ForgotPasswordForm/ForgotPasswordForm'
11
10
import Header from './components/Header/Header'
12
11
import Home from './components/Home/Home'
@@ -22,6 +21,11 @@ const ProfileRestrictedLoadable = restricted(Loadable({
22
21
loading : Loading
23
22
} ) )
24
23
24
+ const CreateProjectRestrictedLoadable = restricted ( Loadable ( {
25
+ loader : ( ) => import ( './components/CreateProjectForm/CreateProjectForm' ) ,
26
+ loading : Loading
27
+ } ) )
28
+
25
29
class App extends Component {
26
30
componentDidMount ( ) {
27
31
this . props . appLoad ( )
@@ -34,7 +38,7 @@ class App extends Component {
34
38
< Version />
35
39
< Switch >
36
40
< Route exact path = '/' component = { Home } />
37
- < Route path = '/create-project' component = { CreateProjectForm } />
41
+ < Route path = '/create-project' component = { CreateProjectRestrictedLoadable } />
38
42
< Route path = '/forgot-password' component = { ForgotPasswordForm } />
39
43
< Route path = '/login' component = { LoginForm } />
40
44
< Route path = '/profile' component = { ProfileRestrictedLoadable } />
Original file line number Diff line number Diff line change 1
1
import React , { Component } from 'react'
2
2
import { connect } from 'react-redux'
3
3
import PropTypes from 'prop-types'
4
+ import { default as constants } from '../../constants'
4
5
5
6
/**
6
7
* Higher-order component (HOC) to wrap restricted pages
@@ -21,6 +22,18 @@ export default function (BaseComponent) {
21
22
const { history } = params
22
23
if ( ! params . authenticated ) {
23
24
history . replace ( { pathname : '/login' } )
25
+ } else {
26
+ if ( ! this . routesAvailableByUserType ( ) ) {
27
+ history . replace ( { pathname : '/' } )
28
+ }
29
+ }
30
+ }
31
+
32
+ routesAvailableByUserType ( ) {
33
+ switch ( this . props . location . pathname ) {
34
+ case '/create-project' :
35
+ return this . props . user . usertype === constants . USER_TYPE_CONTACT
36
+ default : return true
24
37
}
25
38
}
26
39
@@ -31,12 +44,14 @@ export default function (BaseComponent) {
31
44
32
45
function mapStateToProps ( state ) {
33
46
return {
34
- authenticated : state . auth . authenticated
47
+ authenticated : state . auth . authenticated ,
48
+ user : state . user
35
49
}
36
50
}
37
51
38
52
Restricted . propTypes = {
39
- location : PropTypes . object
53
+ location : PropTypes . object ,
54
+ user : PropTypes . object
40
55
}
41
56
42
57
return connect ( mapStateToProps ) ( Restricted )
Original file line number Diff line number Diff line change
1
+ export default {
2
+ USER_TYPE_VOLUNTEER : 'volunteer' ,
3
+ USER_TYPE_CONTACT : 'contact'
4
+ }
You can’t perform that action at this time.
0 commit comments