Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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