GlobalNotification.jsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 { withUnstatedContainers } 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('External_Notification') }));
  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 my-4">{t('notification_setting.valid_page')}</h2>
  33. <p className="card 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 offset-md-2">
  39. <div className="custom-control custom-checkbox custom-checkbox-success">
  40. <input
  41. id="isNotificationForOwnerPageEnabled"
  42. className="custom-control-input"
  43. type="checkbox"
  44. checked={adminNotificationContainer.state.isNotificationForOwnerPageEnabled || false}
  45. onChange={() => { adminNotificationContainer.switchIsNotificationForOwnerPageEnabled() }}
  46. />
  47. <label className="custom-control-label" htmlFor="isNotificationForOwnerPageEnabled">
  48. {/* eslint-disable-next-line react/no-danger */}
  49. <span dangerouslySetInnerHTML={{ __html: t('notification_setting.just_me_notification_help') }} />
  50. </label>
  51. </div>
  52. </div>
  53. </div>
  54. <div className="row mb-4">
  55. <div className="col-md-8 offset-md-2">
  56. <div className="custom-control custom-checkbox custom-checkbox-success">
  57. <input
  58. id="isNotificationForGroupPageEnabled"
  59. className="custom-control-input"
  60. type="checkbox"
  61. checked={adminNotificationContainer.state.isNotificationForGroupPageEnabled || false}
  62. onChange={() => { adminNotificationContainer.switchIsNotificationForGroupPageEnabled() }}
  63. />
  64. <label className="custom-control-label" htmlFor="isNotificationForGroupPageEnabled">
  65. {/* eslint-disable-next-line react/no-danger */}
  66. <span dangerouslySetInnerHTML={{ __html: t('notification_setting.group_notification_help') }} />
  67. </label>
  68. </div>
  69. </div>
  70. </div>
  71. <div className="row my-3">
  72. <div className="col-sm-5 offset-sm-4">
  73. <button
  74. type="button"
  75. className="btn btn-primary"
  76. onClick={this.onClickSubmit}
  77. disabled={adminNotificationContainer.state.retrieveError}
  78. >{t('Update')}
  79. </button>
  80. </div>
  81. </div>
  82. <h2 className="border-bottom mb-5">{t('notification_setting.notification_list')}
  83. <a href="/admin/global-notification/new">
  84. <p className="btn btn-outline-secondary pull-right">{t('notification_setting.add_notification')}</p>
  85. </a>
  86. </h2>
  87. <table className="table table-bordered">
  88. <thead>
  89. <tr>
  90. <th>ON/OFF</th>
  91. {/* eslint-disable-next-line react/no-danger */}
  92. <th>{t('notification_setting.trigger_path')} <span dangerouslySetInnerHTML={{ __html: t('notification_setting.trigger_path_help') }} /></th>
  93. <th>{t('notification_setting.trigger_events')}</th>
  94. <th>{t('notification_setting.notify_to')}</th>
  95. <th></th>
  96. </tr>
  97. </thead>
  98. {globalNotifications.length !== 0 && (
  99. <tbody className="admin-notif-list">
  100. <GlobalNotificationList />
  101. </tbody>
  102. )}
  103. </table>
  104. </React.Fragment>
  105. );
  106. }
  107. }
  108. const GlobalNotificationWrapper = withUnstatedContainers(GlobalNotification, [AppContainer, AdminNotificationContainer]);
  109. GlobalNotification.propTypes = {
  110. t: PropTypes.func.isRequired, // i18next
  111. appContainer: PropTypes.instanceOf(AppContainer).isRequired,
  112. adminNotificationContainer: PropTypes.instanceOf(AdminNotificationContainer).isRequired,
  113. };
  114. export default withTranslation()(GlobalNotificationWrapper);