UpdateProjectModal.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. import React, { Component } from 'react';
  2. import styled from 'styled-components';
  3. import close from '../../../assets/close.png';
  4. import gradient from '../../../assets/gradient.jpg';
  5. import api from '../../../shared/api';
  6. import { Context } from '../../../shared/Context';
  7. import SaveButton from '../../../components/SaveButton';
  8. import InputRow from '../../../components/values-form/InputRow';
  9. import ConfirmOverlay from '../../../components/ConfirmOverlay';
  10. type PropsType = {
  11. };
  12. type StateType = {
  13. projectName: string,
  14. status: string | null,
  15. showDeleteOverlay: boolean
  16. };
  17. export default class UpdateProjectModal extends Component<PropsType, StateType> {
  18. state = {
  19. projectName: this.context.currentModalData.currentProject.name,
  20. status: null as string | null,
  21. showDeleteOverlay: false,
  22. };
  23. // TODO: Handle update to unmounted component
  24. handleDelete = () => {
  25. let { currentProject } = this.context;
  26. this.setState({ status: 'loading' });
  27. api.deleteProject('<token>', {}, { id: currentProject.id }, (err: any, res: any) => {
  28. if (err) {
  29. this.setState({ status: 'error' });
  30. // console.log(err)
  31. } else {
  32. this.context.setCurrentModal(null, null);
  33. this.context.setCurrentProject(null);
  34. this.setState({ status: 'successful', showDeleteOverlay: false });
  35. }
  36. });
  37. }
  38. render() {
  39. return (
  40. <StyledCreateProjectModal>
  41. <CloseButton onClick={() => {
  42. this.context.setCurrentModal(null, null);
  43. }}>
  44. <CloseButtonImg src={close} />
  45. </CloseButton>
  46. <ModalTitle>Project Settings</ModalTitle>
  47. <Subtitle>
  48. Project name
  49. </Subtitle>
  50. <InputWrapper>
  51. <ProjectIcon>
  52. <ProjectImage src={gradient} />
  53. <Letter>{this.state.projectName ? this.state.projectName[0].toUpperCase() : '-'}</Letter>
  54. </ProjectIcon>
  55. <InputRow
  56. disabled={true}
  57. type='string'
  58. value={this.state.projectName}
  59. setValue={(x: string) => this.setState({ projectName: x })}
  60. placeholder='ex: perspective-vortex'
  61. width='470px'
  62. />
  63. </InputWrapper>
  64. <SaveButton
  65. text='Delete Project'
  66. color='#b91133'
  67. onClick={() => this.setState({ showDeleteOverlay: true })}
  68. status={this.state.status}
  69. />
  70. <ConfirmOverlay
  71. show={this.state.showDeleteOverlay}
  72. message={`Are you sure you want to delete ${this.state.projectName}?`}
  73. onYes={this.handleDelete}
  74. onNo={() => this.setState({ showDeleteOverlay: false })}
  75. />
  76. </StyledCreateProjectModal>
  77. );
  78. }
  79. }
  80. UpdateProjectModal.contextType = Context;
  81. const Letter = styled.div`
  82. height: 100%;
  83. width: 100%;
  84. position: absolute;
  85. background: #00000028;
  86. top: 0;
  87. left: 0;
  88. display: flex;
  89. color: white;
  90. align-items: center;
  91. justify-content: center;
  92. `;
  93. const ProjectImage = styled.img`
  94. width: 100%;
  95. height: 100%;
  96. `;
  97. const ProjectIcon = styled.div`
  98. width: 25px;
  99. min-width: 25px;
  100. height: 25px;
  101. border-radius: 3px;
  102. overflow: hidden;
  103. position: relative;
  104. margin-right: 10px;
  105. font-weight: 400;
  106. margin-top: 14px;
  107. `;
  108. const InputWrapper = styled.div`
  109. display: flex;
  110. align-items: center;
  111. `;
  112. const Subtitle = styled.div`
  113. margin-top: 23px;
  114. font-family: 'Work Sans', sans-serif;
  115. font-size: 13px;
  116. color: #aaaabb;
  117. overflow: hidden;
  118. white-space: nowrap;
  119. text-overflow: ellipsis;
  120. margin-bottom: -10px;
  121. `;
  122. const ModalTitle = styled.div`
  123. margin: 0px 0px 13px;
  124. display: flex;
  125. flex: 1;
  126. font-family: 'Assistant';
  127. font-size: 18px;
  128. color: #ffffff;
  129. user-select: none;
  130. font-weight: 700;
  131. align-items: center;
  132. position: relative;
  133. white-space: nowrap;
  134. text-overflow: ellipsis;
  135. `;
  136. const CloseButton = styled.div`
  137. position: absolute;
  138. display: block;
  139. width: 40px;
  140. height: 40px;
  141. padding: 13px 0 12px 0;
  142. z-index: 1;
  143. text-align: center;
  144. border-radius: 50%;
  145. right: 15px;
  146. top: 12px;
  147. cursor: pointer;
  148. :hover {
  149. background-color: #ffffff11;
  150. }
  151. `;
  152. const CloseButtonImg = styled.img`
  153. width: 14px;
  154. margin: 0 auto;
  155. `;
  156. const StyledCreateProjectModal= styled.div`
  157. width: 100%;
  158. position: absolute;
  159. left: 0;
  160. top: 0;
  161. height: 100%;
  162. padding: 25px 32px;
  163. overflow: hidden;
  164. border-radius: 6px;
  165. background: #202227;
  166. `;