blob: 8f01c59baeb25cdd1fc068f2fa02c07ad7282905 [file] [log] [blame]
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +05301<template>
2 <b-container fluid="xl">
3 <page-title />
4
5 <b-row>
6 <b-col md="8" lg="8" xl="6">
Sukanya Pandeyfc16f3c2020-06-23 22:54:27 +05307 <page-section
8 :section-title="$t('pageProfileSettings.profileInfoTitle')"
9 >
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053010 <dl>
Sukanya Pandeyfc16f3c2020-06-23 22:54:27 +053011 <dt>{{ $t('pageProfileSettings.username') }}</dt>
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053012 <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 Pandeyfc16f3c2020-06-23 22:54:27 +053023 <page-section
24 :section-title="$t('pageProfileSettings.changePassword')"
25 >
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053026 <b-form-group
27 id="input-group-1"
Sukanya Pandeyfc16f3c2020-06-23 22:54:27 +053028 :label="$t('pageProfileSettings.newPassword')"
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053029 label-for="input-1"
30 >
31 <b-form-text id="password-help-block">
32 {{
Sandeepa Singhb4406162021-07-26 15:05:39 +053033 $t('pageUserManagement.modal.passwordMustBeBetween', {
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053034 min: passwordRequirements.minLength,
Derick Montague602e98a2020-10-21 16:20:00 -050035 max: passwordRequirements.maxLength,
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053036 })
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 Pandey4334d262020-07-29 11:12:06 +053046 data-test-id="profileSettings-input-newPassword"
Dixsie Wolmers5ea16782020-07-27 17:50:43 -050047 class="form-control-with-button"
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053048 @input="$v.form.newPassword.$touch()"
49 />
50 <b-form-invalid-feedback role="alert">
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053051 <template
52 v-if="
53 !$v.form.newPassword.minLength ||
Derick Montague602e98a2020-10-21 16:20:00 -050054 !$v.form.newPassword.maxLength
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053055 "
56 >
57 {{
Sukanya Pandeyfc16f3c2020-06-23 22:54:27 +053058 $t('pageProfileSettings.newPassLabelTextInfo', {
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053059 min: passwordRequirements.minLength,
Derick Montague602e98a2020-10-21 16:20:00 -050060 max: passwordRequirements.maxLength,
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053061 })
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 Pandeyfc16f3c2020-06-23 22:54:27 +053069 :label="$t('pageProfileSettings.confirmPassword')"
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053070 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 Pandey4334d262020-07-29 11:12:06 +053078 data-test-id="profileSettings-input-confirmPassword"
Dixsie Wolmers5ea16782020-07-27 17:50:43 -050079 class="form-control-with-button"
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053080 @input="$v.form.confirmPassword.$touch()"
81 />
82 <b-form-invalid-feedback role="alert">
Sukanya Pandeyfc16f3c2020-06-23 22:54:27 +053083 <template v-if="!$v.form.confirmPassword.sameAsPassword">
84 {{ $t('pageProfileSettings.passwordsDoNotMatch') }}
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053085 </template>
86 </b-form-invalid-feedback>
87 </input-password-toggle>
88 </b-form-group>
89 </page-section>
90 </b-col>
91 </b-row>
Sukanya Pandeyfc16f3c2020-06-23 22:54:27 +053092 <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 Pandey4334d262020-07-29 11:12:06 +0530100 data-test-id="profileSettings-radio-defaultUTC"
Sukanya Pandeyfc16f3c2020-06-23 22:54:27 +0530101 >
102 {{ $t('pageProfileSettings.defaultUTC') }}
103 </b-form-radio>
104 <b-form-radio
105 v-model="form.isUtcDisplay"
106 :value="false"
Sukanya Pandey4334d262020-07-29 11:12:06 +0530107 data-test-id="profileSettings-radio-browserOffset"
Sukanya Pandeyfc16f3c2020-06-23 22:54:27 +0530108 >
109 {{
110 $t('pageProfileSettings.browserOffset', {
Derick Montague602e98a2020-10-21 16:20:00 -0500111 timezone,
Sukanya Pandeyfc16f3c2020-06-23 22:54:27 +0530112 })
113 }}
114 </b-form-radio>
115 </b-form-group>
116 </b-col>
117 </b-row>
118 </page-section>
Sukanya Pandey4334d262020-07-29 11:12:06 +0530119 <b-button
120 variant="primary"
121 type="submit"
122 data-test-id="profileSettings-button-saveSettings"
123 >
Sukanya Pandeyfc16f3c2020-06-23 22:54:27 +0530124 {{ $t('global.action.saveSettings') }}
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530125 </b-button>
126 </b-form>
127 </b-container>
128</template>
129
130<script>
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530131import BVToastMixin from '@/components/Mixins/BVToastMixin';
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530132import InputPasswordToggle from '@/components/Global/InputPasswordToggle';
Sukanya Pandey570a74f2020-12-21 16:12:05 +0530133import { maxLength, minLength, sameAs } from 'vuelidate/lib/validators';
Sukanya Pandeyb93608d2020-07-10 18:51:58 +0530134import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
Dixsie Wolmersfcda2002020-07-29 14:18:44 -0500135import LocalTimezoneLabelMixin from '@/components/Mixins/LocalTimezoneLabelMixin';
Sukanya Pandeyb93608d2020-07-10 18:51:58 +0530136import PageTitle from '@/components/Global/PageTitle';
137import PageSection from '@/components/Global/PageSection';
138import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530139
140export default {
141 name: 'ProfileSettings',
Sukanya Pandeyb93608d2020-07-10 18:51:58 +0530142 components: { InputPasswordToggle, PageSection, PageTitle },
Dixsie Wolmersfcda2002020-07-29 14:18:44 -0500143 mixins: [
144 BVToastMixin,
145 LocalTimezoneLabelMixin,
146 LoadingBarMixin,
Derick Montague602e98a2020-10-21 16:20:00 -0500147 VuelidateMixin,
Dixsie Wolmersfcda2002020-07-29 14:18:44 -0500148 ],
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530149 data() {
150 return {
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530151 form: {
152 newPassword: '',
Sukanya Pandeyfc16f3c2020-06-23 22:54:27 +0530153 confirmPassword: '',
Derick Montague602e98a2020-10-21 16:20:00 -0500154 isUtcDisplay: this.$store.getters['global/isUtcDisplay'],
155 },
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530156 };
157 },
Sukanya Pandeyb93608d2020-07-10 18:51:58 +0530158 computed: {
159 username() {
160 return this.$store.getters['global/username'];
161 },
162 passwordRequirements() {
Sandeepa Singhb4406162021-07-26 15:05:39 +0530163 return this.$store.getters['userManagement/accountPasswordRequirements'];
Sukanya Pandeyfc16f3c2020-06-23 22:54:27 +0530164 },
165 timezone() {
Dixsie Wolmersfcda2002020-07-29 14:18:44 -0500166 return this.localOffset();
Derick Montague602e98a2020-10-21 16:20:00 -0500167 },
Sukanya Pandeyb93608d2020-07-10 18:51:58 +0530168 },
169 created() {
170 this.startLoader();
171 this.$store
Sandeepa Singhb4406162021-07-26 15:05:39 +0530172 .dispatch('userManagement/getAccountSettings')
Sukanya Pandeyb93608d2020-07-10 18:51:58 +0530173 .finally(() => this.endLoader());
174 },
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530175 validations() {
176 return {
177 form: {
178 newPassword: {
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530179 minLength: minLength(this.passwordRequirements.minLength),
Derick Montague602e98a2020-10-21 16:20:00 -0500180 maxLength: maxLength(this.passwordRequirements.maxLength),
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530181 },
182 confirmPassword: {
Derick Montague602e98a2020-10-21 16:20:00 -0500183 sameAsPassword: sameAs('newPassword'),
184 },
185 },
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530186 };
187 },
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530188 methods: {
Sukanya Pandeyfc16f3c2020-06-23 22:54:27 +0530189 saveNewPasswordInputData() {
190 this.$v.form.confirmPassword.$touch();
191 this.$v.form.newPassword.$touch();
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530192 if (this.$v.$invalid) return;
193 let userData = {
194 originalUsername: this.username,
Derick Montague602e98a2020-10-21 16:20:00 -0500195 password: this.form.newPassword,
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530196 };
197
198 this.$store
Sandeepa Singhb4406162021-07-26 15:05:39 +0530199 .dispatch('userManagement/updateUser', userData)
Derick Montague602e98a2020-10-21 16:20:00 -0500200 .then((message) => {
Sukanya Pandey9422e1a2020-07-13 19:13:07 +0530201 (this.form.newPassword = ''), (this.form.confirmPassword = '');
202 this.$v.$reset();
203 this.successToast(message);
204 })
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530205 .catch(({ message }) => this.errorToast(message));
Sukanya Pandeyfc16f3c2020-06-23 22:54:27 +0530206 },
207 saveTimeZonePrefrenceData() {
208 localStorage.setItem('storedUtcDisplay', this.form.isUtcDisplay);
209 this.$store.commit('global/setUtcTime', this.form.isUtcDisplay);
210 this.successToast(
Sandeepa Singh77e64902021-12-29 19:34:16 +0530211 this.$t('pageProfileSettings.toast.successUpdatingTimeZone')
Sukanya Pandeyfc16f3c2020-06-23 22:54:27 +0530212 );
213 },
214 submitForm() {
215 if (this.form.confirmPassword || this.form.newPassword) {
216 this.saveNewPasswordInputData();
217 }
Sukanya Pandey570a74f2020-12-21 16:12:05 +0530218 this.saveTimeZonePrefrenceData();
Derick Montague602e98a2020-10-21 16:20:00 -0500219 },
220 },
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530221};
222</script>