itizawa 6 lat temu
rodzic
commit
5fe7a06ed9

+ 15 - 9
src/client/js/components/Admin/Notification/GlobalNotificationList.jsx

@@ -19,29 +19,35 @@ class GlobalNotificationList extends React.Component {
     super(props);
 
     this.state = {
-      isNotificationDeleteModalShown: false,
+      isConfirmationModalOpen: false,
+      notificatiionIdForConfiguration: null,
     };
 
-    this.toggleDeleteModal = this.toggleDeleteModal.bind(this);
+    this.openConfirmationModal = this.openConfirmationModal.bind(this);
+    this.closeConfirmationModal = this.closeConfirmationModal.bind(this);
     this.onClickSubmit = this.onClickSubmit.bind(this);
   }
 
-  toggleDeleteModal() {
-    this.setState({ isNotificationDeleteModalShown: !this.state.isNotificationDeleteModalShown });
+  openConfirmationModal(notificatiionId) {
+    this.setState({ isConfirmationModalOpen: true, notificatiionIdForConfiguration: notificatiionId });
+  }
+
+  closeConfirmationModal() {
+    this.setState({ isConfirmationModalOpen: false, notificatiionIdForConfiguration: null });
   }
 
   async onClickSubmit() {
     const { t, adminNotificationContainer } = this.props;
 
     try {
-      await adminNotificationContainer.deleteGlobalNotificationPattern();
+      await adminNotificationContainer.deleteGlobalNotificationPattern(this.state.notificatiionIdForConfiguration);
       toastSuccess(t('notification_setting.delete_notification_pattern'));
     }
     catch (err) {
       toastError(err);
       logger.error(err);
     }
-    this.setState({ isNotificationDeleteModalShown: false });
+    this.setState({ isConfirmationModalOpen: false });
   }
 
   render() {
@@ -109,7 +115,7 @@ class GlobalNotificationList extends React.Component {
                         <i className="icon-fw icon-note"></i> {t('Edit')}
                       </a>
                     </li>
-                    <li onClick={this.toggleDeleteModal}>
+                    <li onClick={() => this.toggleDeleteModal(notification._id)}>
                       <a>
                         <i className="icon-fw icon-fire text-danger"></i> {t('Delete')}
                       </a>
@@ -121,8 +127,8 @@ class GlobalNotificationList extends React.Component {
           );
         })}
         <NotificationDeleteModal
-          isOpen={this.state.isNotificationDeleteModalShown}
-          onClose={this.toggleDeleteModal}
+          isOpen={this.state.isConfirmationModalOpen}
+          onClose={this.closeConfirmationModal}
           onClickSubmit={this.onClickSubmit}
         />;
       </React.Fragment>

+ 1 - 12
src/client/js/components/Admin/Notification/NotificationDeleteModal.jsx

@@ -4,9 +4,6 @@ import { withTranslation } from 'react-i18next';
 
 import Modal from 'react-bootstrap/es/Modal';
 
-import { createSubscribedElement } from '../../UnstatedUtils';
-import AppContainer from '../../../services/AppContainer';
-
 class NotificationDeleteModal extends React.PureComponent {
 
   render() {
@@ -37,14 +34,6 @@ class NotificationDeleteModal extends React.PureComponent {
 
 }
 
-/**
- * Wrapper component for using unstated
- */
-const NotificationDeleteModalWrapper = (props) => {
-  return createSubscribedElement(NotificationDeleteModal, props, [AppContainer]);
-};
-
-
 NotificationDeleteModal.propTypes = {
   t: PropTypes.func.isRequired, // i18next
 
@@ -53,4 +42,4 @@ NotificationDeleteModal.propTypes = {
   onClickSubmit: PropTypes.func.isRequired,
 };
 
-export default withTranslation()(NotificationDeleteModalWrapper);
+export default withTranslation()(NotificationDeleteModal);