Răsfoiți Sursa

create apiV3

itizawa 6 ani în urmă
părinte
comite
682582d0a5

+ 3 - 4
src/client/js/components/Admin/Notification/UserNotificationRow.jsx

@@ -8,7 +8,7 @@ import AppContainer from '../../../services/AppContainer';
 import AdminNotificationContainer from '../../../services/AdminNotificationContainer';
 
 
-class UserNotificationRow extends React.Component {
+class UserNotificationRow extends React.PureComponent {
 
   render() {
     const { t, notification } = this.props;
@@ -22,8 +22,7 @@ class UserNotificationRow extends React.Component {
             {notification.channel}
           </td>
           <td>
-            {/* TODO GW-806 create apiV3 for delete notification */}
-            <button type="submit" className="btn btn-default">{t('Delete')}</button>
+            <button type="submit" className="btn btn-default" onClick={() => { this.props.onClickDeleteBtn(notification._id) }}>{t('Delete')}</button>
           </td>
         </tr>
       </React.Fragment>
@@ -44,7 +43,7 @@ UserNotificationRow.propTypes = {
   adminNotificationContainer: PropTypes.instanceOf(AdminNotificationContainer).isRequired,
 
   notification: PropTypes.object.isRequired,
-
+  onClickDeleteBtn: PropTypes.func.isRequired,
 };
 
 export default withTranslation()(UserNotificationRowWrapper);

+ 15 - 1
src/client/js/components/Admin/Notification/UserTriggerNotification.jsx

@@ -27,6 +27,7 @@ class UserTriggerNotification extends React.Component {
     this.changeChannel = this.changeChannel.bind(this);
     this.validateForm = this.validateForm.bind(this);
     this.onClickSubmit = this.onClickSubmit.bind(this);
+    this.onClickDeleteBtn = this.onClickDeleteBtn.bind(this);
 
   }
 
@@ -62,6 +63,19 @@ class UserTriggerNotification extends React.Component {
     }
   }
 
+  async onClickDeleteBtn(notificationIdForDelete) {
+    const { t, adminNotificationContainer } = this.props;
+
+    try {
+      const deletedNotificaton = await adminNotificationContainer.deleteUserTriggerNotificationPattern(notificationIdForDelete);
+      toastSuccess(t('notification_setting.delete_notification_pattern', { path: deletedNotificaton.pathPattern }));
+    }
+    catch (err) {
+      toastError(err);
+      logger.error(err);
+    }
+  }
+
   // TODO GW-788 i18n
   render() {
     const { t, adminNotificationContainer } = this.props;
@@ -111,7 +125,7 @@ class UserTriggerNotification extends React.Component {
               </td>
             </tr>
             {adminNotificationContainer.state.userNotifications.map((notification) => {
-              return <UserNotificationRow notification={notification} />;
+              return <UserNotificationRow notification={notification} onClickDeleteBtn={this.onClickDeleteBtn} />;
             })
             }
           </tbody>

+ 10 - 0
src/client/js/services/AdminNotificationContainer.js

@@ -114,6 +114,16 @@ export default class AdminNotificationContainer extends Container {
     this.setState({ userNotifications: response.data.responseParams.userNotifications });
   }
 
+  /**
+   * Delete user trigger notification pattern
+   */
+  async deleteUserTriggerNotificationPattern(notificatiionId) {
+    const response = await this.appContainer.apiv3.delete(`/notification-setting/user-notification/${notificatiionId}`);
+    const deletedNotificaton = response.data;
+    await this.retrieveNotificationData();
+    return deletedNotificaton;
+  }
+
   /**
    * Delete global notification pattern
    */

+ 18 - 0
src/server/routes/apiv3/notification-setting.js

@@ -224,6 +224,24 @@ module.exports = (crowi) => {
 
   });
 
+  // TODO swagger
+  router.delete('/user-notification/:id', loginRequiredStrictly, adminRequired, csrf, async(req, res) => {
+    const { id } = req.params;
+
+    try {
+      const deletedNotificaton = await UpdatePost.remove(id);
+      console.log(deletedNotificaton);
+      return res.apiv3(deletedNotificaton);
+    }
+    catch (err) {
+      const msg = 'Error occurred in delete user trigger notification';
+      logger.error('Error', err);
+      return res.apiv3Err(new ErrorV3(msg, 'delete-userTriggerNotification-failed'));
+    }
+
+
+  });
+
   /**
    * @swagger
    *