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 | {{ |
| 33 | $t('pageLocalUserManagement.modal.passwordMustBeBetween', { |
| 34 | min: passwordRequirements.minLength, |
| 35 | max: passwordRequirements.maxLength |
| 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)" |
| 46 | @input="$v.form.newPassword.$touch()" |
| 47 | /> |
| 48 | <b-form-invalid-feedback role="alert"> |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 49 | <template |
| 50 | v-if=" |
| 51 | !$v.form.newPassword.minLength || |
| 52 | !$v.form.newPassword.maxLength |
| 53 | " |
| 54 | > |
| 55 | {{ |
Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame^] | 56 | $t('pageProfileSettings.newPassLabelTextInfo', { |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 57 | min: passwordRequirements.minLength, |
| 58 | max: passwordRequirements.maxLength |
| 59 | }) |
| 60 | }} |
| 61 | </template> |
| 62 | </b-form-invalid-feedback> |
| 63 | </input-password-toggle> |
| 64 | </b-form-group> |
| 65 | <b-form-group |
| 66 | id="input-group-2" |
Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame^] | 67 | :label="$t('pageProfileSettings.confirmPassword')" |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 68 | label-for="input-2" |
| 69 | > |
| 70 | <input-password-toggle> |
| 71 | <b-form-input |
| 72 | id="password-confirmation" |
| 73 | v-model="form.confirmPassword" |
| 74 | type="password" |
| 75 | :state="getValidationState($v.form.confirmPassword)" |
| 76 | @input="$v.form.confirmPassword.$touch()" |
| 77 | /> |
| 78 | <b-form-invalid-feedback role="alert"> |
Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame^] | 79 | <template v-if="!$v.form.confirmPassword.sameAsPassword"> |
| 80 | {{ $t('pageProfileSettings.passwordsDoNotMatch') }} |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 81 | </template> |
| 82 | </b-form-invalid-feedback> |
| 83 | </input-password-toggle> |
| 84 | </b-form-group> |
| 85 | </page-section> |
| 86 | </b-col> |
| 87 | </b-row> |
Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame^] | 88 | <page-section :section-title="$t('pageProfileSettings.timezoneDisplay')"> |
| 89 | <p>{{ $t('pageProfileSettings.timezoneDisplayDesc') }}</p> |
| 90 | <b-row> |
| 91 | <b-col md="9" lg="8" xl="9"> |
| 92 | <b-form-group :label="$t('pageProfileSettings.timezone')"> |
| 93 | <b-form-radio |
| 94 | v-model="form.isUtcDisplay" |
| 95 | :value="true" |
| 96 | @change="$v.form.isUtcDisplay.$touch()" |
| 97 | > |
| 98 | {{ $t('pageProfileSettings.defaultUTC') }} |
| 99 | </b-form-radio> |
| 100 | <b-form-radio |
| 101 | v-model="form.isUtcDisplay" |
| 102 | :value="false" |
| 103 | @change="$v.form.isUtcDisplay.$touch()" |
| 104 | > |
| 105 | {{ |
| 106 | $t('pageProfileSettings.browserOffset', { |
| 107 | timezone |
| 108 | }) |
| 109 | }} |
| 110 | </b-form-radio> |
| 111 | </b-form-group> |
| 112 | </b-col> |
| 113 | </b-row> |
| 114 | </page-section> |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 115 | <b-button variant="primary" type="submit"> |
Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame^] | 116 | {{ $t('global.action.saveSettings') }} |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 117 | </b-button> |
| 118 | </b-form> |
| 119 | </b-container> |
| 120 | </template> |
| 121 | |
| 122 | <script> |
Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame^] | 123 | import i18n from '@/i18n'; |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 124 | import BVToastMixin from '@/components/Mixins/BVToastMixin'; |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 125 | import InputPasswordToggle from '@/components/Global/InputPasswordToggle'; |
Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame^] | 126 | import { format } from 'date-fns-tz'; |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 127 | import { |
| 128 | maxLength, |
| 129 | minLength, |
| 130 | required, |
| 131 | sameAs |
| 132 | } from 'vuelidate/lib/validators'; |
Sukanya Pandey | b93608d | 2020-07-10 18:51:58 +0530 | [diff] [blame] | 133 | import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin'; |
| 134 | import PageTitle from '@/components/Global/PageTitle'; |
| 135 | import PageSection from '@/components/Global/PageSection'; |
| 136 | import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js'; |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 137 | |
| 138 | export default { |
| 139 | name: 'ProfileSettings', |
Sukanya Pandey | b93608d | 2020-07-10 18:51:58 +0530 | [diff] [blame] | 140 | components: { InputPasswordToggle, PageSection, PageTitle }, |
| 141 | mixins: [BVToastMixin, LoadingBarMixin, VuelidateMixin], |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 142 | data() { |
| 143 | return { |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 144 | form: { |
| 145 | newPassword: '', |
Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame^] | 146 | confirmPassword: '', |
| 147 | isUtcDisplay: this.$store.getters['global/isUtcDisplay'] |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 148 | } |
| 149 | }; |
| 150 | }, |
Sukanya Pandey | b93608d | 2020-07-10 18:51:58 +0530 | [diff] [blame] | 151 | computed: { |
| 152 | username() { |
| 153 | return this.$store.getters['global/username']; |
| 154 | }, |
| 155 | passwordRequirements() { |
| 156 | return this.$store.getters['localUsers/accountPasswordRequirements']; |
Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame^] | 157 | }, |
| 158 | timezone() { |
| 159 | const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone; |
| 160 | const shortTz = this.$options.filters.shortTimeZone(new Date()); |
| 161 | const pattern = `'${shortTz}' O`; |
| 162 | return format(new Date(), pattern, { timezone }).replace('GMT', 'UTC'); |
Sukanya Pandey | b93608d | 2020-07-10 18:51:58 +0530 | [diff] [blame] | 163 | } |
| 164 | }, |
| 165 | created() { |
| 166 | this.startLoader(); |
| 167 | this.$store |
| 168 | .dispatch('localUsers/getAccountSettings') |
| 169 | .finally(() => this.endLoader()); |
| 170 | }, |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 171 | validations() { |
| 172 | return { |
| 173 | form: { |
Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame^] | 174 | isUtcDisplay: { required }, |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 175 | newPassword: { |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 176 | minLength: minLength(this.passwordRequirements.minLength), |
| 177 | maxLength: maxLength(this.passwordRequirements.maxLength) |
| 178 | }, |
| 179 | confirmPassword: { |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 180 | sameAsPassword: sameAs('newPassword') |
| 181 | } |
| 182 | } |
| 183 | }; |
| 184 | }, |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 185 | methods: { |
Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame^] | 186 | saveNewPasswordInputData() { |
| 187 | this.$v.form.confirmPassword.$touch(); |
| 188 | this.$v.form.newPassword.$touch(); |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 189 | if (this.$v.$invalid) return; |
| 190 | let userData = { |
| 191 | originalUsername: this.username, |
| 192 | password: this.form.newPassword |
| 193 | }; |
| 194 | |
| 195 | this.$store |
| 196 | .dispatch('localUsers/updateUser', userData) |
Sukanya Pandey | 9422e1a | 2020-07-13 19:13:07 +0530 | [diff] [blame] | 197 | .then(message => { |
| 198 | (this.form.newPassword = ''), (this.form.confirmPassword = ''); |
| 199 | this.$v.$reset(); |
| 200 | this.successToast(message); |
| 201 | }) |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 202 | .catch(({ message }) => this.errorToast(message)); |
Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame^] | 203 | }, |
| 204 | saveTimeZonePrefrenceData() { |
| 205 | localStorage.setItem('storedUtcDisplay', this.form.isUtcDisplay); |
| 206 | this.$store.commit('global/setUtcTime', this.form.isUtcDisplay); |
| 207 | this.successToast( |
| 208 | i18n.t('pageProfileSettings.toast.successSaveSettings') |
| 209 | ); |
| 210 | }, |
| 211 | submitForm() { |
| 212 | if (this.form.confirmPassword || this.form.newPassword) { |
| 213 | this.saveNewPasswordInputData(); |
| 214 | } |
| 215 | if (this.$v.form.isUtcDisplay.$anyDirty) { |
| 216 | this.saveTimeZonePrefrenceData(); |
| 217 | } |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 218 | } |
| 219 | } |
| 220 | }; |
| 221 | </script> |