33 lines
820 B
TypeScript
33 lines
820 B
TypeScript
import { Injectable, inject } from '@angular/core';
|
|
import { Confirmation, ConfirmationService } from 'primeng/api';
|
|
|
|
export interface AppConfirmOptions {
|
|
header: string;
|
|
message: string;
|
|
acceptLabel?: string;
|
|
rejectLabel?: string;
|
|
accept?: () => void;
|
|
reject?: () => void;
|
|
}
|
|
|
|
@Injectable({
|
|
providedIn: 'root',
|
|
})
|
|
export class AppConfirmationService {
|
|
private confirmationService = inject(ConfirmationService);
|
|
|
|
ask(options: Confirmation): Promise<boolean> {
|
|
return new Promise((resolve) => {
|
|
this.confirmationService.confirm({
|
|
position: 'bottom',
|
|
acceptLabel: 'تایید',
|
|
rejectLabel: 'لغو',
|
|
...options,
|
|
closeOnEscape: true,
|
|
accept: () => options.accept?.() || resolve(true),
|
|
reject: () => resolve(false),
|
|
});
|
|
});
|
|
}
|
|
}
|