GlobalNotification.jsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 mb-5">通知が有効になるページ</h2>
  34. {/* TODO GW-1279 add checkbox for display isNotificationOwnerPageEnabled */}
  35. {/* TODO GW-1279 add checkbox for display isNotificationGroupPageEnabled */}
  36. <div className="row my-3">
  37. <div className="col-xs-offset-4 col-xs-5">
  38. <button
  39. type="button"
  40. className="btn btn-primary"
  41. onClick={this.onClickSubmit}
  42. disabled={adminNotificationContainer.state.retrieveError}
  43. >{t('Update')}
  44. </button>
  45. </div>
  46. </div>
  47. <a href="/admin/global-notification/new">
  48. <p className="btn btn-default">{t('notification_setting.add_notification')}</p>
  49. </a>
  50. <h2 className="border-bottom mb-5">{t('notification_setting.notification_list')}</h2>
  51. <table className="table table-bordered">
  52. <thead>
  53. <tr>
  54. <th>ON/OFF</th>
  55. {/* eslint-disable-next-line react/no-danger */}
  56. <th>{t('notification_setting.trigger_path')} <span dangerouslySetInnerHTML={{ __html: t('notification_setting.trigger_path_help') }} /></th>
  57. <th>{t('notification_setting.trigger_events')}</th>
  58. <th>{t('notification_setting.notify_to')}</th>
  59. <th></th>
  60. </tr>
  61. </thead>
  62. {globalNotifications.length !== 0 && (
  63. <tbody className="admin-notif-list">
  64. <GlobalNotificationList />
  65. </tbody>
  66. )}
  67. </table>
  68. </React.Fragment>
  69. );
  70. }
  71. }
  72. const GlobalNotificationWrapper = (props) => {
  73. return createSubscribedElement(GlobalNotification, props, [AppContainer, AdminNotificationContainer]);
  74. };
  75. GlobalNotification.propTypes = {
  76. t: PropTypes.func.isRequired, // i18next
  77. appContainer: PropTypes.instanceOf(AppContainer).isRequired,
  78. adminNotificationContainer: PropTypes.instanceOf(AdminNotificationContainer).isRequired,
  79. };
  80. export default withTranslation()(GlobalNotificationWrapper);