Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 7378 | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

import React, { lazy, Suspense, useEffect } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { BrowserRouter as Router, Switch } from 'react-router-dom'
import { getLanguage } from '../../redux/intl/intl.action'
import { getPermissions } from '../redux/auth/auth.actions'

import AuthRoute from './AuthRoute'
import PrivateRoute from './PrivateRoute'
import Spinner from '../components/UI/Spinner'
import NotificationAlert from '../components/UI/notification/NotificationAlert'
import LoaderContainer from '../components/UI/LoaderContainer'

import ChatHelper from '../components/chat/helper/ChatHelper'
import Header from '../components/navbar/Header'

const DashboardPage = lazy(() => import('../pages/dashboard/DashboardPage'))
const MyConnectionsPage = lazy(() =>
  import('../pages/connections/MyConnectionsPage')
)
const InvitationsReceivedPage = lazy(() =>
  import('../pages/connections/InvitationsReceivedPage')
)
const InvitationsSendPage = lazy(() =>
  import('../pages/connections/InvitationsSendPage')
)
const PeopleYouMayKnowPage = lazy(() =>
  import('../pages/connections/PeopleYouMayKnowPage')
)
const PeopleBlockedPage = lazy(() =>
  import('../pages/connections/PeopleBlockedPage')
)
const MyProfilesPage = lazy(() => import('../pages/profiles/MyProfilesPage'))
const PeopleViewedMyProfilePage = lazy(() =>
  import('../pages/profiles/PeopleViewedMyProfilePage')
)
const SavedJobsPage = lazy(() => import('../pages/jobs/SavedJobsPage'))
const AppliedJobsPage = lazy(() => import('../pages/jobs/AppliedJobsPage'))
const GroupsRequestsSendPage = lazy(() =>
  import('../pages/groups/GroupsRequestsSendPage')
)
const GroupsRequestsReceivedPage = lazy(() =>
  import('../pages/groups/GroupsRequestsReceivedPage')
)
const JoinedGroupsPage = lazy(() => import('../pages/groups/JoinedGroupsPage'))
const MyGroupsPage = lazy(() => import('../pages/groups/MyGroupsPage'))
const MyCompanies = lazy(() => import('../pages/company/MyCompaniesPage'))
const FollowingCompaniesPage = lazy(() =>
  import('../pages/company/FollowingCompaniesPage')
)
const CompaniesWhenIWorkPage = lazy(() =>
  import('../pages/company/CompaniesWhenIWorkPage')
)
const CompanyRequestSendPage = lazy(() =>
  import('../pages/company/CompanyRequestSendPage')
)
const CompanyInvitationsReceivedPage = lazy(() =>
  import('../pages/company/CompanyInvitationsReceivedPage')
)
const ProfileViewPage = lazy(() => import('../pages/profiles/ProfileViewPage'))
const ProfileEditPage = lazy(() => import('../pages/profiles/ProfileEditPage'))
const CompanyViewPage = lazy(() => import('../pages/company/CompanyViewPage'))
const GroupViewPage = lazy(() => import('../pages/groups/GroupViewPage'))
const GroupEditPage = lazy(() => import('../pages/groups/GroupEditPage'))
const ChatPage = lazy(() => import('../pages/chat/ChatPage'))
const InmailPage = lazy(() => import('../pages/inmail/InmailPage'))
const MarketPlacePage = lazy(() =>
  import('../pages/marketplace/MarketplacePage')
)
const NotificationsPage = lazy(() =>
  import('../pages/notifications/NotificationsPage')
)
const SearchPage = lazy(() => import('../pages/search/SearchPage'))
const KnowledgeAreaPage = lazy(() =>
  import('../pages/knowledge-area/KnowledgeAreaPage')
)
const KnowledgeViewPage = lazy(() =>
  import('../pages/knowledge-area/KnowledgeViewPage')
)
const PostViewPage = lazy(() => import('../pages/posts/PostViewPage'))
const MyCoachPage = lazy(() => import('../pages/my-coach/MyCoachPage'))
const MyCoachViewPage = lazy(() => import('../pages/my-coach/MyCoachViewPage'))
const JobViewPage = lazy(() => import('../pages/jobs/JobView'))
const CalendarPage = lazy(() => import('../pages/calendar/CalendarPage'))
const SigninPage = lazy(() => import('../pages/auth/SigninPage'))
const ImpersonatePage = lazy(() =>
  import('../pages/impersonate/InpersonatePage')
)

const AppRouter = () => {
  const { theme_id, isAuth, loading } = useSelector(({ auth }) => auth)
  const dispatch = useDispatch()

  useEffect(() => {
    dispatch(getPermissions())
    dispatch(getLanguage())
  }, [])

  if (loading) {
    return (
      <LoaderContainer>
        <Spinner />
      </LoaderContainer>
    )
  }

  return (
    <Router>
      {isAuth ? <Header theme={theme_id} /> : null}

      <Suspense
        fallback={
          <LoaderContainer>
            <Spinner />
          </LoaderContainer>
        }
      >
        <Switch>
          <PrivateRoute exact path="/dashboard" isAuthenticated={isAuth}>
            <DashboardPage />
          </PrivateRoute>
          <PrivateRoute
            exact
            path="/connection/my-connections"
            isAuthenticated={isAuth}
          >
            <MyConnectionsPage />
          </PrivateRoute>
          <PrivateRoute
            exact
            path="/connection/invitations-sent"
            isAuthenticated={isAuth}
          >
            <InvitationsSendPage />
          </PrivateRoute>
          <PrivateRoute
            exact
            path="/connection/invitations-received"
            isAuthenticated={isAuth}
          >
            <InvitationsReceivedPage />
          </PrivateRoute>
          <PrivateRoute
            exact
            path="/connection/people-you-may-know"
            isAuthenticated={isAuth}
          >
            <PeopleYouMayKnowPage />
          </PrivateRoute>
          <PrivateRoute
            exact
            path="/connection/people-blocked"
            isAuthenticated={isAuth}
          >
            <PeopleBlockedPage />
          </PrivateRoute>
          <PrivateRoute
            exact
            path="/profile/my-profiles"
            isAuthenticated={isAuth}
          >
            <MyProfilesPage />
          </PrivateRoute>
          <PrivateRoute
            exact
            path="/profile/people-viewed-profile"
            isAuthenticated={isAuth}
          >
            <PeopleViewedMyProfilePage />
          </PrivateRoute>
          <PrivateRoute path="/profile/view/:uuid" isAuthenticated={isAuth}>
            <ProfileViewPage />
          </PrivateRoute>
          <PrivateRoute
            path="/profile/my-profiles/edit/:uuid"
            isAuthenticated={isAuth}
          >
            <ProfileEditPage />
          </PrivateRoute>
          <PrivateRoute exact path="/job/saved-jobs" isAuthenticated={isAuth}>
            <SavedJobsPage />
          </PrivateRoute>
          <PrivateRoute exact path="/job/applied-jobs" isAuthenticated={isAuth}>
            <AppliedJobsPage />
          </PrivateRoute>
          <PrivateRoute
            exact
            path="/group/requests-sent"
            isAuthenticated={isAuth}
          >
            <GroupsRequestsSendPage />
          </PrivateRoute>
          <PrivateRoute
            exact
            path="/group/invitations-received"
            isAuthenticated={isAuth}
          >
            <GroupsRequestsReceivedPage />
          </PrivateRoute>
          <PrivateRoute
            exact
            path="/group/joined-groups"
            isAuthenticated={isAuth}
          >
            <JoinedGroupsPage />
          </PrivateRoute>
          <PrivateRoute exact path="/group/my-groups" isAuthenticated={isAuth}>
            <MyGroupsPage />
          </PrivateRoute>
          <PrivateRoute path="/group/view/:uuid" isAuthenticated={isAuth}>
            <GroupViewPage />
          </PrivateRoute>
          <PrivateRoute
            path="/group/my-groups/edit/:uuid"
            isAuthenticated={isAuth}
          >
            <GroupEditPage />
          </PrivateRoute>
          <PrivateRoute
            exact
            path="/company/my-companies"
            isAuthenticated={isAuth}
          >
            <MyCompanies />
          </PrivateRoute>
          <PrivateRoute
            exact
            path="/company/following-companies"
            isAuthenticated={isAuth}
          >
            <FollowingCompaniesPage />
          </PrivateRoute>
          <PrivateRoute
            exact
            path="/company/i-work-with"
            isAuthenticated={isAuth}
          >
            <CompaniesWhenIWorkPage />
          </PrivateRoute>
          <PrivateRoute
            exact
            path="/company/requests-sent"
            isAuthenticated={isAuth}
          >
            <CompanyRequestSendPage />
          </PrivateRoute>
          <PrivateRoute
            exact
            path="/company/requests-sent"
            isAuthenticated={isAuth}
          >
            <CompanyRequestSendPage />
          </PrivateRoute>
          <PrivateRoute
            exact
            path="/company/invitations-received"
            isAuthenticated={isAuth}
          >
            <CompanyInvitationsReceivedPage />
          </PrivateRoute>
          <PrivateRoute path="/company/view/:uuid" isAuthenticated={isAuth}>
            <CompanyViewPage />
          </PrivateRoute>
          <PrivateRoute path="/chat" isAuthenticated={isAuth}>
            <ChatPage />
          </PrivateRoute>
          <PrivateRoute path="/inmail/:uuid" isAuthenticated={isAuth}>
            <InmailPage />
          </PrivateRoute>
          <PrivateRoute path="/inmail" isAuthenticated={isAuth}>
            <InmailPage />
          </PrivateRoute>
          <PrivateRoute path="/marketplace" isAuthenticated={isAuth}>
            <MarketPlacePage />
          </PrivateRoute>
          <PrivateRoute path="/notifications" isAuthenticated={isAuth}>
            <NotificationsPage />
          </PrivateRoute>
          <PrivateRoute path="/search" isAuthenticated={isAuth}>
            <SearchPage />
          </PrivateRoute>
          <PrivateRoute
            path="/knowledge-area/view/:uuid"
            isAuthenticated={isAuth}
          >
            <KnowledgeViewPage />
          </PrivateRoute>
          <PrivateRoute path="/knowledge-area" isAuthenticated={isAuth}>
            <KnowledgeAreaPage />
          </PrivateRoute>
          <PrivateRoute path="/job/view/:uuid" isAuthenticated={isAuth}>
            <JobViewPage />
          </PrivateRoute>
          <PrivateRoute path="/post/:uuid" isAuthenticated={isAuth}>
            <PostViewPage />
          </PrivateRoute>
          <PrivateRoute path="/calendar" isAuthenticated={isAuth}>
            <CalendarPage />
          </PrivateRoute>
          <PrivateRoute
            path="/my-coach/questions/view/:uuid"
            isAuthenticated={isAuth}
          >
            <MyCoachViewPage />
          </PrivateRoute>
          <PrivateRoute exact path="/my-coach" isAuthenticated={isAuth}>
            <MyCoachPage />
          </PrivateRoute>

          <PrivateRoute
            exact
            path="/signin/impersonate"
            isAuthenticated={isAuth}
          >
            <ImpersonatePage />
          </PrivateRoute>

          {/* Authorization routes */}
          <AuthRoute path="/" isAuthenticated={isAuth}>
            <SigninPage />
          </AuthRoute>
          {/* <AuthRoute exact path="/signin" isAuthenticated={isAuth}>
            <SigninPage />
          </AuthRoute>
          <AuthRoute exact path="/signup" isAuthenticated={isAuth}>
            <SignupPage />
          </AuthRoute>
          <AuthRoute exact path="/reset-password" isAuthenticated={isAuth}>
            <ResetPasswordPage />
          </AuthRoute>
          <AuthRoute exact path="/forgot-password" isAuthenticated={isAuth}>
            <ForgotPasswordPage />
          </AuthRoute> */}
        </Switch>
      </Suspense>

      <NotificationAlert />
      {isAuth ? <ChatHelper /> : null}
    </Router>
  )
}

export default AppRouter