EndpointDuplicateOptions.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. import React from 'react'
  15. import { observer } from 'mobx-react'
  16. import styled from 'styled-components'
  17. import StatusImage from '@src/components/ui/StatusComponents/StatusImage'
  18. import Button from '@src/components/ui/Button'
  19. import FieldInput from '@src/components/ui/FieldInput'
  20. import KeyboardManager from '@src/utils/KeyboardManager'
  21. import type { Project } from '@src/@types/Project'
  22. import { ThemePalette } from '@src/components/Theme'
  23. import duplicateImage from './images/duplicate.svg'
  24. const Wrapper = styled.div<any>`
  25. display: flex;
  26. flex-direction: column;
  27. align-items: center;
  28. padding: 0 32px 32px 32px;
  29. `
  30. const Options = styled.div<any>`
  31. display: flex;
  32. flex-direction: column;
  33. align-items: center;
  34. width: 100%;
  35. `
  36. const Image = styled.div<any>`
  37. margin-top: 48px;
  38. margin-bottom: 80px;
  39. width: 128px;
  40. height: 96px;
  41. background: url('${duplicateImage}') no-repeat center;
  42. `
  43. const Message = styled.div<any>`
  44. margin-top: 48px;
  45. text-align: center;
  46. `
  47. const Title = styled.div<any>`
  48. font-size: 18px;
  49. margin-bottom: 8px;
  50. `
  51. const Subtitle = styled.div<any>`
  52. color: ${ThemePalette.grayscale[4]};
  53. `
  54. const Form = styled.div<any>`
  55. margin-bottom: 128px;
  56. `
  57. const Loading = styled.div<any>`
  58. display: flex;
  59. flex-direction: column;
  60. align-items: center;
  61. margin-top: 32px;
  62. `
  63. const Buttons = styled.div<any>`
  64. display: flex;
  65. justify-content: space-between;
  66. width: 100%;
  67. `
  68. const FieldInputStyled = styled(FieldInput)`
  69. width: 319px;
  70. justify-content: space-between;
  71. `
  72. type Props = {
  73. projects: Project[],
  74. selectedProjectId: string,
  75. duplicating: boolean,
  76. onCancelClick: () => void,
  77. onDuplicateClick: (projectId: string) => void,
  78. }
  79. type State = {
  80. selectedProjectId: string,
  81. }
  82. @observer
  83. class EndpointDuplicateOptions extends React.Component<Props, State> {
  84. UNSAFE_componentWillMount() {
  85. this.setState({ selectedProjectId: this.props.selectedProjectId })
  86. }
  87. componentDidMount() {
  88. KeyboardManager.onEnter('duplicate-options', () => {
  89. this.props.onDuplicateClick(this.state.selectedProjectId)
  90. }, 2)
  91. }
  92. componentWillUnmount() {
  93. KeyboardManager.removeKeyDown('duplicate-options')
  94. }
  95. renderDuplicating() {
  96. return (
  97. <Loading>
  98. <StatusImage loading />
  99. <Message>
  100. <Title>Duplicating Endpoint</Title>
  101. <Subtitle>Please wait ...</Subtitle>
  102. </Message>
  103. </Loading>
  104. )
  105. }
  106. renderOptions() {
  107. return (
  108. <Options>
  109. <Image />
  110. <Form>
  111. <FieldInputStyled
  112. name="duplicate_to_project"
  113. label="Duplicate To Project"
  114. type="string"
  115. enum={this.props.projects}
  116. value={this.state.selectedProjectId}
  117. onChange={projectId => { this.setState({ selectedProjectId: projectId }) }}
  118. width={318}
  119. layout="page"
  120. />
  121. </Form>
  122. <Buttons>
  123. <Button secondary onClick={this.props.onCancelClick}>Cancel</Button>
  124. <Button
  125. onClick={() => { this.props.onDuplicateClick(this.state.selectedProjectId) }}
  126. >Duplicate
  127. </Button>
  128. </Buttons>
  129. </Options>
  130. )
  131. }
  132. render() {
  133. return (
  134. <Wrapper>
  135. {this.props.duplicating ? this.renderDuplicating() : this.renderOptions()}
  136. </Wrapper>
  137. )
  138. }
  139. }
  140. export default EndpointDuplicateOptions