+import { firstValueFrom, Subject } from 'rxjs'
import { Injectable } from '@angular/core'
-import { Subject } from 'rxjs/Subject'
-import 'rxjs/add/operator/first'
-import 'rxjs/add/operator/toPromise'
+
+type ConfirmOptions = {
+ title: string
+ message: string
+ inputLabel?: string
+ expectedInputValue?: string
+ confirmButtonText?: string
+}
@Injectable()
export class ConfirmService {
- showConfirm = new Subject<{ title: string, message: string, inputLabel?: string, expectedInputValue?: string }>()
+ showConfirm = new Subject<ConfirmOptions>()
confirmResponse = new Subject<boolean>()
- confirm (message: string, title = '') {
- this.showConfirm.next({ title, message })
+ confirm (message: string, title = '', confirmButtonText?: string) {
+ this.showConfirm.next({ title, message, confirmButtonText })
- return this.confirmResponse.asObservable().first().toPromise()
+ return firstValueFrom(this.confirmResponse.asObservable())
}
- confirmWithInput (message: string, inputLabel: string, expectedInputValue: string, title = '') {
- this.showConfirm.next({ title, message, inputLabel, expectedInputValue })
+ confirmWithInput (message: string, inputLabel: string, expectedInputValue: string, title = '', confirmButtonText?: string) {
+ this.showConfirm.next({ title, message, inputLabel, expectedInputValue, confirmButtonText })
- return this.confirmResponse.asObservable().first().toPromise()
+ return firstValueFrom(this.confirmResponse.asObservable())
}
}