Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6707 | Rev 6717 | 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`
6716 stevensc 21
  position: relative;
22
  padding: 100px;
6707 stevensc 23
  background: rgba(255, 255, 255, 0.4);
6716 stevensc 24
  border-radius: 50%;
6707 stevensc 25
  display: flex;
26
  justify-content: center;
27
  align-items: center;
28
  z-index: 300;
29
`
30
 
6490 stevensc 31
const AppRouter = () => {
6601 stevensc 32
  const { isAuth } = useSelector(({ auth }) => auth)
6490 stevensc 33
  const dispatch = useDispatch()
34
 
35
  useEffect(() => {
36
    dispatch(getLanguage())
37
  }, [])
38
 
39
  return (
40
    <Router>
6707 stevensc 41
      <Suspense
42
        fallback={
43
          <StyledSpinnerContainer>
44
            <Spinner />
45
          </StyledSpinnerContainer>
46
        }
47
      >
48
        {isAuth && <Header />}
49
 
50
        <Switch>
6601 stevensc 51
          <PrivateRoute exact path="/dashboard" isAuthenticated={isAuth}>
52
            <DashboardPage />
53
          </PrivateRoute>
6707 stevensc 54
          <PrivateRoute
55
            exact
56
            path="/connection/my-connections"
57
            isAuthenticated={isAuth}
58
          >
59
            <MyConnectionsPage />
60
          </PrivateRoute>
6601 stevensc 61
 
62
          <PublicRoute path="/" isAuthenticated={isAuth}>
6546 stevensc 63
            <Auth />
64
          </PublicRoute>
6707 stevensc 65
        </Switch>
66
      </Suspense>
6512 stevensc 67
 
68
      <NotificationAlert />
6490 stevensc 69
    </Router>
70
  )
71
}
72
 
73
export default AppRouter