import { Component, OnInit, Input, OnDestroy } from '@angular/core'; import { MatDialogRef, MatDialog } from '@angular/material'; import { Subscription } from 'rxjs'; import { HBORModalService } from '../../services/hbor-modal.service'; import { HBORCommunicationService } from '../../services/hbor-communication.service'; import { ModalSubject } from '../../interfaces/modal.subject'; @Component({ selector: 'hbor-confirmation-dialog', templateUrl: './confirmation-dialog.component.html', styleUrls: ['./confirmation-dialog.component.css'] }) export class ConfirmationDialogComponent implements OnInit, OnDestroy { show = false; private subscription: Subscription; selectedOption: boolean; constructor(public dialog: MatDialog, private modalService: HBORModalService, private communicationService: HBORCommunicationService) { } ngOnDestroy() { this.subscription.unsubscribe(); } ngOnInit() { this.subscription = this.modalService.modalState$ .subscribe((state: ModalSubject) => { this.show = state.showConfirmDialog; if (this.show) { this.openDialog(state.title, state.description, state.type); } }); } openDialog(title?: string, description?: string, type?: string) { const dialogRef = this.dialog.open(ConfirmDialogComponent, { disableClose: true }); dialogRef.componentInstance.title = title; dialogRef.componentInstance.description = description; dialogRef.afterClosed().subscribe(result => { this.selectedOption = result; this.communicationService.publishDataDelete({ type: type, state: true, }) }); } } @Component({ selector: 'hbor-confirm-dialog', templateUrl: './confirm-dialog.html', styleUrls: ['./confirmation-dialog.component.css'] }) export class ConfirmDialogComponent { @Input() title: string; @Input() description: string; constructor(public dialogRef: MatDialogRef) { } }