mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-10-31 02:57:57 +00:00 
			
		
		
		
	Add option to reset password of agents to Admin (#351)
* Add option to reset password of agents to Admin * Fix copy, remove setTimeout
This commit is contained in:
		 Mukesh Chaudhary
					Mukesh Chaudhary
				
			
				
					committed by
					
						 Sojan Jose
						Sojan Jose
					
				
			
			
				
	
			
			
			 Sojan Jose
						Sojan Jose
					
				
			
						parent
						
							cef1200351
						
					
				
				
					commit
					5b275ea157
				
			| @@ -80,9 +80,16 @@ | |||||||
|         "SUBMIT": "Edit Agent" |         "SUBMIT": "Edit Agent" | ||||||
|       }, |       }, | ||||||
|       "BUTTON_TEXT": "Edit", |       "BUTTON_TEXT": "Edit", | ||||||
|  |       "CANCEL_BUTTON_TEXT": "Cancel", | ||||||
|       "API": { |       "API": { | ||||||
|         "SUCCESS_MESSAGE": "Agent updated successfully", |         "SUCCESS_MESSAGE": "Agent updated successfully", | ||||||
|         "ERROR_MESSAGE": "Could not connect to Woot Server, Please try again later" |         "ERROR_MESSAGE": "Could not connect to Woot Server, Please try again later" | ||||||
|  |       }, | ||||||
|  |       "PASSWORD_RESET": { | ||||||
|  |         "ADMIN_RESET_BUTTON": "Reset Password", | ||||||
|  |         "ADMIN_SUCCESS_MESSAGE": "An email with reset password instructions has been sent to the agent", | ||||||
|  |         "SUCCESS_MESSAGE": "Agent password reset successfully", | ||||||
|  |         "ERROR_MESSAGE": "Could not connect to Woot Server, Please try again later" | ||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|     "SEARCH": { |     "SEARCH": { | ||||||
|   | |||||||
| @@ -1,19 +1,22 @@ | |||||||
| <template> | <template> | ||||||
|   <modal :show.sync="show" :on-close="onClose"> |   <modal :show.sync="show" :on-close="onClose"> | ||||||
|     <div class="column content-box"> |     <div class="column content-box"> | ||||||
|       <woot-modal-header |       <woot-modal-header :header-title="pageTitle" /> | ||||||
|         :header-title="pageTitle" |       <form class="row medium-8" @submit.prevent="editAgent()"> | ||||||
|       /> |  | ||||||
|       <form class="row medium-8" v-on:submit.prevent="editAgent()"> |  | ||||||
|         <div class="medium-12 columns"> |         <div class="medium-12 columns"> | ||||||
|           <label :class="{ 'error': $v.agentName.$error }"> |           <label :class="{ error: $v.agentName.$error }"> | ||||||
|             {{ $t('AGENT_MGMT.EDIT.FORM.NAME.LABEL') }} |             {{ $t('AGENT_MGMT.EDIT.FORM.NAME.LABEL') }} | ||||||
|             <input type="text" v-model.trim="agentName" @input="$v.agentName.$touch" :placeholder="$t('AGENT_MGMT.EDIT.FORM.NAME.PLACEHOLDER')"> |             <input | ||||||
|  |               v-model.trim="agentName" | ||||||
|  |               type="text" | ||||||
|  |               :placeholder="$t('AGENT_MGMT.EDIT.FORM.NAME.PLACEHOLDER')" | ||||||
|  |               @input="$v.agentName.$touch" | ||||||
|  |             /> | ||||||
|           </label> |           </label> | ||||||
|         </div> |         </div> | ||||||
|  |  | ||||||
|         <div class="medium-12 columns"> |         <div class="medium-12 columns"> | ||||||
|           <label :class="{ 'error': $v.agentType.$error }"> |           <label :class="{ error: $v.agentType.$error }"> | ||||||
|             {{ $t('AGENT_MGMT.EDIT.FORM.AGENT_TYPE.LABEL') }} |             {{ $t('AGENT_MGMT.EDIT.FORM.AGENT_TYPE.LABEL') }} | ||||||
|             <multiselect |             <multiselect | ||||||
|               v-model.trim="agentType" |               v-model.trim="agentType" | ||||||
| @@ -23,19 +26,31 @@ | |||||||
|               :searchable="false" |               :searchable="false" | ||||||
|               @select="setPageName" |               @select="setPageName" | ||||||
|             /> |             /> | ||||||
|             <span class="message" v-if="$v.agentType.$error"> |             <span v-if="$v.agentType.$error" class="message"> | ||||||
|               {{ $t('AGENT_MGMT.EDIT.FORM.AGENT_TYPE.ERROR') }} |               {{ $t('AGENT_MGMT.EDIT.FORM.AGENT_TYPE.ERROR') }} | ||||||
|             </span> |             </span> | ||||||
|           </label> |           </label> | ||||||
|         </div> |         </div> | ||||||
|         <div class="modal-footer"> |         <div class="medium-12 modal-footer"> | ||||||
|           <div class="medium-12 columns"> |           <div class="medium-6 columns"> | ||||||
|             <woot-submit-button |             <woot-submit-button | ||||||
|               :disabled="$v.agentType.$invalid || $v.agentName.$invalid || editAgentsApi.showLoading" |               :disabled=" | ||||||
|  |                 $v.agentType.$invalid || | ||||||
|  |                   $v.agentName.$invalid || | ||||||
|  |                   editAgentsApi.showLoading | ||||||
|  |               " | ||||||
|               :button-text="$t('AGENT_MGMT.EDIT.FORM.SUBMIT')" |               :button-text="$t('AGENT_MGMT.EDIT.FORM.SUBMIT')" | ||||||
|               :loading="editAgentsApi.showLoading" |               :loading="editAgentsApi.showLoading" | ||||||
|             /> |             /> | ||||||
|             <a @click="onClose">Cancel</a> |             <a @click="onClose"> | ||||||
|  |               {{ $t('AGENT_MGMT.EDIT.CANCEL_BUTTON_TEXT') }} | ||||||
|  |             </a> | ||||||
|  |           </div> | ||||||
|  |           <div class="medium-6 columns text-right"> | ||||||
|  |             <a @click="resetPassword"> | ||||||
|  |               <i class="ion-locked"></i> | ||||||
|  |               {{ $t('AGENT_MGMT.EDIT.PASSWORD_RESET.ADMIN_RESET_BUTTON') }} | ||||||
|  |             </a> | ||||||
|           </div> |           </div> | ||||||
|         </div> |         </div> | ||||||
|       </form> |       </form> | ||||||
| @@ -48,19 +63,19 @@ | |||||||
| /* eslint no-console: 0 */ | /* eslint no-console: 0 */ | ||||||
| import { required, minLength } from 'vuelidate/lib/validators'; | import { required, minLength } from 'vuelidate/lib/validators'; | ||||||
|  |  | ||||||
| import PageHeader from '../SettingsSubPageHeader'; |  | ||||||
| import WootSubmitButton from '../../../../components/buttons/FormSubmitButton'; | import WootSubmitButton from '../../../../components/buttons/FormSubmitButton'; | ||||||
| import Modal from '../../../../components/Modal'; | import Modal from '../../../../components/Modal'; | ||||||
|  | import Auth from '../../../../api/auth'; | ||||||
|  |  | ||||||
| export default { | export default { | ||||||
|   components: { |   components: { | ||||||
|     PageHeader, |  | ||||||
|     WootSubmitButton, |     WootSubmitButton, | ||||||
|     Modal, |     Modal, | ||||||
|   }, |   }, | ||||||
|   props: { |   props: { | ||||||
|     id: Number, |     id: Number, | ||||||
|     name: String, |     name: String, | ||||||
|  |     email: String, | ||||||
|     type: String, |     type: String, | ||||||
|     onClose: Function, |     onClose: Function, | ||||||
|   }, |   }, | ||||||
| @@ -77,6 +92,9 @@ export default { | |||||||
|         name: this.type, |         name: this.type, | ||||||
|         label: this.type, |         label: this.type, | ||||||
|       }, |       }, | ||||||
|  |       agentCredentials: { | ||||||
|  |         email: this.email, | ||||||
|  |       }, | ||||||
|       show: true, |       show: true, | ||||||
|     }; |     }; | ||||||
|   }, |   }, | ||||||
| @@ -103,7 +121,8 @@ export default { | |||||||
|       bus.$emit('newToastMessage', this.editAgentsApi.message); |       bus.$emit('newToastMessage', this.editAgentsApi.message); | ||||||
|     }, |     }, | ||||||
|     resetForm() { |     resetForm() { | ||||||
|       this.agentName = this.agentType = ''; |       this.agentName = ''; | ||||||
|  |       this.agentType = ''; | ||||||
|       this.$v.agentName.$reset(); |       this.$v.agentName.$reset(); | ||||||
|       this.$v.agentType.$reset(); |       this.$v.agentType.$reset(); | ||||||
|     }, |     }, | ||||||
| @@ -111,26 +130,47 @@ export default { | |||||||
|       // Show loading on button |       // Show loading on button | ||||||
|       this.editAgentsApi.showLoading = true; |       this.editAgentsApi.showLoading = true; | ||||||
|       // Make API Calls |       // Make API Calls | ||||||
|       this.$store.dispatch('editAgent', { |       this.$store | ||||||
|         id: this.id, |         .dispatch('editAgent', { | ||||||
|         name: this.agentName, |           id: this.id, | ||||||
|         role: this.agentType.name.toLowerCase(), |           name: this.agentName, | ||||||
|       }) |           role: this.agentType.name.toLowerCase(), | ||||||
|       .then(() => { |         }) | ||||||
|         // Reset Form, Show success message |         .then(() => { | ||||||
|         this.editAgentsApi.showLoading = false; |           // Reset Form, Show success message | ||||||
|         this.editAgentsApi.message = this.$t('AGENT_MGMT.EDIT.API.SUCCESS_MESSAGE'); |           this.editAgentsApi.showLoading = false; | ||||||
|         this.showAlert(); |           this.editAgentsApi.message = this.$t( | ||||||
|         this.resetForm(); |             'AGENT_MGMT.EDIT.API.SUCCESS_MESSAGE' | ||||||
|         setTimeout(() => { |           ); | ||||||
|           this.onClose(); |           this.showAlert(); | ||||||
|         }, 10); |           this.resetForm(); | ||||||
|       }) |           setTimeout(() => { | ||||||
|       .catch(() => { |             this.onClose(); | ||||||
|         this.editAgentsApi.showLoading = false; |           }, 10); | ||||||
|         this.editAgentsApi.message = this.$t('AGENT_MGMT.EDIT.API.ERROR_MESSAGE'); |         }) | ||||||
|         this.showAlert(); |         .catch(() => { | ||||||
|       }); |           this.editAgentsApi.showLoading = false; | ||||||
|  |           this.editAgentsApi.message = this.$t( | ||||||
|  |             'AGENT_MGMT.EDIT.API.ERROR_MESSAGE' | ||||||
|  |           ); | ||||||
|  |           this.showAlert(); | ||||||
|  |         }); | ||||||
|  |     }, | ||||||
|  |     resetPassword() { | ||||||
|  |       // Call resetPassword from Auth Service | ||||||
|  |       Auth.resetPassword(this.agentCredentials) | ||||||
|  |         .then(() => { | ||||||
|  |           this.editAgentsApi.message = this.$t( | ||||||
|  |             'AGENT_MGMT.EDIT.PASSWORD_RESET.ADMIN_SUCCESS_MESSAGE' | ||||||
|  |           ); | ||||||
|  |           this.showAlert(); | ||||||
|  |         }) | ||||||
|  |         .catch(() => { | ||||||
|  |           this.editAgentsApi.message = this.$t( | ||||||
|  |             'AGENT_MGMT.EDIT.PASSWORD_RESET.ERROR_MESSAGE' | ||||||
|  |           ); | ||||||
|  |           this.showAlert(); | ||||||
|  |         }); | ||||||
|     }, |     }, | ||||||
|   }, |   }, | ||||||
| }; | }; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user