AboutModal.jsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. Copyright (C) 2019 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 apiCaller from '../../../utils/ApiCaller'
  19. import logger from '../../../utils/ApiLogger'
  20. import Modal from '../../molecules/Modal/Modal'
  21. import LicenceComponent from '../../organisms/Licence'
  22. import Palette from '../../styleUtils/Palette'
  23. import StyleProps from '../../styleUtils/StyleProps'
  24. import licenceStore from '../../../stores/LicenceStore'
  25. import logoImage from './images/coriolis-logo.svg'
  26. const Wrapper = styled.div`
  27. display: flex;
  28. flex-direction: column;
  29. align-items: center;
  30. justify-content: center;
  31. padding: 60px 0 32px 0;
  32. position: relative;
  33. height: 100%;
  34. min-height: 0;
  35. `
  36. const Gradient = styled.div`
  37. position: absolute;
  38. height: 100%;
  39. max-height: 230px;
  40. top: 0;
  41. width: 100%;
  42. background: linear-gradient(#A7B0CA, #FFFFFF);
  43. `
  44. const Content = styled.div`
  45. z-index: 1;
  46. display: flex;
  47. flex-direction: column;
  48. align-items: center;
  49. width: 100%;
  50. height: 100%;
  51. min-height: 0;
  52. `
  53. const AboutContentWrapper = styled.div``
  54. const Logo = styled.div`
  55. width: 362px;
  56. ${StyleProps.exactHeight('71px')}
  57. background: url('${logoImage}') center no-repeat;
  58. `
  59. const Text = styled.div`
  60. margin: 48px 0;
  61. color: ${Palette.grayscale[5]};
  62. font-size: 12px;
  63. `
  64. const TextLine = styled.div`
  65. display: flex;
  66. justify-content: center;
  67. margin-left: -6px;
  68. margin-top: 8px;
  69. &:first-child {
  70. margin-top: 0;
  71. }
  72. span, a {
  73. margin-left: 6px;
  74. }
  75. `
  76. const LinkMock = styled.span`
  77. text-decoration: underline;
  78. cursor: pointer;
  79. `
  80. type Props = {
  81. onRequestClose: () => void,
  82. }
  83. type State = {
  84. version: string,
  85. licenceAddMode: boolean,
  86. }
  87. @observer
  88. class AboutModal extends React.Component<Props, State> {
  89. state = {
  90. version: '-',
  91. licenceAddMode: false,
  92. }
  93. componentWillMount() {
  94. apiCaller.get('/version').then(res => {
  95. this.setState({ version: res.data.version })
  96. })
  97. licenceStore.loadLicenceInfo()
  98. }
  99. async handleAddLicence(licence: string) {
  100. await licenceStore.addLicence(licence)
  101. licenceStore.loadLicenceInfo()
  102. this.setState({ licenceAddMode: false })
  103. }
  104. render() {
  105. return (
  106. <Modal
  107. title="About"
  108. isOpen
  109. onRequestClose={() => { this.props.onRequestClose() }}
  110. >
  111. <Wrapper>
  112. {!this.state.licenceAddMode ? <Gradient /> : null}
  113. <Content>
  114. {!this.state.licenceAddMode ? (
  115. <AboutContentWrapper>
  116. <Logo />
  117. <Text>
  118. <TextLine>
  119. <span>Version {this.state.version}</span>
  120. <span>|</span>
  121. <LinkMock onClick={() => { logger.download() }} >Download Log</LinkMock>
  122. </TextLine>
  123. <TextLine>
  124. © {new Date().getFullYear()} Cloudbase Solutions. All Rights Reserved.
  125. </TextLine>
  126. </Text>
  127. </AboutContentWrapper>
  128. ) : null}
  129. <LicenceComponent
  130. licenceInfo={licenceStore.licenceInfo}
  131. loadingLicenceInfo={licenceStore.loadingLicenceInfo}
  132. onRequestClose={this.props.onRequestClose}
  133. addMode={this.state.licenceAddMode}
  134. onAddModeChange={licenceAddMode => { this.setState({ licenceAddMode }) }}
  135. onAddLicence={licence => { this.handleAddLicence(licence) }}
  136. addingLicence={licenceStore.addingLicence}
  137. />
  138. </Content>
  139. </Wrapper>
  140. </Modal>
  141. )
  142. }
  143. }
  144. export default AboutModal