CurrentError.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 onClick={() => this.setState({ expanded: true })}>
  27. <ErrorText>Error: {this.props.currentError}</ErrorText>
  28. <CloseButton
  29. onClick={e => {
  30. this.context.setCurrentError(null);
  31. e.stopPropagation();
  32. }}
  33. >
  34. <CloseButtonImg src={close} />
  35. </CloseButton>
  36. </StyledCurrentError>
  37. );
  38. }
  39. return (
  40. <ExpandedError onClick={() => this.setState({ expanded: false })}>
  41. Error: {this.props.currentError}
  42. <CloseButtonAlt onClick={() => this.context.setCurrentError(null)}>
  43. <CloseButtonImg src={close} />
  44. </CloseButtonAlt>
  45. </ExpandedError>
  46. );
  47. }
  48. return null;
  49. }
  50. }
  51. CurrentError.contextType = Context;
  52. const CloseButton = styled.div`
  53. display: flex;
  54. align-items: center;
  55. justify-content: center;
  56. width: 30px;
  57. height: 30px;
  58. border-radius: 50%;
  59. margin-left: 10px;
  60. cursor: pointer;
  61. :hover {
  62. background-color: #ffffff11;
  63. }
  64. `;
  65. const CloseButtonAlt = styled(CloseButton)`
  66. position: absolute;
  67. top: 5px;
  68. right: 5px;
  69. `;
  70. const CloseButtonImg = styled.img`
  71. width: 10px;
  72. `;
  73. const ErrorText = styled.div`
  74. white-space: nowrap;
  75. overflow: hidden;
  76. text-overflow: ellipsis;
  77. width: calc(100% - 50px);
  78. `;
  79. const StyledCurrentError = styled.div`
  80. position: fixed;
  81. bottom: 22px;
  82. width: 300px;
  83. left: 20px;
  84. padding: 15px;
  85. padding-right: 0px;
  86. font-family: "Work Sans", sans-serif;
  87. height: 50px;
  88. font-size: 13px;
  89. border-radius: 3px;
  90. background: #272731cc;
  91. border: 1px solid #ffffff55;
  92. display: flex;
  93. align-items: center;
  94. color: #ffffff;
  95. > i {
  96. font-size: 18px;
  97. margin-right: 10px;
  98. }
  99. animation: floatIn 0.5s;
  100. animation-fill-mode: forwards;
  101. @keyframes floatIn {
  102. from {
  103. opacity: 0;
  104. transform: translateY(20px);
  105. }
  106. to {
  107. opacity: 1;
  108. transform: translateY(0px);
  109. }
  110. }
  111. `;
  112. const ExpandedError = styled(StyledCurrentError)`
  113. width: 500px;
  114. height: auto;
  115. max-height: 300px;
  116. padding: 20px;
  117. overflow-y: auto;
  118. `;