From ffaeb9f9683d60d8c6ea757d6d7e2d007e395637 Mon Sep 17 00:00:00 2001 From: DimaShapoval Date: Tue, 10 Dec 2024 18:18:53 +0200 Subject: [PATCH] add filter operator for action buttons function --- .../workshop-details.component.ts | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/app/shell/details/workshop-details/workshop-details.component.ts b/src/app/shell/details/workshop-details/workshop-details.component.ts index fd348e5c4..ed02183b7 100644 --- a/src/app/shell/details/workshop-details/workshop-details.component.ts +++ b/src/app/shell/details/workshop-details/workshop-details.component.ts @@ -3,7 +3,7 @@ import { MatLegacyTabChangeEvent as MatTabChangeEvent, MatLegacyTabGroup as MatT import { ActivatedRoute, Params, Router } from '@angular/router'; import { Store } from '@ngxs/store'; import { Subject } from 'rxjs'; -import { debounceTime, takeUntil } from 'rxjs/operators'; +import { debounceTime, filter, switchMap, takeUntil } from 'rxjs/operators'; import { Constants, PaginationConstants } from 'shared/constants/constants'; import { CategoryIcons } from 'shared/enum/category-icons'; @@ -22,6 +22,7 @@ import { GetProviderById } from 'shared/store/shared-user.actions'; import { InfoMenuType } from 'shared/enum/info-menu-type'; import { MatDialog } from '@angular/material/dialog'; import { ConfirmationModalWindowComponent } from 'shared/components/confirmation-modal-window/confirmation-modal-window.component'; +import { ModalConfirmationType } from 'shared/enum/modal-confirmation'; @Component({ selector: 'app-workshop-details', @@ -52,6 +53,7 @@ export class WorkshopDetailsComponent implements OnInit, OnDestroy { public readonly FormOfLearningEnum = FormOfLearningEnum; public readonly Role = Role; public readonly InfoMenuType = InfoMenuType; + public readonly modalType = ModalConfirmationType; public workshopStatusOpen: boolean; public selectedIndex: number; @@ -100,18 +102,24 @@ export class WorkshopDetailsComponent implements OnInit, OnDestroy { this.store.dispatch(new ResetAchievements()); } - public onActionButtonClick(modalType: string): void { + public onActionButtonClick(modalType: ModalConfirmationType): void { const dialogRef = this.dialog.open(ConfirmationModalWindowComponent, { width: Constants.MODAL_SMALL, data: { type: modalType } }); - dialogRef.afterClosed().subscribe((res) => { - if (res && modalType === 'publishWorkshop') { - return this.store.dispatch(new PublishWorkshop(this.workshop.providerId)); - } - }); + dialogRef + .afterClosed() + .pipe( + filter((res) => !!res), + switchMap(() => { + if (modalType === this.modalType.publishWorkshop) { + return this.store.dispatch(new PublishWorkshop(this.workshop.providerId)); + } + }) + ) + .subscribe(); } private getWorkshopData(): void {