GlobalNotification.jsx 5.0 KB

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