1- import React from "react" ;
2- import { BrowserRouter , Route , Switch } from "react-router-dom" ;
1+ import React , { useEffect } from "react" ;
2+ import { BrowserRouter , Route , Switch , Redirect } from "react-router-dom" ;
33import Login from "./user/auth/login/login" ;
44import Dashboard from "./user/dashboard/dashboard" ;
55import PinnedPosts from "./user/pinned-posts/pinned-posts" ;
@@ -25,44 +25,58 @@ import Activity from "./user/Activity/Activity";
2525import IntegrationsPage from "./user/integrations/IntegrationsPage/IntegrationsPage" ;
2626import UserIntegrations from "./user/integrations/UserIntegrations/UserIntegrations" ;
2727import TicketDashboard from "../src/user/Admin/Tickets/TicketDashboard" ;
28+ import { loadUser } from './actions/authAction' ;
29+ import { connect } from 'react-redux' ;
2830
29- const Router = ( ) => (
30- < BrowserRouter >
31- < Switch >
32- < Route exact path = "/" component = { Login } />
33- < Route exact path = "/login" component = { Login } />
34- < Route exact path = "/maintenance" component = { Maintenance } > </ Route >
35- < PrivateRoute exact path = "/dashboard" component = { Dashboard } />
36- < PrivateRoute exact path = "/pinned-posts" component = { PinnedPosts } />
37- < PrivateRoute exact path = "/profile/:id" component = { Profile } />
38- < PrivateRoute exact path = "/:id/proj-info" component = { ProjInfo } />
39- < PrivateRoute exact path = "/organization" component = { Organization } />
40- < PrivateRoute exact path = "/wikis" component = { Wikis } />
41- < PrivateRoute exact path = "/settings" component = { Settings } />
42- < PrivateRoute exact path = "/projects" component = { Projects } />
43- < PrivateRoute exact path = "/events" component = { Events } />
44- < PrivateRoute exact path = "/proposal" component = { UserProposalDashboard } />
45- < PrivateRoute
46- exact
47- path = "/proposaldiscussion"
48- component = { ProposalDiscussion }
49- />
50- < PrivateRoute exact path = "/proposaleditor" component = { ProposalEditor } />
51- < PrivateRoute exact path = "/setup" component = { Setup } />
52- < AdminRoute exact path = "/org-settings" component = { CommunitySetting } />
53- < AdminRoute exact path = "/activity/:userId" component = { Activity } />
54- < PrivateRoute exact path = "/insight" component = { Insight } />
55- < PrivateRoute exact path = "/admin" component = { Admin } />
56- < PrivateRoute exact path = "/integrations" component = { IntegrationsPage } />
57- < PrivateRoute
58- exact
59- path = "/userintegrations"
60- component = { UserIntegrations }
61- />
62- < PrivateRoute exact path = "/tickets" component = { TicketDashboard } />
63- < Route component = { NotFound } />
64- </ Switch >
65- </ BrowserRouter >
66- ) ;
31+ const Router = ( { loadUser, auth} ) => {
32+ useEffect ( ( ) => {
33+ loadUser ( ) ;
34+ } , [ ] )
35+ return (
36+ < BrowserRouter >
37+ { auth && auth . isAuthenticated ?< Redirect to = "/dashboard" /> :null }
38+ < Switch >
39+ < Route exact path = "/" component = { Login } />
40+ < Route exact path = "/login" component = { Login } />
41+ < Route exact path = "/maintenance" component = { Maintenance } > </ Route >
42+ < PrivateRoute exact path = "/dashboard" component = { Dashboard } />
43+ < PrivateRoute exact path = "/pinned-posts" component = { PinnedPosts } />
44+ < PrivateRoute exact path = "/profile/:id" component = { Profile } />
45+ < PrivateRoute exact path = "/:id/proj-info" component = { ProjInfo } />
46+ < PrivateRoute exact path = "/organization" component = { Organization } />
47+ < PrivateRoute exact path = "/wikis" component = { Wikis } />
48+ < PrivateRoute exact path = "/settings" component = { Settings } />
49+ < PrivateRoute exact path = "/projects" component = { Projects } />
50+ < PrivateRoute exact path = "/events" component = { Events } />
51+ < PrivateRoute exact path = "/proposal" component = { UserProposalDashboard } />
52+ < PrivateRoute
53+ exact
54+ path = "/proposaldiscussion"
55+ component = { ProposalDiscussion }
56+ />
57+ < PrivateRoute exact path = "/proposaleditor" component = { ProposalEditor } />
58+ < PrivateRoute exact path = "/setup" component = { Setup } />
59+ < AdminRoute exact path = "/org-settings" component = { CommunitySetting } />
60+ < AdminRoute exact path = "/activity/:userId" component = { Activity } />
61+ < PrivateRoute exact path = "/insight" component = { Insight } />
62+ < PrivateRoute exact path = "/admin" component = { Admin } />
63+ < PrivateRoute exact path = "/integrations" component = { IntegrationsPage } />
64+ < PrivateRoute
65+ exact
66+ path = "/userintegrations"
67+ component = { UserIntegrations }
68+ />
69+ < PrivateRoute exact path = "/tickets" component = { TicketDashboard } />
70+ < Route component = { NotFound } />
71+ </ Switch >
72+ </ BrowserRouter >
73+ )
74+ } ;
6775
68- export default Router ;
76+ const mapStateToProps = ( state ) => {
77+ return {
78+ auth : state . auth
79+ }
80+ }
81+
82+ export default connect ( mapStateToProps , { loadUser} ) ( Router ) ;
0 commit comments