NotificationSettingContents.jsx 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { withTranslation } from 'react-i18next';
  4. import {
  5. TabContent, TabPane, Nav, NavItem, NavLink,
  6. } from 'reactstrap';
  7. import { withUnstatedContainers } from '../../UnstatedUtils';
  8. import AppContainer from '../../../services/AppContainer';
  9. import AdminNotificationContainer from '../../../services/AdminNotificationContainer';
  10. import SlackAppConfiguration from './SlackAppConfiguration';
  11. import UserTriggerNotification from './UserTriggerNotification';
  12. import GlobalNotification from './GlobalNotification';
  13. class NotificationSettingContents extends React.Component {
  14. constructor(props) {
  15. super(props);
  16. this.state = {
  17. activeTab: 'slack-configuration',
  18. // Prevent unnecessary rendering
  19. activeComponents: new Set(['slack-configuration']),
  20. };
  21. this.toggleActiveTab = this.toggleActiveTab.bind(this);
  22. }
  23. toggleActiveTab(activeTab) {
  24. this.setState({
  25. activeTab, activeComponents: this.state.activeComponents.add(activeTab),
  26. });
  27. }
  28. render() {
  29. const { activeTab, activeComponents } = this.state;
  30. return (
  31. <React.Fragment>
  32. <Nav tabs>
  33. <NavItem>
  34. <NavLink
  35. className={`${activeTab === 'slack-configuration' && 'active'} `}
  36. onClick={() => { this.toggleActiveTab('slack-configuration') }}
  37. href="#slack-configuration"
  38. >
  39. <i className="icon-settings"></i> Slack configuration
  40. </NavLink>
  41. </NavItem>
  42. <NavItem>
  43. <NavLink
  44. className={`${activeTab === 'user-trigger-notification' && 'active'} `}
  45. onClick={() => { this.toggleActiveTab('user-trigger-notification') }}
  46. href="#user-trigger-notification"
  47. >
  48. <i className="icon-settings"></i> User trigger notification
  49. </NavLink>
  50. </NavItem>
  51. <NavItem>
  52. <NavLink
  53. className={`${activeTab === 'global-notification' && 'active'} `}
  54. onClick={() => { this.toggleActiveTab('global-notification') }}
  55. href="#global-notification"
  56. >
  57. <i className="icon-settings"></i> Global notification
  58. </NavLink>
  59. </NavItem>
  60. </Nav>
  61. <TabContent activeTab={activeTab}>
  62. <TabPane tabId="slack-configuration">
  63. {activeComponents.has('slack-configuration') && <SlackAppConfiguration />}
  64. </TabPane>
  65. <TabPane tabId="user-trigger-notification">
  66. {activeComponents.has('user-trigger-notification') && <UserTriggerNotification />}
  67. </TabPane>
  68. <TabPane tabId="global-notification">
  69. {activeComponents.has('global-notification') && <GlobalNotification />}
  70. </TabPane>
  71. </TabContent>
  72. </React.Fragment>
  73. );
  74. }
  75. }
  76. const NotificationSettingContentsWrapper = withUnstatedContainers(NotificationSettingContents, [AppContainer, AdminNotificationContainer]);
  77. NotificationSettingContents.propTypes = {
  78. t: PropTypes.func.isRequired, // i18next
  79. appContainer: PropTypes.instanceOf(AppContainer).isRequired,
  80. adminNotificationContainer: PropTypes.instanceOf(AdminNotificationContainer).isRequired,
  81. };
  82. export default withTranslation()(NotificationSettingContentsWrapper);