aboutsummaryrefslogblamecommitdiffhomepage
path: root/client/src/app/core/confirm/confirm.service.ts
blob: 8419f622b257e0afd395a24f780f554e3449e088 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
                                      
                                          
                              
 







                             

                             
                                             
                                          
 

                                                                     
 
                                                                        

   

                                                                                                                              
 
                                                                        

   
import { first } from 'rxjs/operators'
import { Injectable } from '@angular/core'
import { Subject } from 'rxjs'

type ConfirmOptions = {
  title: string
  message: string
  inputLabel?: string
  expectedInputValue?: string
  confirmButtonText?: string
}

@Injectable()
export class ConfirmService {
  showConfirm = new Subject<ConfirmOptions>()
  confirmResponse = new Subject<boolean>()

  confirm (message: string, title = '', confirmButtonText?: string) {
    this.showConfirm.next({ title, message, confirmButtonText })

    return this.confirmResponse.asObservable().pipe(first()).toPromise()
  }

  confirmWithInput (message: string, inputLabel: string, expectedInputValue: string, title = '', confirmButtonText?: string) {
    this.showConfirm.next({ title, message, inputLabel, expectedInputValue, confirmButtonText })

    return this.confirmResponse.asObservable().pipe(first()).toPromise()
  }
}