DeleteTransferModal.tsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. Copyright (C) 2020 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 { observer } from "mobx-react";
  15. import React from "react";
  16. import styled from "styled-components";
  17. import { ThemePalette } from "@src/components/Theme";
  18. import Button from "@src/components/ui/Button";
  19. import Modal from "@src/components/ui/Modal";
  20. import StatusImage from "@src/components/ui/StatusComponents/StatusImage";
  21. const Wrapper = styled.div<any>`
  22. display: flex;
  23. flex-direction: column;
  24. align-items: center;
  25. justify-content: center;
  26. padding: 48px;
  27. `;
  28. const Message = styled.div<any>`
  29. font-size: 18px;
  30. text-align: center;
  31. margin-top: 48px;
  32. `;
  33. const ExtraMessage = styled.div<any>`
  34. color: ${ThemePalette.grayscale[4]};
  35. margin: 11px 0 48px 0;
  36. text-align: center;
  37. font-size: 12px;
  38. `;
  39. const Buttons = styled.div<any>`
  40. display: flex;
  41. justify-content: space-between;
  42. width: 100%;
  43. align-items: flex-end;
  44. `;
  45. const ButtonsColumn = styled.div<any>`
  46. display: flex;
  47. flex-direction: column;
  48. `;
  49. const Loading = styled.div`
  50. display: flex;
  51. flex-direction: column;
  52. align-items: center;
  53. margin: 64px;
  54. `;
  55. const LoadingMessage = styled.div`
  56. max-width: 100%;
  57. overflow: auto;
  58. margin-top: 48px;
  59. text-align: center;
  60. `;
  61. const LoadingTitle = styled.div`
  62. font-size: 18px;
  63. margin-bottom: 8px;
  64. `;
  65. const LoadingSubtitle = styled.div<any>`
  66. color: ${ThemePalette.grayscale[4]};
  67. `;
  68. type Props = {
  69. hasDisks: boolean;
  70. isMultiTransferSelection?: boolean;
  71. loading?: boolean;
  72. onDeleteTransfer: () => void;
  73. onDeleteDisks: () => void;
  74. onRequestClose: () => void;
  75. };
  76. @observer
  77. class DeleteTransferModal extends React.Component<Props> {
  78. renderExtraMessage() {
  79. if (this.props.hasDisks) {
  80. if (this.props.isMultiTransferSelection) {
  81. return (
  82. <ExtraMessage>
  83. Some of the selected Transfer have been executed at least once and
  84. thus may have disks created on the destination platform. If those
  85. Transfers are to be deleted now, the disks on the destination will
  86. persist. If this is not desired, please use the &quot;Delete Transfer
  87. Disks&quot; option to delete those disks before deleting the
  88. Transfers themselves.
  89. </ExtraMessage>
  90. );
  91. }
  92. return (
  93. <ExtraMessage>
  94. This Transfer has been executed at least once and thus may have disks
  95. created on the destination platform. If the Transfer is to be deleted
  96. now, the disks on the destination will persist. If this is not
  97. desired, please use the &quot;Delete Transfer Disks&quot; option to
  98. delete the disks before deleting the Transfer itself.
  99. </ExtraMessage>
  100. );
  101. }
  102. return (
  103. <ExtraMessage>Deleting a Coriolis Transfer is permanent!</ExtraMessage>
  104. );
  105. }
  106. renderLoading() {
  107. return (
  108. <Loading>
  109. <StatusImage loading />
  110. <LoadingMessage>
  111. <LoadingTitle>Validating Transfer Details</LoadingTitle>
  112. <LoadingSubtitle>Please wait ...</LoadingSubtitle>
  113. </LoadingMessage>
  114. </Loading>
  115. );
  116. }
  117. renderContent() {
  118. const message = this.props.isMultiTransferSelection
  119. ? "Are you sure you want to delete the selected transfers?"
  120. : "Are you sure you want to delete this transfer?";
  121. return (
  122. <Wrapper>
  123. <StatusImage status="QUESTION" />
  124. <Message>{message}</Message>
  125. {this.renderExtraMessage()}
  126. <Buttons>
  127. <Button secondary onClick={this.props.onRequestClose}>
  128. Cancel
  129. </Button>
  130. <ButtonsColumn>
  131. {this.props.hasDisks ? (
  132. <Button
  133. onClick={this.props.onDeleteDisks}
  134. hollow
  135. style={{ marginBottom: "16px" }}
  136. alert
  137. >
  138. Delete Transfer Disks
  139. </Button>
  140. ) : null}
  141. <Button onClick={this.props.onDeleteTransfer} alert>
  142. Delete Transfer{this.props.isMultiTransferSelection ? "s" : ""}
  143. </Button>
  144. </ButtonsColumn>
  145. </Buttons>
  146. </Wrapper>
  147. );
  148. }
  149. render() {
  150. const title = this.props.isMultiTransferSelection
  151. ? "Delete Selected Transfers?"
  152. : "Delete Transfer?";
  153. return (
  154. <Modal isOpen title={title} onRequestClose={this.props.onRequestClose}>
  155. {this.props.loading ? this.renderLoading() : this.renderContent()}
  156. </Modal>
  157. );
  158. }
  159. }
  160. export default DeleteTransferModal;