From 33e0c86a1f98afbab677fd4a84beb5604786fdf5 Mon Sep 17 00:00:00 2001 From: Mazdak Gibran <141390141+mazdakgibran@users.noreply.github.com> Date: Mon, 5 Jan 2026 17:42:41 +0500 Subject: [PATCH] change password screen fix change password screen fix for first time login --- .../change-password.component.ts | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/src/app/user-management/change-password/change-password.component.ts b/src/app/user-management/change-password/change-password.component.ts index 423cdd4..5c7d275 100644 --- a/src/app/user-management/change-password/change-password.component.ts +++ b/src/app/user-management/change-password/change-password.component.ts @@ -5,6 +5,7 @@ import { TranslateModule } from '@ngx-translate/core'; import { PasswordHideShowComponent } from '../../shared/components/password-hide-show/password-hide-show.component'; import { HttpURIService } from '../../app.http.uri.service'; import { URIKey } from '../../utils/uri-enums'; +import { StorageService } from '../../shared/services/storage.service'; @Component({ selector: 'app-change-password', @@ -26,7 +27,7 @@ passwordType2: string = 'password'; @ViewChild('psh') passwordHideShow?: PasswordHideShowComponent; @ViewChild('psh1') passwordHideShow1 ?: PasswordHideShowComponent; @ViewChild('psh2') passwordHideShow2 ?: PasswordHideShowComponent; -constructor(private fb: FormBuilder, private httpURIService: HttpURIService){} +constructor(private fb: FormBuilder, private httpURIService: HttpURIService, private storageService: StorageService){} togglePasswordType() { this.passwordType = this.passwordHideShow?.showPassword ? 'password' : 'text'; @@ -45,6 +46,11 @@ constructor(private fb: FormBuilder, private httpURIService: HttpURIService){} } ngOnInit(): void { + this.checkIfFirstTimeChangePasswordOrNot(); + + if (!this.isFirstLogin) { + this.initChangePasswordForm(); + } this.changePasswordForm = this.fb.group({ oldPassword: ['', Validators.required], enterNewPassword: ['',[ Validators.required, Validators.minLength(6)]], @@ -55,7 +61,40 @@ constructor(private fb: FormBuilder, private httpURIService: HttpURIService){} } ) } - get newPasswordError$() { + + checkIfFirstTimeChangePasswordOrNot(): void { + const fromMenu = history.state?.['fromMenu']; + + if (fromMenu) { + this.isFirstLogin = false; + return; + } + + try { + const currentUser: any = JSON.parse( + this.storageService.getItem('user') || '{}' + ); + + this.isFirstLogin = !!currentUser?.user?.isFirstLogin; + } catch (error) { + console.error('Error parsing user data:', error); + this.isFirstLogin = false; + } + } + + initChangePasswordForm(): void { + this.changePasswordForm = this.fb.group( + { + oldPassword: ['', Validators.required], + enterNewPassword: ['', [Validators.required, Validators.minLength(6)]], + confirmPassword: ['', [Validators.required, Validators.minLength(6)]], + }, + { validators: this.passwordMatchValidator } + ); + } + + + get newPasswordError$() { const control = this.changePasswordForm.get('newPassword'); if (!control || !control.touched) return null;