Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 1 | <template> |
| 2 | <b-container fluid="xl"> |
| 3 | <page-title /> |
| 4 | |
| 5 | <b-row> |
| 6 | <b-col md="8" lg="8" xl="6"> |
Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 7 | <page-section |
| 8 | :section-title="$t('pageProfileSettings.profileInfoTitle')" |
| 9 | > |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 10 | <dl> |
Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 11 | <dt>{{ $t('pageProfileSettings.username') }}</dt> |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 12 | <dd> |
| 13 | {{ username }} |
| 14 | </dd> |
| 15 | </dl> |
| 16 | </page-section> |
| 17 | </b-col> |
| 18 | </b-row> |
| 19 | |
| 20 | <b-form @submit.prevent="submitForm"> |
| 21 | <b-row> |
| 22 | <b-col sm="8" md="6" xl="3"> |
Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 23 | <page-section |
| 24 | :section-title="$t('pageProfileSettings.changePassword')" |
| 25 | > |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 26 | <b-form-group |
| 27 | id="input-group-1" |
Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 28 | :label="$t('pageProfileSettings.newPassword')" |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 29 | label-for="input-1" |
| 30 | > |
| 31 | <b-form-text id="password-help-block"> |
| 32 | {{ |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 33 | $t('pageUserManagement.modal.passwordMustBeBetween', { |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 34 | min: passwordRequirements.minLength, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 35 | max: passwordRequirements.maxLength, |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 36 | }) |
| 37 | }} |
| 38 | </b-form-text> |
| 39 | <input-password-toggle> |
| 40 | <b-form-input |
| 41 | id="password" |
| 42 | v-model="form.newPassword" |
| 43 | type="password" |
| 44 | aria-describedby="password-help-block" |
| 45 | :state="getValidationState($v.form.newPassword)" |
Sukanya Pandey | 4334d26 | 2020-07-29 11:12:06 +0530 | [diff] [blame] | 46 | data-test-id="profileSettings-input-newPassword" |
Dixsie Wolmers | 5ea1678 | 2020-07-27 17:50:43 -0500 | [diff] [blame] | 47 | class="form-control-with-button" |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 48 | @input="$v.form.newPassword.$touch()" |
| 49 | /> |
| 50 | <b-form-invalid-feedback role="alert"> |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 51 | <template |
| 52 | v-if=" |
| 53 | !$v.form.newPassword.minLength || |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 54 | !$v.form.newPassword.maxLength |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 55 | " |
| 56 | > |
| 57 | {{ |
Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 58 | $t('pageProfileSettings.newPassLabelTextInfo', { |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 59 | min: passwordRequirements.minLength, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 60 | max: passwordRequirements.maxLength, |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 61 | }) |
| 62 | }} |
| 63 | </template> |
| 64 | </b-form-invalid-feedback> |
| 65 | </input-password-toggle> |
| 66 | </b-form-group> |
| 67 | <b-form-group |
| 68 | id="input-group-2" |
Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 69 | :label="$t('pageProfileSettings.confirmPassword')" |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 70 | label-for="input-2" |
| 71 | > |
| 72 | <input-password-toggle> |
| 73 | <b-form-input |
| 74 | id="password-confirmation" |
| 75 | v-model="form.confirmPassword" |
| 76 | type="password" |
| 77 | :state="getValidationState($v.form.confirmPassword)" |
Sukanya Pandey | 4334d26 | 2020-07-29 11:12:06 +0530 | [diff] [blame] | 78 | data-test-id="profileSettings-input-confirmPassword" |
Dixsie Wolmers | 5ea1678 | 2020-07-27 17:50:43 -0500 | [diff] [blame] | 79 | class="form-control-with-button" |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 80 | @input="$v.form.confirmPassword.$touch()" |
| 81 | /> |
| 82 | <b-form-invalid-feedback role="alert"> |
Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 83 | <template v-if="!$v.form.confirmPassword.sameAsPassword"> |
| 84 | {{ $t('pageProfileSettings.passwordsDoNotMatch') }} |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 85 | </template> |
| 86 | </b-form-invalid-feedback> |
| 87 | </input-password-toggle> |
| 88 | </b-form-group> |
| 89 | </page-section> |
| 90 | </b-col> |
| 91 | </b-row> |
Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 92 | <page-section :section-title="$t('pageProfileSettings.timezoneDisplay')"> |
| 93 | <p>{{ $t('pageProfileSettings.timezoneDisplayDesc') }}</p> |
| 94 | <b-row> |
| 95 | <b-col md="9" lg="8" xl="9"> |
| 96 | <b-form-group :label="$t('pageProfileSettings.timezone')"> |
| 97 | <b-form-radio |
| 98 | v-model="form.isUtcDisplay" |
| 99 | :value="true" |
Sukanya Pandey | 4334d26 | 2020-07-29 11:12:06 +0530 | [diff] [blame] | 100 | data-test-id="profileSettings-radio-defaultUTC" |
Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 101 | > |
| 102 | {{ $t('pageProfileSettings.defaultUTC') }} |
| 103 | </b-form-radio> |
| 104 | <b-form-radio |
| 105 | v-model="form.isUtcDisplay" |
| 106 | :value="false" |
Sukanya Pandey | 4334d26 | 2020-07-29 11:12:06 +0530 | [diff] [blame] | 107 | data-test-id="profileSettings-radio-browserOffset" |
Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 108 | > |
| 109 | {{ |
| 110 | $t('pageProfileSettings.browserOffset', { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 111 | timezone, |
Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 112 | }) |
| 113 | }} |
| 114 | </b-form-radio> |
| 115 | </b-form-group> |
| 116 | </b-col> |
| 117 | </b-row> |
| 118 | </page-section> |
Sukanya Pandey | 4334d26 | 2020-07-29 11:12:06 +0530 | [diff] [blame] | 119 | <b-button |
| 120 | variant="primary" |
| 121 | type="submit" |
| 122 | data-test-id="profileSettings-button-saveSettings" |
| 123 | > |
Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 124 | {{ $t('global.action.saveSettings') }} |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 125 | </b-button> |
| 126 | </b-form> |
| 127 | </b-container> |
| 128 | </template> |
| 129 | |
| 130 | <script> |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 131 | import BVToastMixin from '@/components/Mixins/BVToastMixin'; |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 132 | import InputPasswordToggle from '@/components/Global/InputPasswordToggle'; |
Sukanya Pandey | 570a74f | 2020-12-21 16:12:05 +0530 | [diff] [blame] | 133 | import { maxLength, minLength, sameAs } from 'vuelidate/lib/validators'; |
Sukanya Pandey | b93608d | 2020-07-10 18:51:58 +0530 | [diff] [blame] | 134 | import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin'; |
Dixsie Wolmers | fcda200 | 2020-07-29 14:18:44 -0500 | [diff] [blame] | 135 | import LocalTimezoneLabelMixin from '@/components/Mixins/LocalTimezoneLabelMixin'; |
Sukanya Pandey | b93608d | 2020-07-10 18:51:58 +0530 | [diff] [blame] | 136 | import PageTitle from '@/components/Global/PageTitle'; |
| 137 | import PageSection from '@/components/Global/PageSection'; |
| 138 | import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js'; |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 139 | |
| 140 | export default { |
| 141 | name: 'ProfileSettings', |
Sukanya Pandey | b93608d | 2020-07-10 18:51:58 +0530 | [diff] [blame] | 142 | components: { InputPasswordToggle, PageSection, PageTitle }, |
Dixsie Wolmers | fcda200 | 2020-07-29 14:18:44 -0500 | [diff] [blame] | 143 | mixins: [ |
| 144 | BVToastMixin, |
| 145 | LocalTimezoneLabelMixin, |
| 146 | LoadingBarMixin, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 147 | VuelidateMixin, |
Dixsie Wolmers | fcda200 | 2020-07-29 14:18:44 -0500 | [diff] [blame] | 148 | ], |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 149 | data() { |
| 150 | return { |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 151 | form: { |
| 152 | newPassword: '', |
Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 153 | confirmPassword: '', |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 154 | isUtcDisplay: this.$store.getters['global/isUtcDisplay'], |
| 155 | }, |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 156 | }; |
| 157 | }, |
Sukanya Pandey | b93608d | 2020-07-10 18:51:58 +0530 | [diff] [blame] | 158 | computed: { |
| 159 | username() { |
| 160 | return this.$store.getters['global/username']; |
| 161 | }, |
| 162 | passwordRequirements() { |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 163 | return this.$store.getters['userManagement/accountPasswordRequirements']; |
Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 164 | }, |
| 165 | timezone() { |
Dixsie Wolmers | fcda200 | 2020-07-29 14:18:44 -0500 | [diff] [blame] | 166 | return this.localOffset(); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 167 | }, |
Sukanya Pandey | b93608d | 2020-07-10 18:51:58 +0530 | [diff] [blame] | 168 | }, |
| 169 | created() { |
| 170 | this.startLoader(); |
| 171 | this.$store |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 172 | .dispatch('userManagement/getAccountSettings') |
Sukanya Pandey | b93608d | 2020-07-10 18:51:58 +0530 | [diff] [blame] | 173 | .finally(() => this.endLoader()); |
| 174 | }, |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 175 | validations() { |
| 176 | return { |
| 177 | form: { |
| 178 | newPassword: { |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 179 | minLength: minLength(this.passwordRequirements.minLength), |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 180 | maxLength: maxLength(this.passwordRequirements.maxLength), |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 181 | }, |
| 182 | confirmPassword: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 183 | sameAsPassword: sameAs('newPassword'), |
| 184 | }, |
| 185 | }, |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 186 | }; |
| 187 | }, |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 188 | methods: { |
Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 189 | saveNewPasswordInputData() { |
| 190 | this.$v.form.confirmPassword.$touch(); |
| 191 | this.$v.form.newPassword.$touch(); |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 192 | if (this.$v.$invalid) return; |
| 193 | let userData = { |
| 194 | originalUsername: this.username, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 195 | password: this.form.newPassword, |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 196 | }; |
| 197 | |
| 198 | this.$store |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 199 | .dispatch('userManagement/updateUser', userData) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 200 | .then((message) => { |
Sukanya Pandey | 9422e1a | 2020-07-13 19:13:07 +0530 | [diff] [blame] | 201 | (this.form.newPassword = ''), (this.form.confirmPassword = ''); |
| 202 | this.$v.$reset(); |
| 203 | this.successToast(message); |
| 204 | }) |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 205 | .catch(({ message }) => this.errorToast(message)); |
Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 206 | }, |
| 207 | saveTimeZonePrefrenceData() { |
| 208 | localStorage.setItem('storedUtcDisplay', this.form.isUtcDisplay); |
| 209 | this.$store.commit('global/setUtcTime', this.form.isUtcDisplay); |
| 210 | this.successToast( |
Sandeepa Singh | 77e6490 | 2021-12-29 19:34:16 +0530 | [diff] [blame] | 211 | this.$t('pageProfileSettings.toast.successUpdatingTimeZone') |
Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 212 | ); |
| 213 | }, |
| 214 | submitForm() { |
| 215 | if (this.form.confirmPassword || this.form.newPassword) { |
| 216 | this.saveNewPasswordInputData(); |
| 217 | } |
Sukanya Pandey | 570a74f | 2020-12-21 16:12:05 +0530 | [diff] [blame] | 218 | this.saveTimeZonePrefrenceData(); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 219 | }, |
| 220 | }, |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 221 | }; |
| 222 | </script> |