Bridge.tsx 3.0 KB

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