|
|
@@ -1,6 +1,7 @@
|
|
|
-import React from 'react';
|
|
|
+import { React, useCallback } from 'react';
|
|
|
|
|
|
import { useTranslation } from 'next-i18next';
|
|
|
+import { useRouter } from 'next/router';
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
import AdminNotificationContainer from '~/client/services/AdminNotificationContainer';
|
|
|
@@ -13,17 +14,17 @@ import GlobalNotificationList from './GlobalNotificationList';
|
|
|
|
|
|
const logger = loggerFactory('growi:GlobalNotification');
|
|
|
|
|
|
-class GlobalNotification extends React.Component {
|
|
|
+const GlobalNotification = (props) => {
|
|
|
|
|
|
- constructor() {
|
|
|
- super();
|
|
|
+ const { t, adminNotificationContainer } = props;
|
|
|
|
|
|
- this.onClickSubmit = this.onClickSubmit.bind(this);
|
|
|
- }
|
|
|
+ // constructor() {
|
|
|
+ // super();
|
|
|
|
|
|
- async onClickSubmit() {
|
|
|
- const { t, adminNotificationContainer } = this.props;
|
|
|
+ // this.onClickSubmit = this.onClickSubmit.bind(this);
|
|
|
+ // }
|
|
|
|
|
|
+ const onClickSubmit = useCallback(async() => {
|
|
|
try {
|
|
|
await adminNotificationContainer.updateGlobalNotificationForPages();
|
|
|
toastSuccess(t('toaster.update_successed', { target: t('External_Notification') }));
|
|
|
@@ -32,100 +33,80 @@ class GlobalNotification extends React.Component {
|
|
|
toastError(err);
|
|
|
logger.error(err);
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- render() {
|
|
|
- const { t, adminNotificationContainer } = this.props;
|
|
|
- const { globalNotifications } = adminNotificationContainer.state;
|
|
|
- return (
|
|
|
- <React.Fragment>
|
|
|
-
|
|
|
- <h2 className="border-bottom my-4">{t('notification_setting.valid_page')}</h2>
|
|
|
-
|
|
|
- <p className="card well">
|
|
|
- {/* eslint-disable-next-line react/no-danger */}
|
|
|
- <span dangerouslySetInnerHTML={{ __html: t('notification_setting.link_notification_help') }} />
|
|
|
- </p>
|
|
|
-
|
|
|
-
|
|
|
- <div className="row mb-4">
|
|
|
- <div className="col-md-8 offset-md-2">
|
|
|
- <div className="custom-control custom-checkbox custom-checkbox-success">
|
|
|
- <input
|
|
|
- id="isNotificationForOwnerPageEnabled"
|
|
|
- className="custom-control-input"
|
|
|
- type="checkbox"
|
|
|
- checked={adminNotificationContainer.state.isNotificationForOwnerPageEnabled || false}
|
|
|
- onChange={() => { adminNotificationContainer.switchIsNotificationForOwnerPageEnabled() }}
|
|
|
- />
|
|
|
- <label className="custom-control-label" htmlFor="isNotificationForOwnerPageEnabled">
|
|
|
- {/* eslint-disable-next-line react/no-danger */}
|
|
|
- <span dangerouslySetInnerHTML={{ __html: t('notification_setting.just_me_notification_help') }} />
|
|
|
- </label>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
+ }, [adminNotificationContainer, t]);
|
|
|
+
|
|
|
+ const router = useRouter();
|
|
|
+ const { globalNotifications } = adminNotificationContainer.state;
|
|
|
+ return (
|
|
|
+ <><h2 className="border-bottom my-4">{t('notification_setting.valid_page')}</h2><p className="card well">
|
|
|
+ {/* eslint-disable-next-line react/no-danger */}
|
|
|
+ <span dangerouslySetInnerHTML={{ __html: t('notification_setting.link_notification_help') }} />
|
|
|
+ </p><div className="row mb-4">
|
|
|
+ <div className="col-md-8 offset-md-2">
|
|
|
+ <div className="custom-control custom-checkbox custom-checkbox-success">
|
|
|
+ <input
|
|
|
+ id="isNotificationForOwnerPageEnabled"
|
|
|
+ className="custom-control-input"
|
|
|
+ type="checkbox"
|
|
|
+ checked={adminNotificationContainer.state.isNotificationForOwnerPageEnabled || false}
|
|
|
+ onChange={() => { adminNotificationContainer.switchIsNotificationForOwnerPageEnabled() } } />
|
|
|
+ <label className="custom-control-label" htmlFor="isNotificationForOwnerPageEnabled">
|
|
|
+ {/* eslint-disable-next-line react/no-danger */}
|
|
|
+ <span dangerouslySetInnerHTML={{ __html: t('notification_setting.just_me_notification_help') }} />
|
|
|
+ </label>
|
|
|
</div>
|
|
|
-
|
|
|
-
|
|
|
- <div className="row mb-4">
|
|
|
- <div className="col-md-8 offset-md-2">
|
|
|
- <div className="custom-control custom-checkbox custom-checkbox-success">
|
|
|
- <input
|
|
|
- id="isNotificationForGroupPageEnabled"
|
|
|
- className="custom-control-input"
|
|
|
- type="checkbox"
|
|
|
- checked={adminNotificationContainer.state.isNotificationForGroupPageEnabled || false}
|
|
|
- onChange={() => { adminNotificationContainer.switchIsNotificationForGroupPageEnabled() }}
|
|
|
- />
|
|
|
- <label className="custom-control-label" htmlFor="isNotificationForGroupPageEnabled">
|
|
|
- {/* eslint-disable-next-line react/no-danger */}
|
|
|
- <span dangerouslySetInnerHTML={{ __html: t('notification_setting.group_notification_help') }} />
|
|
|
- </label>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
+ </div>
|
|
|
+ </div><div className="row mb-4">
|
|
|
+ <div className="col-md-8 offset-md-2">
|
|
|
+ <div className="custom-control custom-checkbox custom-checkbox-success">
|
|
|
+ <input
|
|
|
+ id="isNotificationForGroupPageEnabled"
|
|
|
+ className="custom-control-input"
|
|
|
+ type="checkbox"
|
|
|
+ checked={adminNotificationContainer.state.isNotificationForGroupPageEnabled || false}
|
|
|
+ onChange={() => { adminNotificationContainer.switchIsNotificationForGroupPageEnabled() } } />
|
|
|
+ <label className="custom-control-label" htmlFor="isNotificationForGroupPageEnabled">
|
|
|
+ {/* eslint-disable-next-line react/no-danger */}
|
|
|
+ <span dangerouslySetInnerHTML={{ __html: t('notification_setting.group_notification_help') }} />
|
|
|
+ </label>
|
|
|
</div>
|
|
|
-
|
|
|
- <div className="row my-3">
|
|
|
- <div className="col-sm-5 offset-sm-4">
|
|
|
- <button
|
|
|
- type="button"
|
|
|
- className="btn btn-primary"
|
|
|
- onClick={this.onClickSubmit}
|
|
|
- disabled={adminNotificationContainer.state.retrieveError}
|
|
|
- >{t('Update')}
|
|
|
- </button>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
-
|
|
|
- <h2 className="border-bottom mb-5">{t('notification_setting.notification_list')}
|
|
|
- <a href="/admin/global-notification/new">
|
|
|
- <p className="btn btn-outline-secondary pull-right">{t('notification_setting.add_notification')}</p>
|
|
|
- </a>
|
|
|
- </h2>
|
|
|
-
|
|
|
- <table className="table table-bordered">
|
|
|
- <thead>
|
|
|
- <tr>
|
|
|
- <th>ON/OFF</th>
|
|
|
- {/* eslint-disable-next-line react/no-danger */}
|
|
|
- <th>{t('notification_setting.trigger_path')} <span dangerouslySetInnerHTML={{ __html: t('notification_setting.trigger_path_help') }} /></th>
|
|
|
- <th>{t('notification_setting.trigger_events')}</th>
|
|
|
- <th>{t('notification_setting.notify_to')}</th>
|
|
|
- <th></th>
|
|
|
- </tr>
|
|
|
- </thead>
|
|
|
- {globalNotifications.length !== 0 && (
|
|
|
- <tbody className="admin-notif-list">
|
|
|
- <GlobalNotificationList />
|
|
|
- </tbody>
|
|
|
- )}
|
|
|
- </table>
|
|
|
-
|
|
|
- </React.Fragment>
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
+ </div>
|
|
|
+ </div><div className="row my-3">
|
|
|
+ <div className="col-sm-5 offset-sm-4">
|
|
|
+ <button
|
|
|
+ type="button"
|
|
|
+ className="btn btn-primary"
|
|
|
+ onClick={onClickSubmit}
|
|
|
+ disabled={adminNotificationContainer.state.retrieveError}
|
|
|
+ >{t('Update')}
|
|
|
+ </button>
|
|
|
+ </div>
|
|
|
+ </div><h2 className="border-bottom mb-5">{t('notification_setting.notification_list')}
|
|
|
+ <div className="btn btn-outline-secondary pull-right">
|
|
|
+ <button type="button" onClick={() => router.push('/admin/global-notification/new')}>{t('notification_setting.add_notification')}</button>
|
|
|
+ </div>
|
|
|
+ {/* <a href="/admin/global-notification/new">
|
|
|
+ <p className="btn btn-outline-secondary pull-right">{t('notification_setting.add_notification')}</p>
|
|
|
+ </a> */}
|
|
|
+ </h2><table className="table table-bordered">
|
|
|
+ <thead>
|
|
|
+ <tr>
|
|
|
+ <th>ON/OFF</th>
|
|
|
+ {/* eslint-disable-next-line react/no-danger */}
|
|
|
+ <th>{t('notification_setting.trigger_path')} <span dangerouslySetInnerHTML={{ __html: t('notification_setting.trigger_path_help') }} /></th>
|
|
|
+ <th>{t('notification_setting.trigger_events')}</th>
|
|
|
+ <th>{t('notification_setting.notify_to')}</th>
|
|
|
+ <th></th>
|
|
|
+ </tr>
|
|
|
+ </thead>
|
|
|
+ {globalNotifications.length !== 0 && (
|
|
|
+ <tbody className="admin-notif-list">
|
|
|
+ <GlobalNotificationList />
|
|
|
+ </tbody>
|
|
|
+ )}
|
|
|
+ </table></>
|
|
|
+ );
|
|
|
+};
|
|
|
|
|
|
GlobalNotification.propTypes = {
|
|
|
t: PropTypes.func.isRequired, // i18next
|