Navigation.jsx 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 { observer } from 'mobx-react'
  17. import styled from 'styled-components'
  18. import Logo from '../../atoms/Logo'
  19. import userStore from '../../../stores/UserStore'
  20. import { navigationMenu } from '../../../config'
  21. import backgroundImage from './images/star-bg.jpg'
  22. const Wrapper = styled.div`
  23. background-image: url('${backgroundImage}');
  24. display: flex;
  25. flex-direction: column;
  26. height: 100%;
  27. `
  28. const LogoStyled = styled(Logo)`
  29. margin: 40px auto 0 30px;
  30. cursor: pointer;
  31. `
  32. const Menu = styled.div`
  33. display: flex;
  34. flex-direction: column;
  35. margin-top:32px;
  36. `
  37. const MenuItem = styled.a`
  38. font-size: 18px;
  39. color: ${props => props.selected ? '#007AFF' : 'white'};
  40. cursor: pointer;
  41. margin-top: 26px;
  42. margin-left: 96px;
  43. display: inline-block;
  44. text-decoration: none;
  45. `
  46. const Footer = styled.div``
  47. @observer
  48. class Navigation extends React.Component<{ currentPage: string }> {
  49. renderMenu() {
  50. const isAdmin = userStore.loggedUser ? userStore.loggedUser.isAdmin : false
  51. return (
  52. <Menu>
  53. {
  54. // $FlowIgnore
  55. navigationMenu.filter(i => i.disabled ? !i.disabled : i.requiresAdmin ? isAdmin : true).map(item => {
  56. return (
  57. <MenuItem
  58. key={item.value}
  59. selected={this.props.currentPage === item.value}
  60. href={`/#/${item.value}`}
  61. data-test-id={`navigation-item-${item.value}`}
  62. >{item.label}</MenuItem>
  63. )
  64. })}
  65. </Menu>
  66. )
  67. }
  68. render() {
  69. return (
  70. <Wrapper>
  71. <LogoStyled small href={navigationMenu[0].value} />
  72. {this.renderMenu()}
  73. <Footer />
  74. </Wrapper>
  75. )
  76. }
  77. }
  78. export default Navigation