GlobalNotificationList.jsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { withTranslation } from 'react-i18next';
  4. import urljoin from 'url-join';
  5. import { createSubscribedElement } from '../../UnstatedUtils';
  6. import AppContainer from '../../../services/AppContainer';
  7. import AdminNotificationContainer from '../../../services/AdminNotificationContainer';
  8. import NotificationDeleteModal from './NotificationDeleteModal';
  9. class GlobalNotificationList extends React.Component {
  10. constructor(props) {
  11. super(props);
  12. this.state = {
  13. isNotificationDeleteModalShown: false,
  14. };
  15. this.toggleDeleteModal = this.toggleDeleteModal.bind(this);
  16. }
  17. toggleDeleteModal() {
  18. this.setState({ isNotificationDeleteModalShown: !this.state.isNotificationDeleteModalShown });
  19. }
  20. render() {
  21. const { t, adminNotificationContainer } = this.props;
  22. const { globalNotifications } = adminNotificationContainer.state;
  23. return (
  24. <React.Fragment>
  25. {globalNotifications.map((notification) => {
  26. return (
  27. <tr key={notification._id}>
  28. <td className="align-middle td-abs-center">
  29. {/* GW-807 switch enable notification */}
  30. <input type="checkbox" className="js-switch" data-size="small" data-id="{{ notification._id.toString() }}" />
  31. </td>
  32. <td>
  33. {notification.triggerPath}
  34. </td>
  35. <td>
  36. {notification.triggerEvents.includes('pageCreate') && (
  37. <span className="label label-success" data-toggle="tooltip" data-placement="top" title="Page Create">
  38. <i className="icon-doc"></i> CREATE
  39. </span>
  40. )}
  41. {notification.triggerEvents.includes('pageEdit') && (
  42. <span className="label label-warning" data-toggle="tooltip" data-placement="top" title="Page Edit">
  43. <i className="icon-pencil"></i> EDIT
  44. </span>
  45. )}
  46. {notification.triggerEvents.includes('pageMove') && (
  47. <span className="label label-warning" data-toggle="tooltip" data-placement="top" title="Page Move">
  48. <i className="icon-action-redo"></i> MOVE
  49. </span>
  50. )}
  51. {notification.triggerEvents.includes('pageDelete') && (
  52. <span className="label label-danger" data-toggle="tooltip" data-placement="top" title="Page Delte">
  53. <i className="icon-fire"></i> DELETE
  54. </span>
  55. )}
  56. {notification.triggerEvents.includes('pageLike') && (
  57. <span className="label label-info" data-toggle="tooltip" data-placement="top" title="Page Like">
  58. <i className="icon-like"></i> LIKE
  59. </span>
  60. )}
  61. {notification.triggerEvents.includes('comment') && (
  62. <span className="label label-default" data-toggle="tooltip" data-placement="top" title="New Comment">
  63. <i className="icon-fw icon-bubble"></i> POST
  64. </span>
  65. )}
  66. </td>
  67. <td>
  68. {notification.__t === 'mail'
  69. && <span data-toggle="tooltip" data-placement="top" title="Email"><i className="ti-email"></i> {notification.toEmail}</span>}
  70. {notification.__t === 'slack'
  71. && <span data-toggle="tooltip" data-placement="top" title="Slack"><i className="fa fa-slack"></i> {notification.slackChannels}</span>}
  72. </td>
  73. <td className="td-abs-center">
  74. <div className="btn-group admin-group-menu">
  75. <button type="button" className="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
  76. <i className="icon-settings"></i> <span className="caret"></span>
  77. </button>
  78. <ul className="dropdown-menu" role="menu">
  79. <li>
  80. <a href={urljoin('/admin/global-notification/', notification._id)}>
  81. <i className="icon-fw icon-note"></i> {t('Edit')}
  82. </a>
  83. </li>
  84. <li onClick={this.toggleDeleteModal}>
  85. <a>
  86. <i className="icon-fw icon-fire text-danger"></i> {t('Delete')}
  87. </a>
  88. </li>
  89. </ul>
  90. </div>
  91. </td>
  92. </tr>
  93. );
  94. })}
  95. <NotificationDeleteModal isOpen={this.state.isNotificationDeleteModalShown} onClose={this.toggleDeleteModal} />;
  96. </React.Fragment>
  97. );
  98. }
  99. }
  100. const GlobalNotificationListWrapper = (props) => {
  101. return createSubscribedElement(GlobalNotificationList, props, [AppContainer, AdminNotificationContainer]);
  102. };
  103. GlobalNotificationList.propTypes = {
  104. t: PropTypes.func.isRequired, // i18next
  105. appContainer: PropTypes.instanceOf(AppContainer).isRequired,
  106. adminNotificationContainer: PropTypes.instanceOf(AdminNotificationContainer).isRequired,
  107. };
  108. export default withTranslation()(GlobalNotificationListWrapper);