Sfoglia il codice sorgente

Merge pull request #1529 from weseek/reactify-admin/create-delete-notification-modal

Reactify admin/create delete notification modal
itizawa 6 anni fa
parent
commit
bf49f65f28

+ 5 - 2
resource/locales/en-US/translation.json

@@ -373,7 +373,7 @@
     "siteurl_help": "Site full URL beginning from <code>http://</code> or <code>https://</code>.",
     "siteurl_help": "Site full URL beginning from <code>http://</code> or <code>https://</code>.",
     "Confidential name": "Confidential name",
     "Confidential name": "Confidential name",
     "Default Language for new users": "Default Language for new users",
     "Default Language for new users": "Default Language for new users",
-    "ex) internal use only":"ex): internal use only",
+    "ex) internal use only": "ex): internal use only",
     "File Uploading": "File Uploading",
     "File Uploading": "File Uploading",
     "enable_files_except_image": "Enable file upload other than image files.",
     "enable_files_except_image": "Enable file upload other than image files.",
     "attach_enable": "You can attach files other than image files if you enable this option.",
     "attach_enable": "You can attach files other than image files if you enable this option.",
@@ -611,7 +611,10 @@
       "ifttt_link": "Create a new IFTTT applet with Email trigger"
       "ifttt_link": "Create a new IFTTT applet with Email trigger"
     },
     },
     "updated_slackApp": "Succeeded to update Slack App Configuration setting",
     "updated_slackApp": "Succeeded to update Slack App Configuration setting",
-    "add_notification_pattern": "Add user trigger notification patterns"
+    "add_notification_pattern": "Add user trigger notification patterns",
+    "delete_notification_pattern": "Delete notification pattern",
+    "delete_notification_pattern_desc1": "Delete Path: {{path}}",
+    "delete_notification_pattern_desc2": "Once deleted, it cannot be recovered"
   },
   },
   "customize_page": {
   "customize_page": {
     "recommended": "Recommended",
     "recommended": "Recommended",

+ 4 - 1
resource/locales/ja/translation.json

@@ -594,7 +594,10 @@
       "ifttt_link": "IFTTT でメールトリガの新しいアプレットを作る"
       "ifttt_link": "IFTTT でメールトリガの新しいアプレットを作る"
     },
     },
     "updated_slackApp": "SlackApp設定を更新しました",
     "updated_slackApp": "SlackApp設定を更新しました",
-    "add_notification_pattern": "通知パターンを追加しました。"
+    "add_notification_pattern": "通知パターンを追加しました。",
+    "delete_notification_pattern": "通知パターンを削除しました。",
+    "delete_notification_pattern_desc1": "Path: {{path}} を削除します。",
+    "delete_notification_pattern_desc2": "Once deleted, it cannot be recovered"
   },
   },
   "customize_page": {
   "customize_page": {
     "recommended": "おすすめ",
     "recommended": "おすすめ",

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

@@ -2,15 +2,54 @@ import React from 'react';
 import PropTypes from 'prop-types';
 import PropTypes from 'prop-types';
 import { withTranslation } from 'react-i18next';
 import { withTranslation } from 'react-i18next';
 import urljoin from 'url-join';
 import urljoin from 'url-join';
+import loggerFactory from '@alias/logger';
 
 
 import { createSubscribedElement } from '../../UnstatedUtils';
 import { createSubscribedElement } from '../../UnstatedUtils';
+import { toastSuccess, toastError } from '../../../util/apiNotification';
 
 
 import AppContainer from '../../../services/AppContainer';
 import AppContainer from '../../../services/AppContainer';
 import AdminNotificationContainer from '../../../services/AdminNotificationContainer';
 import AdminNotificationContainer from '../../../services/AdminNotificationContainer';
+import NotificationDeleteModal from './NotificationDeleteModal';
 
 
+const logger = loggerFactory('growi:GolobalNotificationList');
 
 
 class GlobalNotificationList extends React.Component {
 class GlobalNotificationList extends React.Component {
 
 
+  constructor(props) {
+    super(props);
+
+    this.state = {
+      isConfirmationModalOpen: false,
+      notificatiionForConfiguration: null,
+    };
+
+    this.openConfirmationModal = this.openConfirmationModal.bind(this);
+    this.closeConfirmationModal = this.closeConfirmationModal.bind(this);
+    this.onClickSubmit = this.onClickSubmit.bind(this);
+  }
+
+  openConfirmationModal(notificatiion) {
+    this.setState({ isConfirmationModalOpen: true, notificatiionForConfiguration: notificatiion });
+  }
+
+  closeConfirmationModal() {
+    this.setState({ isConfirmationModalOpen: false, notificatiionForConfiguration: null });
+  }
+
+  async onClickSubmit() {
+    const { t, adminNotificationContainer } = this.props;
+
+    try {
+      await adminNotificationContainer.deleteGlobalNotificationPattern(this.state.notificatiionForConfiguration);
+      toastSuccess(t('notification_setting.delete_notification_pattern'));
+    }
+    catch (err) {
+      toastError(err);
+      logger.error(err);
+    }
+    this.setState({ isConfirmationModalOpen: false });
+  }
+
   render() {
   render() {
     const { t, adminNotificationContainer } = this.props;
     const { t, adminNotificationContainer } = this.props;
     const { globalNotifications } = adminNotificationContainer.state;
     const { globalNotifications } = adminNotificationContainer.state;
@@ -76,24 +115,25 @@ class GlobalNotificationList extends React.Component {
                         <i className="icon-fw icon-note"></i> {t('Edit')}
                         <i className="icon-fw icon-note"></i> {t('Edit')}
                       </a>
                       </a>
                     </li>
                     </li>
-                    {/*  TODO GW-780 create delete modal  */}
-                    <li className="btn-delete">
-                      <a
-                        href="#"
-                        data-setting-id="{{ notification.id }}"
-                        data-target="#admin-delete-global-notification"
-                        data-toggle="modal"
-                      >
+                    <li onClick={() => this.openConfirmationModal(notification)}>
+                      <a>
                         <i className="icon-fw icon-fire text-danger"></i> {t('Delete')}
                         <i className="icon-fw icon-fire text-danger"></i> {t('Delete')}
                       </a>
                       </a>
                     </li>
                     </li>
-
                   </ul>
                   </ul>
                 </div>
                 </div>
               </td>
               </td>
             </tr>
             </tr>
           );
           );
         })}
         })}
+        {this.state.notificatiionForConfiguration != null && (
+          <NotificationDeleteModal
+            isOpen={this.state.isConfirmationModalOpen}
+            onClose={this.closeConfirmationModal}
+            onClickSubmit={this.onClickSubmit}
+            notificatiionForConfiguration={this.state.notificatiionForConfiguration}
+          />
+        )}
       </React.Fragment>
       </React.Fragment>
     );
     );
 
 

+ 48 - 0
src/client/js/components/Admin/Notification/NotificationDeleteModal.jsx

@@ -0,0 +1,48 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+import { withTranslation } from 'react-i18next';
+
+import Modal from 'react-bootstrap/es/Modal';
+
+class NotificationDeleteModal extends React.PureComponent {
+
+  render() {
+    const { t, notificatiionForConfiguration } = this.props;
+    return (
+      <Modal show={this.props.isOpen} onHide={this.props.onClose}>
+        <Modal.Header className="modal-header" closeButton>
+          <Modal.Title>
+            <div className="modal-header bg-danger">
+              <i className="icon icon-fire"></i> Delete Global Notification Setting
+            </div>
+          </Modal.Title>
+        </Modal.Header>
+        <Modal.Body>
+          <p>
+            {t('notification_setting.delete_notification_pattern_desc1', { path: notificatiionForConfiguration.triggerPath })}
+          </p>
+          <span className="text-danger">
+            {t('notification_setting.delete_notification_pattern_desc2')}
+          </span>
+        </Modal.Body>
+        <Modal.Footer className="text-right">
+          <button type="button" className="btn btn-sm btn-danger" onClick={this.props.onClickSubmit}>
+            <i className="icon icon-fire"></i> {t('Delete')}
+          </button>
+        </Modal.Footer>
+      </Modal>
+    );
+  }
+
+}
+
+NotificationDeleteModal.propTypes = {
+  t: PropTypes.func.isRequired, // i18next
+
+  isOpen: PropTypes.bool.isRequired,
+  onClose: PropTypes.func.isRequired,
+  onClickSubmit: PropTypes.func.isRequired,
+  notificatiionForConfiguration: PropTypes.object.isRequired,
+};
+
+export default withTranslation()(NotificationDeleteModal);

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

@@ -114,4 +114,11 @@ export default class AdminNotificationContainer extends Container {
     this.setState({ userNotifications: response.data.responseParams.userNotifications });
     this.setState({ userNotifications: response.data.responseParams.userNotifications });
   }
   }
 
 
+  /**
+   * Delete global notification pattern
+   */
+  async deleteGlobalNotificationPattern(notificatiionId) {
+    // TODO GW-780 create apiV3
+  }
+
 }
 }