]>
Commit | Line | Data |
---|---|---|
1 | import { firstValueFrom, Subject } from 'rxjs' | |
2 | import { Injectable } from '@angular/core' | |
3 | ||
4 | type ConfirmOptions = { | |
5 | title: string | |
6 | message: string | |
7 | inputLabel?: string | |
8 | expectedInputValue?: string | |
9 | confirmButtonText?: string | |
10 | } | |
11 | ||
12 | @Injectable() | |
13 | export class ConfirmService { | |
14 | showConfirm = new Subject<ConfirmOptions>() | |
15 | confirmResponse = new Subject<boolean>() | |
16 | ||
17 | confirm (message: string, title = '', confirmButtonText?: string) { | |
18 | this.showConfirm.next({ title, message, confirmButtonText }) | |
19 | ||
20 | return firstValueFrom(this.confirmResponse.asObservable()) | |
21 | } | |
22 | ||
23 | confirmWithInput (message: string, inputLabel: string, expectedInputValue: string, title = '', confirmButtonText?: string) { | |
24 | this.showConfirm.next({ title, message, inputLabel, expectedInputValue, confirmButtonText }) | |
25 | ||
26 | return firstValueFrom(this.confirmResponse.asObservable()) | |
27 | } | |
28 | } |