itizawa 6 лет назад
Родитель
Сommit
eb8fcabbf0

+ 18 - 15
src/client/js/components/Admin/Notification/ManageGlobalNotification.jsx

@@ -19,7 +19,14 @@ class ManageGlobalNotification extends React.Component {
   constructor() {
   constructor() {
     super();
     super();
 
 
-    const globalNotification = JSON.parse(document.getElementById('admin-global-notification-setting').getAttribute('data-global-notification'));
+    let globalNotification;
+    try {
+      globalNotification = JSON.parse(document.getElementById('admin-global-notification-setting').getAttribute('data-global-notification'));
+    }
+    catch (err) {
+      toastError(err);
+      logger.error(err);
+    }
 
 
     this.state = {
     this.state = {
       globalNotificationId: globalNotification._id || null,
       globalNotificationId: globalNotification._id || null,
@@ -64,24 +71,20 @@ class ManageGlobalNotification extends React.Component {
 
 
   async submitHandler() {
   async submitHandler() {
 
 
+    const requestParams = {
+      triggerPath: this.state.triggerPath,
+      notifyToType: this.state.notifyToType,
+      toEmail: this.state.emailToSend,
+      slackChannels: this.state.slackChannelToSend,
+      triggerEvents: [...this.state.triggerEvents],
+    };
+
     try {
     try {
       if (this.state.globalNotificationId != null) {
       if (this.state.globalNotificationId != null) {
-        await this.props.appContainer.apiv3.put(`/notification-setting/global-notification/${this.state.globalNotificationId}`, {
-          triggerPath: this.state.triggerPath,
-          notifyToType: this.state.notifyToType,
-          toEmail: this.state.emailToSend,
-          slackChannels: this.state.slackChannelToSend,
-          triggerEvents: [...this.state.triggerEvents],
-        });
+        await this.props.appContainer.apiv3.put(`/notification-setting/global-notification/${this.state.globalNotificationId}`, requestParams);
       }
       }
       else {
       else {
-        await this.props.appContainer.apiv3.post('/notification-setting/global-notification', {
-          triggerPath: this.state.triggerPath,
-          notifyToType: this.state.notifyToType,
-          toEmail: this.state.emailToSend,
-          slackChannels: this.state.slackChannelToSend,
-          triggerEvents: [...this.state.triggerEvents],
-        });
+        await this.props.appContainer.apiv3.post('/notification-setting/global-notification', requestParams);
       }
       }
       window.location.href = urljoin(window.location.origin, '/admin/notification#global-notification');
       window.location.href = urljoin(window.location.origin, '/admin/notification#global-notification');
     }
     }

+ 1 - 1
src/server/routes/apiv3/notification-setting.js

@@ -285,7 +285,7 @@ module.exports = (crowi) => {
    *
    *
    *    /_api/v3/notification-setting/global-notification/{id}:
    *    /_api/v3/notification-setting/global-notification/{id}:
    *      put:
    *      put:
-   *        tags: [NotificationSetting]
+   *        tags: [NotificationSetting, apiv3]
    *        description: update global notification
    *        description: update global notification
    *        parameters:
    *        parameters:
    *          - name: id
    *          - name: id