Bridge.tsx 3.1 KB

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