GlobalNotification.jsx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. import { React, useCallback } from 'react';
  2. import { useRouter } from 'next/router';
  3. import { useTranslation } from 'next-i18next';
  4. import PropTypes from 'prop-types';
  5. import AdminNotificationContainer from '~/client/services/AdminNotificationContainer';
  6. import { toastError, toastSuccess } 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(
  18. t('toaster.update_successed', {
  19. target: t('external_notification.external_notification'),
  20. ns: 'commons',
  21. }),
  22. );
  23. } catch (err) {
  24. toastError(err);
  25. logger.error(err);
  26. }
  27. }, [adminNotificationContainer, t]);
  28. const router = useRouter();
  29. const { globalNotifications } = adminNotificationContainer.state;
  30. return (
  31. <>
  32. <h2 className="border-bottom my-4">
  33. {t('notification_settings.valid_page')}
  34. </h2>
  35. <p className="card custom-card bg-body-tertiary">
  36. <span
  37. // biome-ignore lint/security/noDangerouslySetInnerHtml: trusted translation markup
  38. dangerouslySetInnerHTML={{
  39. __html: t('notification_settings.link_notification_help'),
  40. }}
  41. />
  42. </p>
  43. <div className="row mb-4">
  44. <div className="col-md-8 offset-md-2">
  45. <div className="form-check form-check-success">
  46. <input
  47. id="isNotificationForOwnerPageEnabled"
  48. className="form-check-input"
  49. type="checkbox"
  50. checked={
  51. adminNotificationContainer.state
  52. .isNotificationForOwnerPageEnabled || false
  53. }
  54. onChange={() => {
  55. adminNotificationContainer.switchIsNotificationForOwnerPageEnabled();
  56. }}
  57. />
  58. <label
  59. className="form-label form-check-label"
  60. htmlFor="isNotificationForOwnerPageEnabled"
  61. >
  62. <span
  63. // biome-ignore lint/security/noDangerouslySetInnerHtml: trusted translation markup
  64. dangerouslySetInnerHTML={{
  65. __html: t('notification_settings.just_me_notification_help'),
  66. }}
  67. />
  68. </label>
  69. </div>
  70. </div>
  71. </div>
  72. <div className="row mb-4">
  73. <div className="col-md-8 offset-md-2">
  74. <div className="form-check form-check-success">
  75. <input
  76. id="isNotificationForGroupPageEnabled"
  77. className="form-check-input"
  78. type="checkbox"
  79. checked={
  80. adminNotificationContainer.state
  81. .isNotificationForGroupPageEnabled || false
  82. }
  83. onChange={() => {
  84. adminNotificationContainer.switchIsNotificationForGroupPageEnabled();
  85. }}
  86. />
  87. <label
  88. className="form-label form-check-label"
  89. htmlFor="isNotificationForGroupPageEnabled"
  90. >
  91. <span
  92. // biome-ignore lint/security/noDangerouslySetInnerHtml: trusted translation markup
  93. dangerouslySetInnerHTML={{
  94. __html: t('notification_settings.group_notification_help'),
  95. }}
  96. />
  97. </label>
  98. </div>
  99. </div>
  100. </div>
  101. <div className="row mt-3 mb-5">
  102. <div className="col-sm-5 offset-sm-4">
  103. <button
  104. type="button"
  105. className="btn btn-primary"
  106. onClick={onClickSubmit}
  107. disabled={adminNotificationContainer.state.retrieveError}
  108. >
  109. {t('Update')}
  110. </button>
  111. </div>
  112. </div>
  113. <h2 className="border-bottom mb-3">
  114. {t('notification_settings.notification_list')}
  115. </h2>
  116. <button
  117. className="btn btn-outline-secondary mb-3"
  118. type="button"
  119. onClick={() => router.push('/admin/global-notification/new')}
  120. >
  121. {t('notification_settings.add_notification')}
  122. </button>
  123. <table className="table table-bordered">
  124. <thead>
  125. <tr>
  126. <th>ON/OFF</th>
  127. <th>
  128. {t('notification_settings.trigger_path')}{' '}
  129. <span
  130. // biome-ignore lint/security/noDangerouslySetInnerHtml: trusted translation markup
  131. dangerouslySetInnerHTML={{
  132. __html: t('notification_settings.trigger_path_help'),
  133. }}
  134. />
  135. </th>
  136. <th>{t('notification_settings.trigger_events')}</th>
  137. <th>{t('notification_settings.notify_to')}</th>
  138. <th></th>
  139. </tr>
  140. </thead>
  141. {globalNotifications.length !== 0 && (
  142. <tbody className="admin-notif-list">
  143. <GlobalNotificationList />
  144. </tbody>
  145. )}
  146. </table>
  147. </>
  148. );
  149. };
  150. GlobalNotification.propTypes = {
  151. adminNotificationContainer: PropTypes.instanceOf(AdminNotificationContainer)
  152. .isRequired,
  153. };
  154. const GlobalNotificationWrapper = withUnstatedContainers(GlobalNotification, [
  155. AdminNotificationContainer,
  156. ]);
  157. export default GlobalNotificationWrapper;