Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6724 | Rev 6726 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
6601 stevensc 1
import React, { lazy, Suspense, useEffect } from 'react'
2
import { useDispatch, useSelector } from 'react-redux'
6514 stevensc 3
import { BrowserRouter as Router, Switch } from 'react-router-dom'
6707 stevensc 4
import styled from 'styled-components'
6490 stevensc 5
import { getLanguage } from '../../redux/intl/intl.action'
6
 
6530 stevensc 7
import PublicRoute from './PublicRoute'
6601 stevensc 8
import PrivateRoute from './PrivateRoute'
6707 stevensc 9
import Spinner from '../components/UI/Spinner'
6512 stevensc 10
import NotificationAlert from '../components/UI/notification/NotificationAlert'
6490 stevensc 11
 
6707 stevensc 12
const Header = lazy(() => import('../components/navbar/Header'))
6601 stevensc 13
const Auth = lazy(() => import('../pages/auth/Auth'))
14
const DashboardPage = lazy(() => import('../pages/dashboard/DashboardPage'))
6707 stevensc 15
const MyConnectionsPage = lazy(() =>
6719 stevensc 16
  import('../pages/connections/MyConnectionsPage')
6707 stevensc 17
)
6724 stevensc 18
const InvitationsReceivedPage = lazy(() =>
19
  import('../pages/connections/InvitationsReceivedPage')
20
)
6719 stevensc 21
const InvitationsSendPage = lazy(() =>
6724 stevensc 22
  import('../pages/connections/InvitationsSendPage')
6719 stevensc 23
)
6725 stevensc 24
const PeopleYouMayKnowPage = lazy(() =>
25
  import('../pages/connections/PeopleYouMayKnowPage')
26
)
27
const PeopleBlockedPage = lazy(() =>
28
  import('../pages/connections/PeopleBlockedPage')
29
)
6490 stevensc 30
 
6707 stevensc 31
const StyledSpinnerContainer = styled.div`
6718 stevensc 32
  margin: 1rem auto;
33
  position: relative;
6717 stevensc 34
  width: 80px;
35
  text-align: center;
36
  height: 80px;
37
  border-radius: 100px;
38
  background-color: #fff;
39
  line-height: 80px;
40
  border: 1px solid #e1e1e1;
41
  cursor: pointer;
6707 stevensc 42
`
43
 
6490 stevensc 44
const AppRouter = () => {
6601 stevensc 45
  const { isAuth } = useSelector(({ auth }) => auth)
6490 stevensc 46
  const dispatch = useDispatch()
47
 
48
  useEffect(() => {
49
    dispatch(getLanguage())
50
  }, [])
51
 
52
  return (
53
    <Router>
6724 stevensc 54
      <Suspense fallback={null}>{isAuth && <Header />}</Suspense>
55
 
6707 stevensc 56
      <Suspense
57
        fallback={
58
          <StyledSpinnerContainer>
59
            <Spinner />
60
          </StyledSpinnerContainer>
61
        }
62
      >
63
        <Switch>
6601 stevensc 64
          <PrivateRoute exact path="/dashboard" isAuthenticated={isAuth}>
65
            <DashboardPage />
66
          </PrivateRoute>
6707 stevensc 67
          <PrivateRoute
68
            exact
69
            path="/connection/my-connections"
70
            isAuthenticated={isAuth}
71
          >
72
            <MyConnectionsPage />
73
          </PrivateRoute>
6719 stevensc 74
          <PrivateRoute
75
            exact
76
            path="/connection/invitations-sent"
77
            isAuthenticated={isAuth}
78
          >
79
            <InvitationsSendPage />
80
          </PrivateRoute>
6724 stevensc 81
          <PrivateRoute
82
            exact
83
            path="/connection/invitations-received"
84
            isAuthenticated={isAuth}
85
          >
86
            <InvitationsReceivedPage />
87
          </PrivateRoute>
6725 stevensc 88
          <PrivateRoute
89
            exact
90
            path="/connection/people-you-may-know"
91
            isAuthenticated={isAuth}
92
          >
93
            <PeopleYouMayKnowPage />
94
          </PrivateRoute>
95
          <PrivateRoute
96
            exact
97
            path="/connection/invitations-received"
98
            isAuthenticated={isAuth}
99
          >
100
            <PeopleBlockedPage />
101
          </PrivateRoute>
6601 stevensc 102
 
103
          <PublicRoute path="/" isAuthenticated={isAuth}>
6546 stevensc 104
            <Auth />
105
          </PublicRoute>
6707 stevensc 106
        </Switch>
107
      </Suspense>
6512 stevensc 108
 
109
      <NotificationAlert />
6490 stevensc 110
    </Router>
111
  )
112
}
113
 
114
export default AppRouter