Просмотр исходного кода

create showToasterByEmailList func

Shun Miyazawa 4 лет назад
Родитель
Сommit
0a101c38da
1 измененных файлов с 22 добавлено и 8 удалено
  1. 22 8
      src/client/js/components/Admin/Users/UserInviteModal.jsx

+ 22 - 8
src/client/js/components/Admin/Users/UserInviteModal.jsx

@@ -41,6 +41,24 @@ class UserInviteModal extends React.Component {
     toastSuccess('Copied Mail and Password');
   }
 
+  showToasterByEmailList(emailList, toast) {
+    let msg = '';
+    emailList.forEach((email) => {
+      msg += `${email}\n`;
+    });
+    switch (toast) {
+      case 'success':
+        toastSuccess(msg);
+        break;
+      case 'warning':
+        toastWarning(msg);
+        break;
+      case 'error':
+        toastError(msg);
+        break;
+    }
+  }
+
   renderModalBody() {
     const { t } = this.props;
 
@@ -193,16 +211,12 @@ class UserInviteModal extends React.Component {
 
     try {
       const emailList = await adminUsersContainer.createUserInvited(shapedEmailList, this.state.sendEmail);
-      const existingEmailList = emailList.existingEmailList;
-      if (existingEmailList.length > 0) {
-        let msg = 'Email addresses already exist\n\n';
-        existingEmailList.forEach((email) => {
-          msg += `${email}\n`;
-        });
-        toastWarning(msg);
-      }
       this.setState({ emailInputValue: '' });
       this.setState({ invitedEmailList: emailList });
+
+      if (emailList.existingEmailList.length > 0) {
+        this.showToasterByEmailList(emailList.existingEmailList, 'warning');
+      }
     }
     catch (err) {
       toastError(err);