Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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