CurrentError.tsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. import React, { Component } from "react";
  2. import styled from "styled-components";
  3. import close from "assets/close.png";
  4. import { Context } from "shared/Context";
  5. type PropsType = {
  6. currentError: string;
  7. };
  8. type StateType = {};
  9. export default class CurrentError extends Component<PropsType, StateType> {
  10. state = {
  11. expanded: false,
  12. };
  13. componentDidUpdate(prevProps: PropsType) {
  14. if (
  15. prevProps.currentError !== this.props.currentError &&
  16. this.props.currentError ===
  17. "Provisioning failed. Check your credentials and try again."
  18. ) {
  19. this.setState({ expanded: true });
  20. }
  21. }
  22. render() {
  23. let currentError = this.props.currentError;
  24. if (!React.isValidElement(this.props.currentError)) {
  25. currentError = String(this.props.currentError);
  26. }
  27. if (this.props.currentError) {
  28. if (!this.state.expanded) {
  29. return (
  30. <StyledCurrentError>
  31. <ErrorText>Error: {currentError}</ErrorText>
  32. <ExpandButton onClick={() => this.setState({ expanded: true })}>
  33. <i className="material-icons">launch</i>
  34. </ExpandButton>
  35. <CloseButton
  36. onClick={(e) => {
  37. e.stopPropagation();
  38. this.setState({ expanded: false }, () => {
  39. this.context.setCurrentError(null);
  40. });
  41. }}
  42. >
  43. <CloseButtonImg src={close} />
  44. </CloseButton>
  45. </StyledCurrentError>
  46. );
  47. }
  48. return (
  49. <Overlay>
  50. <ExpandedError>
  51. Porter encountered an error. Full error log:
  52. <CodeBlock>{currentError}</CodeBlock>
  53. <ExpandButtonAlt onClick={() => this.setState({ expanded: false })}>
  54. <i className="material-icons">remove</i>
  55. </ExpandButtonAlt>
  56. <CloseButtonAlt
  57. onClick={(e) => {
  58. e.stopPropagation();
  59. this.setState({ expanded: false }, () => {
  60. this.context.setCurrentError(null);
  61. });
  62. }}
  63. >
  64. <CloseButtonImg src={close} />
  65. </CloseButtonAlt>
  66. </ExpandedError>
  67. </Overlay>
  68. );
  69. }
  70. return null;
  71. }
  72. }
  73. CurrentError.contextType = Context;
  74. const CloseButton = styled.div`
  75. display: flex;
  76. align-items: center;
  77. justify-content: center;
  78. width: 30px;
  79. height: 30px;
  80. border-radius: 50%;
  81. cursor: pointer;
  82. :hover {
  83. background-color: #ffffff11;
  84. }
  85. `;
  86. const CloseButtonAlt = styled(CloseButton)`
  87. position: absolute;
  88. top: 5px;
  89. right: 5px;
  90. `;
  91. const CloseButtonImg = styled.img`
  92. width: 10px;
  93. `;
  94. const ErrorText = styled.div`
  95. white-space: nowrap;
  96. overflow: hidden;
  97. text-overflow: ellipsis;
  98. width: calc(100% - 80px);
  99. `;
  100. const StyledCurrentError = styled.div`
  101. position: fixed;
  102. bottom: 22px;
  103. width: 310px;
  104. left: 20px;
  105. padding: 15px;
  106. padding-right: 0px;
  107. font-family: "Work Sans", sans-serif;
  108. height: 50px;
  109. font-size: 13px;
  110. border-radius: 3px;
  111. background: #272731cc;
  112. border: 1px solid #ffffff55;
  113. display: flex;
  114. align-items: center;
  115. color: #ffffff;
  116. > i {
  117. font-size: 18px;
  118. margin-right: 10px;
  119. }
  120. animation: floatIn 0.5s;
  121. animation-fill-mode: forwards;
  122. @keyframes floatIn {
  123. from {
  124. opacity: 0;
  125. transform: translateY(20px);
  126. }
  127. to {
  128. opacity: 1;
  129. transform: translateY(0px);
  130. }
  131. }
  132. `;
  133. const ExpandButton = styled(CloseButton)`
  134. display: flex;
  135. width: 30px;
  136. height: 30px;
  137. border-radius: 50%;
  138. cursor: pointer;
  139. :hover {
  140. background-color: #ffffff11;
  141. }
  142. > i {
  143. font-size: 16px;
  144. }
  145. `;
  146. const ExpandButtonAlt = styled(ExpandButton)`
  147. position: absolute;
  148. top: 5px;
  149. right: 34px;
  150. `;
  151. const Overlay = styled.div`
  152. position: fixed;
  153. margin: 0;
  154. padding: 0;
  155. top: 0;
  156. left: 0;
  157. width: 100%;
  158. height: 100%;
  159. background-color: rgba(0, 0, 0, 0.6);
  160. z-index: 3;
  161. display: flex;
  162. align-items: center;
  163. justify-content: center;
  164. `;
  165. const ExpandedError = styled.div`
  166. position: fixed;
  167. display: block;
  168. width: 700px;
  169. left: calc(50% - 350px);
  170. height: auto;
  171. max-height: 500px;
  172. top: 50%;
  173. transform: translateY(-50%);
  174. padding: 20px;
  175. overflow-y: auto;
  176. background: #272731;
  177. border: 1px solid #ffffff55;
  178. font-family: "Work Sans", sans-serif;
  179. font-size: 13px;
  180. border-radius: 12px;
  181. `;
  182. const CodeBlock = styled.span`
  183. display: block;
  184. background-color: #1b1d26;
  185. color: white;
  186. border-radius: 5px;
  187. font-family: monospace;
  188. user-select: text;
  189. max-height: 400px;
  190. width: 90%;
  191. margin-left: 5%;
  192. margin-top: 20px;
  193. overflow-x: hidden;
  194. overflow-y: auto;
  195. padding: 10px;
  196. overflow-wrap: break-word;
  197. `;