All files / src/app/core/services confirm-dialog.service.ts

81.25% Statements 13/16
25% Branches 2/8
66.66% Functions 4/6
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 2710x 10x 10x         10x   4x     3x           3x 3x 1x 1x          
import { Injectable } from '@angular/core';
import { MatDialog, MatDialogRef } from '@angular/material/dialog';
import { ConfirmDialogComponent } from '@features/dialogs/confirm-dialog/confirm-dialog.component';
 
@Injectable({
  providedIn: 'root'
})
export class ConfirmDialogService {
 
  constructor(private dialog: MatDialog) {}
 
  openConfirmDialog(message: String, confirm: () => void): void {
    const dialogRef: MatDialogRef<ConfirmDialogComponent> =  this.dialog.open(ConfirmDialogComponent, {
      width: '80vw',
      maxWidth: '1000px',
      data: { message, confirm }
    });
 
    dialogRef.afterClosed().subscribe((result) => {
      if(result) {
        if(confirm) {
          confirm();
        }
      }
    })
  }
}