64 lines
1.7 KiB
TypeScript
64 lines
1.7 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
import { MatSnackBar } from '@angular/material/snack-bar';
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class NotificationService {
|
|
|
|
constructor(private snackBar: MatSnackBar) {}
|
|
|
|
showSuccess(message: string, duration: number = 3000): void {
|
|
this.snackBar.open(message, 'Close', {
|
|
duration,
|
|
panelClass: ['success-snackbar'],
|
|
horizontalPosition: 'center',
|
|
verticalPosition: 'bottom'
|
|
});
|
|
}
|
|
|
|
showError(message: string, duration: number = 5000): void {
|
|
this.snackBar.open(message, 'Close', {
|
|
duration,
|
|
panelClass: ['error-snackbar'],
|
|
horizontalPosition: 'center',
|
|
verticalPosition: 'bottom'
|
|
});
|
|
}
|
|
|
|
showInfo(message: string, duration: number = 3000): void {
|
|
this.snackBar.open(message, 'Close', {
|
|
duration,
|
|
panelClass: ['info-snackbar'],
|
|
horizontalPosition: 'center',
|
|
verticalPosition: 'bottom'
|
|
});
|
|
}
|
|
|
|
showWarning(message: string, duration: number = 4000): void {
|
|
this.snackBar.open(message, 'Close', {
|
|
duration,
|
|
panelClass: ['warning-snackbar'],
|
|
horizontalPosition: 'center',
|
|
verticalPosition: 'bottom'
|
|
});
|
|
}
|
|
|
|
showConfirmation(message: string, action: string = 'Confirm'): Promise<boolean> {
|
|
const snackBarRef = this.snackBar.open(message, action, {
|
|
duration: 10000,
|
|
panelClass: ['confirmation-snackbar'],
|
|
horizontalPosition: 'center',
|
|
verticalPosition: 'bottom'
|
|
});
|
|
|
|
return new Promise((resolve) => {
|
|
snackBarRef.onAction().subscribe(() => resolve(true));
|
|
snackBarRef.afterDismissed().subscribe((info) => {
|
|
if (!info.dismissedByAction) {
|
|
resolve(false);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
} |