CurrentError.tsx 4.5 KB

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