Bridge.jsx 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import React from 'react';
  2. import { useTranslation } from 'next-i18next';
  3. import PropTypes from 'prop-types';
  4. import { UncontrolledTooltip } from 'reactstrap';
  5. const ProxyCircle = () => (
  6. <div className="grw-bridge-proxy-circle">
  7. <div className="circle position-absolute bg-primary border-light rounded-circle">
  8. <p className="circle-inner text-light font-weight-bold d-none d-lg-inline">Proxy Server</p>
  9. <p className="circle-inner grw-proxy-server-name d-block d-lg-none">Proxy Server</p>
  10. </div>
  11. </div>
  12. );
  13. const BridgeCore = (props) => {
  14. const {
  15. description, iconClass, hrClass, withProxy,
  16. } = props;
  17. return (
  18. <>
  19. <div id="grw-bridge-container" className={`grw-bridge-container ${withProxy ? 'with-proxy' : ''}`}>
  20. <p className={`${withProxy ? 'mt-0' : 'mt-2'}`}>
  21. <i className={iconClass} />
  22. <small
  23. className="ml-2 d-none d-lg-inline"
  24. // eslint-disable-next-line react/no-danger
  25. dangerouslySetInnerHTML={{ __html: description }}
  26. />
  27. </p>
  28. <div className="hr-container">
  29. { withProxy && <ProxyCircle /> }
  30. <hr className={`align-self-center ${hrClass}`} />
  31. </div>
  32. </div>
  33. <UncontrolledTooltip placement="top" fade={false} target="grw-bridge-container" className="d-block d-lg-none">
  34. <small
  35. // eslint-disable-next-line react/no-danger
  36. dangerouslySetInnerHTML={{ __html: description }}
  37. />
  38. </UncontrolledTooltip>
  39. </>
  40. );
  41. };
  42. BridgeCore.propTypes = {
  43. description: PropTypes.string.isRequired,
  44. iconClass: PropTypes.string.isRequired,
  45. hrClass: PropTypes.string.isRequired,
  46. withProxy: PropTypes.bool,
  47. };
  48. const Bridge = (props) => {
  49. const { t } = useTranslation();
  50. const { errorCount, totalCount, withProxy } = props;
  51. let description;
  52. let iconClass;
  53. let hrClass;
  54. // empty or all failed
  55. if (totalCount === 0 || errorCount === totalCount) {
  56. description = t('admin:slack_integration.integration_sentence.integration_is_not_complete');
  57. iconClass = 'icon-info text-danger';
  58. hrClass = 'border-danger admin-border-failed';
  59. }
  60. // all green
  61. else if (errorCount === 0) {
  62. description = t('admin:slack_integration.integration_sentence.integration_successful');
  63. iconClass = 'fa fa-check text-success';
  64. hrClass = 'border-success admin-border-success';
  65. }
  66. // some of them failed
  67. else {
  68. description = t('admin:slack_integration.integration_sentence.integration_some_ws_is_not_complete');
  69. iconClass = 'fa fa-check text-warning';
  70. hrClass = 'border-warning admin-border-failed';
  71. }
  72. return (
  73. <BridgeCore
  74. description={description}
  75. iconClass={iconClass}
  76. hrClass={hrClass}
  77. withProxy={withProxy}
  78. />
  79. );
  80. };
  81. Bridge.propTypes = {
  82. errorCount: PropTypes.number.isRequired,
  83. totalCount: PropTypes.number.isRequired,
  84. withProxy: PropTypes.bool,
  85. };
  86. export default Bridge;