Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6716 | Rev 6718 | 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
 
10
import Spinner from '../components/UI/Spinner'
6512 stevensc 11
import NotificationAlert from '../components/UI/notification/NotificationAlert'
6490 stevensc 12
 
6707 stevensc 13
const Header = lazy(() => import('../components/navbar/Header'))
6601 stevensc 14
const Auth = lazy(() => import('../pages/auth/Auth'))
15
const DashboardPage = lazy(() => import('../pages/dashboard/DashboardPage'))
6707 stevensc 16
const MyConnectionsPage = lazy(() =>
17
  import('../pages/my-connections/MyConnectionsPage')
18
)
6490 stevensc 19
 
6707 stevensc 20
const StyledSpinnerContainer = styled.div`
6717 stevensc 21
  margin: 0 auto 0;
22
  width: 80px;
23
  text-align: center;
24
  height: 80px;
25
  border-radius: 100px;
26
  background-color: #fff;
27
  line-height: 80px;
28
  border: 1px solid #e1e1e1;
29
  cursor: pointer;
6707 stevensc 30
`
31
 
6490 stevensc 32
const AppRouter = () => {
6601 stevensc 33
  const { isAuth } = useSelector(({ auth }) => auth)
6490 stevensc 34
  const dispatch = useDispatch()
35
 
36
  useEffect(() => {
37
    dispatch(getLanguage())
38
  }, [])
39
 
40
  return (
41
    <Router>
6707 stevensc 42
      <Suspense
43
        fallback={
44
          <StyledSpinnerContainer>
45
            <Spinner />
46
          </StyledSpinnerContainer>
47
        }
48
      >
49
        {isAuth && <Header />}
50
 
51
        <Switch>
6601 stevensc 52
          <PrivateRoute exact path="/dashboard" isAuthenticated={isAuth}>
53
            <DashboardPage />
54
          </PrivateRoute>
6707 stevensc 55
          <PrivateRoute
56
            exact
57
            path="/connection/my-connections"
58
            isAuthenticated={isAuth}
59
          >
60
            <MyConnectionsPage />
61
          </PrivateRoute>
6601 stevensc 62
 
63
          <PublicRoute path="/" isAuthenticated={isAuth}>
6546 stevensc 64
            <Auth />
65
          </PublicRoute>
6707 stevensc 66
        </Switch>
67
      </Suspense>
6512 stevensc 68
 
69
      <NotificationAlert />
6490 stevensc 70
    </Router>
71
  )
72
}
73
 
74
export default AppRouter