GlobalNotification.jsx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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><div className="row mb-4">
  33. <div className="col-md-8 offset-md-2">
  34. <div className="custom-control custom-checkbox custom-checkbox-success">
  35. <input
  36. id="isNotificationForOwnerPageEnabled"
  37. className="custom-control-input"
  38. type="checkbox"
  39. checked={adminNotificationContainer.state.isNotificationForOwnerPageEnabled || false}
  40. onChange={() => { adminNotificationContainer.switchIsNotificationForOwnerPageEnabled() } } />
  41. <label className="custom-control-label" htmlFor="isNotificationForOwnerPageEnabled">
  42. {/* eslint-disable-next-line react/no-danger */}
  43. <span dangerouslySetInnerHTML={{ __html: t('notification_settings.just_me_notification_help') }} />
  44. </label>
  45. </div>
  46. </div>
  47. </div><div className="row mb-4">
  48. <div className="col-md-8 offset-md-2">
  49. <div className="custom-control custom-checkbox custom-checkbox-success">
  50. <input
  51. id="isNotificationForGroupPageEnabled"
  52. className="custom-control-input"
  53. type="checkbox"
  54. checked={adminNotificationContainer.state.isNotificationForGroupPageEnabled || false}
  55. onChange={() => { adminNotificationContainer.switchIsNotificationForGroupPageEnabled() } } />
  56. <label className="custom-control-label" htmlFor="isNotificationForGroupPageEnabled">
  57. {/* eslint-disable-next-line react/no-danger */}
  58. <span dangerouslySetInnerHTML={{ __html: t('notification_settings.group_notification_help') }} />
  59. </label>
  60. </div>
  61. </div>
  62. </div>
  63. <div className="row my-3">
  64. <div className="col-sm-5 offset-sm-4">
  65. <button
  66. type="button"
  67. className="btn btn-primary"
  68. onClick={onClickSubmit}
  69. disabled={adminNotificationContainer.state.retrieveError}
  70. >{t('Update')}
  71. </button>
  72. </div>
  73. </div>
  74. <h2 className="border-bottom mb-5">{t('notification_settings.notification_list')}
  75. <button className="btn btn-outline-secondary pull-right"
  76. type="button" onClick={() => router.push('/admin/global-notification/new')}>{t('notification_settings.add_notification')}</button>
  77. {/* <a href="/admin/global-notification/new">
  78. <p className="btn btn-outline-secondary pull-right">{t('notification_setting.add_notification')}</p>
  79. </a> */}
  80. </h2><table className="table table-bordered">
  81. <thead>
  82. <tr>
  83. <th>ON/OFF</th>
  84. {/* eslint-disable-next-line react/no-danger */}
  85. <th>{t('notification_settings.trigger_path')} <span dangerouslySetInnerHTML={{ __html: t('notification_settings.trigger_path_help') }} /></th>
  86. <th>{t('notification_settings.trigger_events')}</th>
  87. <th>{t('notification_settings.notify_to')}</th>
  88. <th></th>
  89. </tr>
  90. </thead>
  91. {globalNotifications.length !== 0 && (
  92. <tbody className="admin-notif-list">
  93. <GlobalNotificationList />
  94. </tbody>
  95. )}
  96. </table>
  97. </>
  98. );
  99. };
  100. GlobalNotification.propTypes = {
  101. adminNotificationContainer: PropTypes.instanceOf(AdminNotificationContainer).isRequired,
  102. };
  103. const GlobalNotificationWrapper = withUnstatedContainers(GlobalNotification, [AdminNotificationContainer]);
  104. export default GlobalNotificationWrapper;