Skip to content

Commit

Permalink
add filter operator for action buttons function
Browse files Browse the repository at this point in the history
  • Loading branch information
DimaShapoval committed Dec 10, 2024
1 parent 93ddb87 commit ffaeb9f
Showing 1 changed file with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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',
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit ffaeb9f

Please sign in to comment.