import { History } from 'history' ; import React from 'react' ; import ThemeProvider from 'design/ThemeProvider' ; import { Router , Route , Switch } from 'teleport/components/Router' ; import CatchError from 'teleport/components/CatchError' ; import Authenticated from 'teleport/components/Authenticated' ; import Main from './Main' ; import Welcome from './Welcome' ; import Login , { LoginSuccess , LoginFailed } from './Login' ; import AppLauncher from './AppLauncher' ; import Console from './Console' ; import DesktopSession from './DesktopSession' ; import Player from './Player' ; import TeleportContextProvider from './teleportContextProvider' ; import TeleportContext from './teleportContext' ; import cfg from './config' ; const Teleport = props => { const { ctx , history } = props ; const publicRoutes = props . renderPublicRoutes || renderPublicRoutes ; const privateRoutes = props . renderPrivateRoutes || renderPrivateRoutes ; return ( < CatchError > < ThemeProvider > < Router history = { history } > < Switch > { publicRoutes ( ) } < Route path = { cfg . routes . root } > < Authenticated > < TeleportContextProvider ctx = { ctx } > < Switch > < Route path = { cfg . routes . appLauncher } component = { AppLauncher } / > < Route > { privateRoutes ( ) } < /Route> < /Switch> < /TeleportContextProvider> < /Authenticated> < /Route> < /Switch> < /Router> < /ThemeProvider> < /CatchError>); } ; export function renderPublicRoutes ( children = [ ] ) { return [ ... children , < Route key = { 1 } title = "Login Failed" path = { cfg . routes . loginError } component = { LoginFailed } / > , < Route key = { 2 } title = "Login Failed" path = { cfg . routes . loginErrorLegacy } component = { LoginFailed } / > , < Route key = { 3 } title = "Login" path = { cfg . routes . login } component = { Login } / > , < Route key = { 4 } title = "Success" path = { cfg . routes . loginSuccess } component = { LoginSuccess } / > , < Route key = { 5 } title = "Invite" path = { cfg . routes . userInvite } component = { Welcome } / > , < Route key = { 6 } title = "Password Reset" path = { cfg . routes . userReset } component = { Welcome } / > , ] ; } export function renderPrivateRoutes ( CustomMain = Main ) { return ( < Switch > < Route path = { cfg . routes . desktop } component = { DesktopSession } / > < Route path = { cfg . routes . console } component = { Console } / > < Route path = { cfg . routes . player } component = { Player } / > < Route path = { cfg . routes . root } component = { CustomMain } / > < /Switch>); } export default Teleport ; export type Props = { ctx : TeleportContext ; history : History ; renderPublicRoutes ? ( children ? ) : JSX . Element [ ] ; renderPrivateRoutes ? ( CustomMain ? ) : JSX . Element ; } ;