GlobalNotification.jsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { withTranslation } from 'react-i18next';
  4. import loggerFactory from '@alias/logger';
  5. import { createSubscribedElement } from '../../UnstatedUtils';
  6. import { toastSuccess, toastError } from '../../../util/apiNotification';
  7. import AppContainer from '../../../services/AppContainer';
  8. import AdminNotificationContainer from '../../../services/AdminNotificationContainer';
  9. import GlobalNotificationList from './GlobalNotificationList';
  10. const logger = loggerFactory('growi:GlobalNotification');
  11. class GlobalNotification extends React.Component {
  12. constructor() {
  13. super();
  14. this.onClickSubmit = this.onClickSubmit.bind(this);
  15. }
  16. async onClickSubmit() {
  17. const { t, adminNotificationContainer } = this.props;
  18. try {
  19. await adminNotificationContainer.updateGlobalNotificationForPages();
  20. toastSuccess(t('toaster.update_successed', { target: t('Notification Settings') }));
  21. }
  22. catch (err) {
  23. toastError(err);
  24. logger.error(err);
  25. }
  26. }
  27. render() {
  28. const { t, adminNotificationContainer } = this.props;
  29. const { globalNotifications } = adminNotificationContainer.state;
  30. return (
  31. <React.Fragment>
  32. <h2 className="border-bottom">{t('notification_setting.valid_page')}</h2>
  33. <p className="well">
  34. {/* eslint-disable-next-line react/no-danger */}
  35. <span dangerouslySetInnerHTML={{ __html: t('notification_setting.link_notification_help') }} />
  36. </p>
  37. <div className="row mb-4">
  38. <div className="col-md-8 col-md-offset-2">
  39. <div className="checkbox checkbox-success">
  40. <input
  41. id="isNotificationForOwnerPageEnabled"
  42. type="checkbox"
  43. />
  44. <label htmlFor="isNotificationForOwnerPageEnabled">
  45. {/* eslint-disable-next-line react/no-danger */}
  46. <span dangerouslySetInnerHTML={{ __html: t('notification_setting.just_me_notification_help') }} />
  47. </label>
  48. </div>
  49. </div>
  50. </div>
  51. <div className="row mb-4">
  52. <div className="col-md-8 col-md-offset-2">
  53. <div className="checkbox checkbox-success">
  54. <input
  55. id="isNotificationForGroupPageEnabled"
  56. type="checkbox"
  57. />
  58. <label htmlFor="isNotificationForGroupPageEnabled">
  59. {/* eslint-disable-next-line react/no-danger */}
  60. <span dangerouslySetInnerHTML={{ __html: t('notification_setting.group_notification_help') }} />
  61. </label>
  62. </div>
  63. </div>
  64. </div>
  65. <div className="row my-3">
  66. <div className="col-xs-offset-4 col-xs-5">
  67. <button
  68. type="button"
  69. className="btn btn-primary"
  70. onClick={this.onClickSubmit}
  71. disabled={adminNotificationContainer.state.retrieveError}
  72. >{t('Update')}
  73. </button>
  74. </div>
  75. </div>
  76. <h2 className="border-bottom mb-5">{t('notification_setting.notification_list')}
  77. <a href="/admin/global-notification/new">
  78. <p className="btn btn-default pull-right">{t('notification_setting.add_notification')}</p>
  79. </a>
  80. </h2>
  81. <table className="table table-bordered">
  82. <thead>
  83. <tr>
  84. <th>ON/OFF</th>
  85. {/* eslint-disable-next-line react/no-danger */}
  86. <th>{t('notification_setting.trigger_path')} <span dangerouslySetInnerHTML={{ __html: t('notification_setting.trigger_path_help') }} /></th>
  87. <th>{t('notification_setting.trigger_events')}</th>
  88. <th>{t('notification_setting.notify_to')}</th>
  89. <th></th>
  90. </tr>
  91. </thead>
  92. {globalNotifications.length !== 0 && (
  93. <tbody className="admin-notif-list">
  94. <GlobalNotificationList />
  95. </tbody>
  96. )}
  97. </table>
  98. </React.Fragment>
  99. );
  100. }
  101. }
  102. const GlobalNotificationWrapper = (props) => {
  103. return createSubscribedElement(GlobalNotification, props, [AppContainer, AdminNotificationContainer]);
  104. };
  105. GlobalNotification.propTypes = {
  106. t: PropTypes.func.isRequired, // i18next
  107. appContainer: PropTypes.instanceOf(AppContainer).isRequired,
  108. adminNotificationContainer: PropTypes.instanceOf(AdminNotificationContainer).isRequired,
  109. };
  110. export default withTranslation()(GlobalNotificationWrapper);