App.jsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. Copyright (C) 2017 Cloudbase Solutions SRL
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. // @flow
  15. import React from 'react'
  16. import { Switch, Route } from 'react-router-dom'
  17. import styled, { injectGlobal } from 'styled-components'
  18. import Fonts from './atoms/Fonts'
  19. import Notifications from './organisms/Notifications'
  20. import LoginPage from './pages/LoginPage'
  21. import ReplicasPage from './pages/ReplicasPage'
  22. import NotFoundPage from './pages/NotFoundPage'
  23. import ReplicaDetailsPage from './pages/ReplicaDetailsPage'
  24. import MigrationsPage from './pages/MigrationsPage'
  25. import MigrationDetailsPage from './pages/MigrationDetailsPage'
  26. import EndpointsPage from './pages/EndpointsPage'
  27. import EndpointDetailsPage from './pages/EndpointDetailsPage'
  28. import WizardPage from './pages/WizardPage'
  29. import userStore from '../stores/UserStore'
  30. import AssessmentsPage from './pages/AssessmentsPage'
  31. import AssessmentDetailsPage from './pages/AssessmentDetailsPage'
  32. import UsersPage from './pages/UsersPage'
  33. import UserDetailsPage from './pages/UserDetailsPage'
  34. import ProjectsPage from './pages/ProjectsPage'
  35. import ProjectDetailsPage from './pages/ProjectDetailsPage'
  36. import { navigationMenu } from '../config'
  37. import Palette from './styleUtils/Palette'
  38. import StyleProps from './styleUtils/StyleProps'
  39. injectGlobal`
  40. ${Fonts}
  41. body {
  42. margin: 0;
  43. color: ${Palette.black};
  44. font-family: Rubik;
  45. font-size: 14px;
  46. font-weight: ${StyleProps.fontWeights.regular};
  47. -webkit-font-smoothing: antialiased;
  48. -moz-osx-font-smoothing: grayscale;
  49. min-width: 1240px;
  50. }
  51. `
  52. const Wrapper = styled.div``
  53. class App extends React.Component<{}> {
  54. componentWillMount() {
  55. userStore.tokenLogin()
  56. }
  57. render() {
  58. let renderOptionalPage = (name: string, component: any, path?: string, exact?: boolean) => {
  59. const isAdmin = userStore.loggedUser ? userStore.loggedUser.isAdmin : true
  60. // $FlowIgnore
  61. if (navigationMenu.find(m => m.value === name && !m.disabled && (!m.requiresAdmin || isAdmin))) {
  62. return <Route path={`${path || `/${name}`}`} component={component} exact={exact} />
  63. }
  64. return null
  65. }
  66. return (
  67. <Wrapper>
  68. <Switch>
  69. <Route path="/" component={LoginPage} exact />
  70. <Route path="/login" component={LoginPage} />
  71. <Route path="/replicas" component={ReplicasPage} />
  72. <Route path="/replica/:id" component={ReplicaDetailsPage} exact />
  73. <Route path="/replica/:page/:id" component={ReplicaDetailsPage} />
  74. <Route path="/migrations" component={MigrationsPage} />
  75. <Route path="/migration/:id" component={MigrationDetailsPage} exact />
  76. <Route path="/migration/:page/:id" component={MigrationDetailsPage} />
  77. <Route path="/endpoints" component={EndpointsPage} />
  78. <Route path="/endpoint/:id" component={EndpointDetailsPage} />
  79. <Route path="/wizard/:type" component={WizardPage} />
  80. {renderOptionalPage('planning', AssessmentsPage)}
  81. {renderOptionalPage('planning', AssessmentDetailsPage, '/assessment/:info')}
  82. {renderOptionalPage('users', UsersPage)}
  83. {renderOptionalPage('users', UserDetailsPage, '/user/:id', true)}
  84. {renderOptionalPage('projects', ProjectsPage)}
  85. {renderOptionalPage('projects', ProjectDetailsPage, '/project/:id', true)}
  86. <Route component={NotFoundPage} />
  87. </Switch>
  88. <Notifications />
  89. </Wrapper>
  90. )
  91. }
  92. }
  93. export default App