GlobalNotification.jsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import { React, useCallback } from 'react';
  2. import { useTranslation } from 'next-i18next';
  3. import { useRouter } from 'next/router';
  4. import PropTypes from 'prop-types';
  5. import AdminNotificationContainer from '~/client/services/AdminNotificationContainer';
  6. import { toastSuccess, toastError } from '~/client/util/toastr';
  7. import loggerFactory from '~/utils/logger';
  8. import { withUnstatedContainers } from '../../UnstatedUtils';
  9. import GlobalNotificationList from './GlobalNotificationList';
  10. const logger = loggerFactory('growi:GlobalNotification');
  11. const GlobalNotification = (props) => {
  12. const { adminNotificationContainer } = props;
  13. const { t } = useTranslation('admin');
  14. const onClickSubmit = useCallback(async() => {
  15. try {
  16. await adminNotificationContainer.updateGlobalNotificationForPages();
  17. toastSuccess(t('toaster.update_successed', { target: t('external_notification.external_notification'), ns: 'commons' }));
  18. }
  19. catch (err) {
  20. toastError(err);
  21. logger.error(err);
  22. }
  23. }, [adminNotificationContainer, t]);
  24. const router = useRouter();
  25. const { globalNotifications } = adminNotificationContainer.state;
  26. return (
  27. <>
  28. <h2 className="border-bottom my-4">{t('notification_settings.valid_page')}</h2>
  29. <p className="card well">
  30. {/* eslint-disable-next-line react/no-danger */}
  31. <span dangerouslySetInnerHTML={{ __html: t('notification_settings.link_notification_help') }} />
  32. </p>
  33. <div className="row mb-4">
  34. <div className="col-md-8 offset-md-2">
  35. <div className="custom-control custom-checkbox custom-checkbox-success">
  36. <input
  37. id="isNotificationForOwnerPageEnabled"
  38. className="custom-control-input"
  39. type="checkbox"
  40. checked={adminNotificationContainer.state.isNotificationForOwnerPageEnabled || false}
  41. onChange={() => { adminNotificationContainer.switchIsNotificationForOwnerPageEnabled() }}
  42. />
  43. <label className="custom-control-label" htmlFor="isNotificationForOwnerPageEnabled">
  44. {/* eslint-disable-next-line react/no-danger */}
  45. <span dangerouslySetInnerHTML={{ __html: t('notification_settings.just_me_notification_help') }} />
  46. </label>
  47. </div>
  48. </div>
  49. </div>
  50. <div className="row mb-4">
  51. <div className="col-md-8 offset-md-2">
  52. <div className="custom-control custom-checkbox custom-checkbox-success">
  53. <input
  54. id="isNotificationForGroupPageEnabled"
  55. className="custom-control-input"
  56. type="checkbox"
  57. checked={adminNotificationContainer.state.isNotificationForGroupPageEnabled || false}
  58. onChange={() => { adminNotificationContainer.switchIsNotificationForGroupPageEnabled() }}
  59. />
  60. <label className="custom-control-label" htmlFor="isNotificationForGroupPageEnabled">
  61. {/* eslint-disable-next-line react/no-danger */}
  62. <span dangerouslySetInnerHTML={{ __html: t('notification_settings.group_notification_help') }} />
  63. </label>
  64. </div>
  65. </div>
  66. </div>
  67. <div className="row my-3">
  68. <div className="col-sm-5 offset-sm-4">
  69. <button
  70. type="button"
  71. className="btn btn-primary"
  72. onClick={onClickSubmit}
  73. disabled={adminNotificationContainer.state.retrieveError}
  74. >{t('Update')}
  75. </button>
  76. </div>
  77. </div>
  78. <h2 className="border-bottom mb-5">{t('notification_settings.notification_list')}
  79. <button
  80. className="btn btn-outline-secondary pull-right"
  81. type="button"
  82. onClick={() => router.push('/admin/global-notification/new')}
  83. >{t('notification_settings.add_notification')}
  84. </button>
  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_settings.trigger_path')} <span dangerouslySetInnerHTML={{ __html: t('notification_settings.trigger_path_help') }} /></th>
  92. <th>{t('notification_settings.trigger_events')}</th>
  93. <th>{t('notification_settings.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. </>
  104. );
  105. };
  106. GlobalNotification.propTypes = {
  107. adminNotificationContainer: PropTypes.instanceOf(AdminNotificationContainer).isRequired,
  108. };
  109. const GlobalNotificationWrapper = withUnstatedContainers(GlobalNotification, [AdminNotificationContainer]);
  110. export default GlobalNotificationWrapper;