AboutModal.jsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 Link = styled.a`
  77. color: inherit;
  78. `
  79. const LinkMock = styled.span`
  80. text-decoration: underline;
  81. cursor: pointer;
  82. `
  83. type Props = {
  84. onRequestClose: () => void,
  85. }
  86. type State = {
  87. version: string,
  88. licenceAddMode: boolean,
  89. }
  90. @observer
  91. class AboutModal extends React.Component<Props, State> {
  92. state = {
  93. version: '-',
  94. licenceAddMode: false,
  95. }
  96. componentWillMount() {
  97. apiCaller.get('/version').then(res => {
  98. this.setState({ version: res.data.version })
  99. })
  100. licenceStore.loadLicenceInfo()
  101. }
  102. async handleAddLicence(licence: string) {
  103. await licenceStore.addLicence(licence)
  104. licenceStore.loadLicenceInfo()
  105. this.setState({ licenceAddMode: false })
  106. }
  107. render() {
  108. return (
  109. <Modal
  110. title="About"
  111. isOpen
  112. onRequestClose={() => { this.props.onRequestClose() }}
  113. >
  114. <Wrapper>
  115. {!this.state.licenceAddMode ? <Gradient /> : null}
  116. <Content>
  117. {!this.state.licenceAddMode ? (
  118. <AboutContentWrapper>
  119. <Logo />
  120. <Text>
  121. <TextLine>
  122. <span>Version {this.state.version}</span>
  123. <span>|</span>
  124. <Link href="https://github.com/cloudbase/coriolis/issues" target="_blank">Report an Issue</Link>
  125. <span>|</span>
  126. <LinkMock onClick={() => { logger.download() }} >Download Log</LinkMock>
  127. </TextLine>
  128. <TextLine>
  129. © {new Date().getFullYear()} Cloudbase Solutions. All Rights Reserved.
  130. </TextLine>
  131. </Text>
  132. </AboutContentWrapper>
  133. ) : null}
  134. <LicenceComponent
  135. licenceInfo={licenceStore.licenceInfo}
  136. loadingLicenceInfo={licenceStore.loadingLicenceInfo}
  137. onRequestClose={this.props.onRequestClose}
  138. addMode={this.state.licenceAddMode}
  139. onAddModeChange={licenceAddMode => { this.setState({ licenceAddMode }) }}
  140. onAddLicence={licence => { this.handleAddLicence(licence) }}
  141. addingLicence={licenceStore.addingLicence}
  142. />
  143. </Content>
  144. </Wrapper>
  145. </Modal>
  146. )
  147. }
  148. }
  149. export default AboutModal