From 2f67801700315fa26c9ee539dfb25edb7f91c41c Mon Sep 17 00:00:00 2001 From: ahasani194 Date: Sun, 7 Jun 2026 13:56:36 +0330 Subject: [PATCH] feat: implement change password functionality with dialog and service integration --- .../accounts/components/form.component.html | 8 +-- .../accounts/components/form.component.html | 8 +-- .../components/change-password.component.html | 1 + .../components/change-password.component.ts | 34 ++++++++++ .../layouts/pagesLayout/layout.component.html | 67 ++++++------------- .../layouts/pagesLayout/layout.component.ts | 14 +++- .../modules/configs/views/root.component.html | 1 - .../modules/configs/views/root.component.ts | 2 - src/app/domains/pos/services/password.ts | 14 ++++ 9 files changed, 89 insertions(+), 60 deletions(-) create mode 100644 src/app/domains/pos/components/change-password.component.html create mode 100644 src/app/domains/pos/components/change-password.component.ts create mode 100644 src/app/domains/pos/services/password.ts diff --git a/src/app/domains/consumer/modules/accounts/components/form.component.html b/src/app/domains/consumer/modules/accounts/components/form.component.html index 58fb76b..203ddde 100644 --- a/src/app/domains/consumer/modules/accounts/components/form.component.html +++ b/src/app/domains/consumer/modules/accounts/components/form.component.html @@ -1,16 +1,14 @@ + (onHide)="close()">
+ [confirmPasswordControl]="form.controls.confirmPassword" /> diff --git a/src/app/domains/partner/modules/accounts/components/form.component.html b/src/app/domains/partner/modules/accounts/components/form.component.html index 58fb76b..203ddde 100644 --- a/src/app/domains/partner/modules/accounts/components/form.component.html +++ b/src/app/domains/partner/modules/accounts/components/form.component.html @@ -1,16 +1,14 @@ + (onHide)="close()">
+ [confirmPasswordControl]="form.controls.confirmPassword" /> diff --git a/src/app/domains/pos/components/change-password.component.html b/src/app/domains/pos/components/change-password.component.html new file mode 100644 index 0000000..df7808a --- /dev/null +++ b/src/app/domains/pos/components/change-password.component.html @@ -0,0 +1 @@ + diff --git a/src/app/domains/pos/components/change-password.component.ts b/src/app/domains/pos/components/change-password.component.ts new file mode 100644 index 0000000..cf1ba49 --- /dev/null +++ b/src/app/domains/pos/components/change-password.component.ts @@ -0,0 +1,34 @@ +import { ToastService } from '@/core/services/toast.service'; +import { AbstractDialog } from '@/shared/abstractClasses/abstract-dialog'; +import { ChangePasswordFormDialogComponent } from '@/shared/components'; +import { Component, inject, signal } from '@angular/core'; +import { finalize } from 'rxjs'; +import { IChangePasswordSubmitPayload } from '../modules/configs/components/changePassword/model'; +import { PosChangePasswordService } from '../services/password'; + +@Component({ + selector: 'pos-change-password', + templateUrl: 'change-password.component.html', + imports: [ChangePasswordFormDialogComponent], +}) +export class PosChangePasswordComponent extends AbstractDialog { + private readonly service = inject(PosChangePasswordService); + private readonly toastService = inject(ToastService); + + submitLoading = signal(false); + + submit(payload: IChangePasswordSubmitPayload) { + this.submitLoading.set(true); + + this.service + .changePassword(payload.password) + .pipe(finalize(() => this.submitLoading.set(false))) + .subscribe(() => { + this.toastService.success({ + text: 'تغییر گذرواژه با موفقیت انجام شد.', + }); + this.submitLoading.set(false); + this.close(); + }); + } +} diff --git a/src/app/domains/pos/layouts/pagesLayout/layout.component.html b/src/app/domains/pos/layouts/pagesLayout/layout.component.html index d890b43..86aa2a0 100644 --- a/src/app/domains/pos/layouts/pagesLayout/layout.component.html +++ b/src/app/domains/pos/layouts/pagesLayout/layout.component.html @@ -25,52 +25,27 @@ @if (loading()) { -} @else { - - - @if (error()) { - @switch (error()?.status) { - @case (412) { - - } - @default { -
- -
- - عدم دسترسی -

متاسفانه امکان دسترسی برای کاربر شما فراهم نیست

- -
-
-
- } +} @else if (error()) { + @switch (error()?.status) { + @case (412) { + + } + @default { +
+ +
+ + عدم دسترسی +

متاسفانه امکان دسترسی برای کاربر شما فراهم نیست

+ +
+
+
} - } @else { - - } - +} @else { + + + } + diff --git a/src/app/domains/pos/layouts/pagesLayout/layout.component.ts b/src/app/domains/pos/layouts/pagesLayout/layout.component.ts index d4859ab..7352374 100644 --- a/src/app/domains/pos/layouts/pagesLayout/layout.component.ts +++ b/src/app/domains/pos/layouts/pagesLayout/layout.component.ts @@ -11,6 +11,7 @@ import { Menu } from 'primeng/menu'; import { finalize } from 'rxjs'; import images from 'src/assets/images'; import config from 'src/config'; +import { PosChangePasswordComponent } from '../../components/change-password.component'; import { PosInfoStore, PosProfileStore } from '../../store'; import { DeviceInfoStore } from '../../store/device.store'; import { PosMainMenuSidebarComponent } from '../mainMenuSidebar/main-menu-sidebar.component'; @@ -30,6 +31,7 @@ import { PosChooseCardsComponent } from './choose-pos.component'; CommonModule, RouterLinkWithHref, RouterOutlet, + PosChangePasswordComponent, ], }) export class PosPagesLayoutComponent { @@ -49,6 +51,7 @@ export class PosPagesLayoutComponent { private readonly layoutService = inject(LayoutService); mainMenuVisible = signal(false); + changePasswordVisible = signal(false); readonly posProfileLoading = computed(() => this.posProfileStore.loading()); readonly posProfile = computed(() => this.posProfileStore.entity()); @@ -67,12 +70,21 @@ export class PosPagesLayoutComponent { this.authService.logout(); }; + showChangePasswordDialog = () => { + this.changePasswordVisible.set(true); + }; + profileMenuItems: MenuItem[] = [ { label: 'راهنمای سامانه', icon: 'pi pi-question-circle', disabled: true, }, + { + label: 'تغییر گذرواژه', + icon: 'pi pi-key', + command: this.showChangePasswordDialog, + }, { label: 'خروج', icon: 'pi pi-sign-out', @@ -97,7 +109,7 @@ export class PosPagesLayoutComponent { .pipe( finalize(() => { this.layoutService.changeFullPageLoading(false); - }), + }) ) .subscribe(); }, diff --git a/src/app/domains/pos/modules/configs/views/root.component.html b/src/app/domains/pos/modules/configs/views/root.component.html index 6ad7c72..7430eca 100644 --- a/src/app/domains/pos/modules/configs/views/root.component.html +++ b/src/app/domains/pos/modules/configs/views/root.component.html @@ -10,7 +10,6 @@ - هریک از موارد زیر را که می‌خواهید در چاپ صورت‌حساب‌ نمایش داده‌ شوند را انتخاب کنید diff --git a/src/app/domains/pos/modules/configs/views/root.component.ts b/src/app/domains/pos/modules/configs/views/root.component.ts index 470260b..2d9f79f 100644 --- a/src/app/domains/pos/modules/configs/views/root.component.ts +++ b/src/app/domains/pos/modules/configs/views/root.component.ts @@ -3,7 +3,6 @@ import { AppCardComponent } from '@/shared/components'; import { Component, computed, inject } from '@angular/core'; import { Router } from '@angular/router'; import { Message } from 'primeng/message'; -import { PosChangePasswordFormDialogComponent } from '../components/changePassword/form.component'; import { PosConfigGoldPriceFormComponent } from '../components/goldPrice/form.component'; import { PosConfigPrintFormComponent } from '../components/print/form.component'; import { PosConfigRapidInvoiceFormComponent } from '../components/rapidInvoice/form.component'; @@ -19,7 +18,6 @@ import { PosConfigSendToFiscalActivationFormComponent } from '../components/send PosConfigGoldPriceFormComponent, PosConfigRapidInvoiceFormComponent, PosConfigSendToFiscalActivationFormComponent, - PosChangePasswordFormDialogComponent, ], }) export class PosConfigPageComponent { diff --git a/src/app/domains/pos/services/password.ts b/src/app/domains/pos/services/password.ts new file mode 100644 index 0000000..8a6847e --- /dev/null +++ b/src/app/domains/pos/services/password.ts @@ -0,0 +1,14 @@ +import { HttpClient } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { Observable } from 'rxjs'; + +@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 }); + } +}