GlobalNotification.jsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. {/* TODO GW-1279 i18n */}
  33. <h2 className="border-bottom">{t('notification_setting.valid_page')}</h2>
  34. <p className="well">
  35. <span dangerouslySetInnerHTML={{ __html: t('notification_setting.link_notification_help') }} />
  36. </p>
  37. {/* TODO GW-1279 add checkbox for display isNotificationForOwnerPageEnabled */}
  38. <div className="row mb-4 d-flex align-items-center">
  39. <strong className="col-xs-3 text-right">
  40. {t('Just me')}
  41. </strong>
  42. <div className="col-xs-8 text-left">
  43. <div className="checkbox checkbox-success">
  44. <input
  45. id="isShowRestrictedByOwner"
  46. type="checkbox"
  47. />
  48. <label htmlFor="isShowRestrictedByOwner">
  49. {t('notification_setting.only_me_notification')}
  50. </label>
  51. </div>
  52. </div>
  53. </div>
  54. {/* TODO GW-1279 add checkbox for display isNotificationForGroupPageEnabled */}
  55. <div className="row mb-4 d-flex align-items-center">
  56. <strong className="col-xs-3 text-right">
  57. {t('Only inside the group')}
  58. </strong>
  59. <div className="col-xs-8 text-left">
  60. <div className="checkbox checkbox-success">
  61. <input
  62. id="isShowRestrictedByGroup"
  63. type="checkbox"
  64. />
  65. <label htmlFor="isShowRestrictedByGroup">
  66. {t('notification_setting.group_notification')}
  67. </label>
  68. </div>
  69. </div>
  70. </div>
  71. <div className="row my-3">
  72. <div className="col-xs-offset-4 col-xs-5">
  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. <a href="/admin/global-notification/new">
  83. <p className="btn btn-default">{t('notification_setting.add_notification')}</p>
  84. </a>
  85. <h2 className="border-bottom mb-5">{t('notification_setting.notification_list')}</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. const GlobalNotificationWrapper = (props) => {
  108. return createSubscribedElement(GlobalNotification, props, [AppContainer, AdminNotificationContainer]);
  109. };
  110. GlobalNotification.propTypes = {
  111. t: PropTypes.func.isRequired, // i18next
  112. appContainer: PropTypes.instanceOf(AppContainer).isRequired,
  113. adminNotificationContainer: PropTypes.instanceOf(AdminNotificationContainer).isRequired,
  114. };
  115. export default withTranslation()(GlobalNotificationWrapper);