GlobalNotification.jsx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. {/* eslint-disable-next-line react/no-danger */}
  37. <span
  38. // biome-ignore lint/security/noDangerouslySetInnerHtml: trusted translation markup
  39. dangerouslySetInnerHTML={{
  40. __html: t('notification_settings.link_notification_help'),
  41. }}
  42. />
  43. </p>
  44. <div className="row mb-4">
  45. <div className="col-md-8 offset-md-2">
  46. <div className="form-check form-check-success">
  47. <input
  48. id="isNotificationForOwnerPageEnabled"
  49. className="form-check-input"
  50. type="checkbox"
  51. checked={
  52. adminNotificationContainer.state
  53. .isNotificationForOwnerPageEnabled || false
  54. }
  55. onChange={() => {
  56. adminNotificationContainer.switchIsNotificationForOwnerPageEnabled();
  57. }}
  58. />
  59. <label
  60. className="form-label form-check-label"
  61. htmlFor="isNotificationForOwnerPageEnabled"
  62. >
  63. {/* eslint-disable-next-line react/no-danger */}
  64. <span
  65. // biome-ignore lint/security/noDangerouslySetInnerHtml: trusted translation markup
  66. dangerouslySetInnerHTML={{
  67. __html: t('notification_settings.just_me_notification_help'),
  68. }}
  69. />
  70. </label>
  71. </div>
  72. </div>
  73. </div>
  74. <div className="row mb-4">
  75. <div className="col-md-8 offset-md-2">
  76. <div className="form-check form-check-success">
  77. <input
  78. id="isNotificationForGroupPageEnabled"
  79. className="form-check-input"
  80. type="checkbox"
  81. checked={
  82. adminNotificationContainer.state
  83. .isNotificationForGroupPageEnabled || false
  84. }
  85. onChange={() => {
  86. adminNotificationContainer.switchIsNotificationForGroupPageEnabled();
  87. }}
  88. />
  89. <label
  90. className="form-label form-check-label"
  91. htmlFor="isNotificationForGroupPageEnabled"
  92. >
  93. {/* eslint-disable-next-line react/no-danger */}
  94. <span
  95. // biome-ignore lint/security/noDangerouslySetInnerHtml: trusted translation markup
  96. dangerouslySetInnerHTML={{
  97. __html: t('notification_settings.group_notification_help'),
  98. }}
  99. />
  100. </label>
  101. </div>
  102. </div>
  103. </div>
  104. <div className="row mt-3 mb-5">
  105. <div className="col-sm-5 offset-sm-4">
  106. <button
  107. type="button"
  108. className="btn btn-primary"
  109. onClick={onClickSubmit}
  110. disabled={adminNotificationContainer.state.retrieveError}
  111. >
  112. {t('Update')}
  113. </button>
  114. </div>
  115. </div>
  116. <h2 className="border-bottom mb-3">
  117. {t('notification_settings.notification_list')}
  118. </h2>
  119. <button
  120. className="btn btn-outline-secondary mb-3"
  121. type="button"
  122. onClick={() => router.push('/admin/global-notification/new')}
  123. >
  124. {t('notification_settings.add_notification')}
  125. </button>
  126. <table className="table table-bordered">
  127. <thead>
  128. <tr>
  129. <th>ON/OFF</th>
  130. {/* eslint-disable-next-line react/no-danger */}
  131. <th>
  132. {t('notification_settings.trigger_path')}{' '}
  133. <span
  134. // biome-ignore lint/security/noDangerouslySetInnerHtml: trusted translation markup
  135. dangerouslySetInnerHTML={{
  136. __html: t('notification_settings.trigger_path_help'),
  137. }}
  138. />
  139. </th>
  140. <th>{t('notification_settings.trigger_events')}</th>
  141. <th>{t('notification_settings.notify_to')}</th>
  142. <th></th>
  143. </tr>
  144. </thead>
  145. {globalNotifications.length !== 0 && (
  146. <tbody className="admin-notif-list">
  147. <GlobalNotificationList />
  148. </tbody>
  149. )}
  150. </table>
  151. </>
  152. );
  153. };
  154. GlobalNotification.propTypes = {
  155. adminNotificationContainer: PropTypes.instanceOf(AdminNotificationContainer)
  156. .isRequired,
  157. };
  158. const GlobalNotificationWrapper = withUnstatedContainers(GlobalNotification, [
  159. AdminNotificationContainer,
  160. ]);
  161. export default GlobalNotificationWrapper;