diff --git a/src/app/domains/pos/components/change-password.component.html b/src/app/domains/pos/components/change-password.component.html index df7808a..a60340b 100644 --- a/src/app/domains/pos/components/change-password.component.html +++ b/src/app/domains/pos/components/change-password.component.html @@ -1 +1,5 @@ - + diff --git a/src/app/domains/pos/components/change-password.component.ts b/src/app/domains/pos/components/change-password.component.ts index 7532d02..c73dccc 100644 --- a/src/app/domains/pos/components/change-password.component.ts +++ b/src/app/domains/pos/components/change-password.component.ts @@ -23,7 +23,7 @@ export class PosChangePasswordComponent extends AbstractDialog { this.submitLoading.set(true); this.service - .changePassword(payload.password) + .changePassword(payload) .pipe(finalize(() => this.submitLoading.set(false))) .subscribe(() => { this.toastService.success({ diff --git a/src/app/domains/pos/services/password.ts b/src/app/domains/pos/services/password.ts index 8a6847e..be6c230 100644 --- a/src/app/domains/pos/services/password.ts +++ b/src/app/domains/pos/services/password.ts @@ -2,13 +2,18 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; +interface IChangePasswordSubmitPayload { + currentPassword: string; + password: string; +} + @Injectable({ providedIn: 'root', }) export class PosChangePasswordService { constructor(private readonly http: HttpClient) {} - changePassword(password: string): Observable { - return this.http.put('/api/v1/pos/update-password', { password }); + changePassword(payload: IChangePasswordSubmitPayload): Observable { + return this.http.put('/api/v1/pos/update-password', payload); } } diff --git a/src/app/shared/components/changePasswordFormDialog/change-password-form-dialog.component.html b/src/app/shared/components/changePasswordFormDialog/change-password-form-dialog.component.html index 0e809b3..674480d 100644 --- a/src/app/shared/components/changePasswordFormDialog/change-password-form-dialog.component.html +++ b/src/app/shared/components/changePasswordFormDialog/change-password-form-dialog.component.html @@ -4,13 +4,26 @@ [modal]="true" [style]="{ width: '500px' }" [closable]="true" - (onHide)="close()" -> + (onHide)="close()">
+ @if (showCurrentPasswordField && form.controls.currentPassword) { + + + + } + [isRenewal]="true" /> diff --git a/src/app/shared/components/changePasswordFormDialog/change-password-form-dialog.component.ts b/src/app/shared/components/changePasswordFormDialog/change-password-form-dialog.component.ts index 27b1619..6047fa3 100644 --- a/src/app/shared/components/changePasswordFormDialog/change-password-form-dialog.component.ts +++ b/src/app/shared/components/changePasswordFormDialog/change-password-form-dialog.component.ts @@ -2,11 +2,14 @@ import { MustMatch, password } from '@/core/validators'; import { AbstractDialog } from '@/shared/abstractClasses/abstract-dialog'; import { SharedDialogComponent } from '@/shared/components/dialog/dialog.component'; import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component'; -import { Component, EventEmitter, Output, input } from '@angular/core'; +import { UikitFieldComponent } from '@/uikit'; +import { Component, EventEmitter, Input, Output, input } from '@angular/core'; import { FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms'; +import { Password } from 'primeng/password'; import { SharedPasswordInputComponent } from '../passwordInput/password-input.component'; export interface IChangePasswordSubmitPayload { + currentPassword: string; password: string; confirmPassword: string; } @@ -19,9 +22,13 @@ export interface IChangePasswordSubmitPayload { SharedDialogComponent, FormFooterActionsComponent, SharedPasswordInputComponent, + UikitFieldComponent, + Password, ], }) export class ChangePasswordFormDialogComponent extends AbstractDialog { + @Input() showCurrentPasswordField = false; + title = input(''); loading = input(false); @@ -29,15 +36,27 @@ export class ChangePasswordFormDialogComponent extends AbstractDialog { private readonly fb = new FormBuilder(); - form = this.fb.group( - { - password: ['', [Validators.required, password()]], - confirmPassword: ['', [Validators.required]], - }, - { - validators: [MustMatch('password', 'confirmPassword')], + initForm() { + const form = this.fb.group( + { + currentPassword: ['', [Validators.required]], + password: ['', [Validators.required, password()]], + confirmPassword: ['', [Validators.required]], + }, + { + validators: [MustMatch('password', 'confirmPassword')], + } + ); + + if (!this.showCurrentPasswordField) { + // @ts-ignore + form.removeControl('currentPassword'); } - ); + + return form; + } + + form = this.initForm(); get dialogHeader() { return this.title() ? `تغییر رمز عبور ${this.title()}` : 'تغییر رمز عبور'; @@ -56,4 +75,8 @@ export class ChangePasswordFormDialogComponent extends AbstractDialog { this.form.reset(); super.close(); } + + ngOnChanges() { + this.form = this.initForm(); + } } diff --git a/src/app/shared/components/passwordInput/password-input.component.html b/src/app/shared/components/passwordInput/password-input.component.html index 963e072..4c1896a 100644 --- a/src/app/shared/components/passwordInput/password-input.component.html +++ b/src/app/shared/components/passwordInput/password-input.component.html @@ -1,4 +1,4 @@ - + - + [invalid]="passwordControl.touched && passwordControl.invalid" /> + {{ hint }} - + + [invalid]="confirmPasswordControl.touched && confirmPasswordControl.invalid" /> diff --git a/src/app/shared/components/passwordInput/password-input.component.ts b/src/app/shared/components/passwordInput/password-input.component.ts index ccfdde8..bc85dd4 100644 --- a/src/app/shared/components/passwordInput/password-input.component.ts +++ b/src/app/shared/components/passwordInput/password-input.component.ts @@ -1,5 +1,5 @@ import { UikitFieldComponent } from '@/uikit'; -import { Component, Input } from '@angular/core'; +import { Component, computed, Input } from '@angular/core'; import { FormControl, ReactiveFormsModule } from '@angular/forms'; import { Password } from 'primeng/password'; @@ -14,4 +14,10 @@ export class SharedPasswordInputComponent { @Input() hint: string = 'رمز باید حداقل ۶ کاراکتر باشد.'; @Input() fluid: boolean = true; @Input() size: 'small' | 'large' = 'large'; + @Input() isRenewal = false; + + passwordFieldLabel = computed(() => (this.isRenewal ? 'رمز عبور جدید' : 'رمز عبور')); + confirmPasswordFieldLabel = computed(() => + this.isRenewal ? 'تکرار رمز عبور جدید' : 'تکرار رمز عبور' + ); } diff --git a/src/app/shared/components/seasonPicker/season-picker.component.html b/src/app/shared/components/seasonPicker/season-picker.component.html index dce6dc7..f5406e8 100644 --- a/src/app/shared/components/seasonPicker/season-picker.component.html +++ b/src/app/shared/components/seasonPicker/season-picker.component.html @@ -1,4 +1,4 @@ -
+