62 lines
1.2 KiB
TypeScript
62 lines
1.2 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
import Swal, { SweetAlertIcon, SweetAlertOptions } from 'sweetalert2';
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class NotificationService {
|
|
|
|
notify(message: string, icon: SweetAlertIcon = 'success', timer = 1500): void {
|
|
Swal.fire({
|
|
position: 'top-end',
|
|
icon: icon,
|
|
title: message,
|
|
showConfirmButton: false,
|
|
timer: timer
|
|
});
|
|
}
|
|
|
|
|
|
success(message: string, timer = 1500): void {
|
|
this.notify(message, 'success', timer);
|
|
}
|
|
|
|
error(
|
|
message: string,
|
|
title = 'Oops...',
|
|
footer: string | null = null
|
|
): void {
|
|
Swal.fire({
|
|
position: 'center',
|
|
icon: 'error',
|
|
title: title,
|
|
text: message,
|
|
...(footer ? { footer: footer } : {}),
|
|
showConfirmButton: true,
|
|
confirmButtonText: 'OK',
|
|
customClass: {
|
|
popup: 'DangerSweetalert'
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
warning(message: string, timer = 2500): void {
|
|
this.notify(message, 'warning', timer);
|
|
}
|
|
|
|
|
|
info(message: string, timer = 2000): void {
|
|
this.notify(message, 'info', timer);
|
|
}
|
|
|
|
custom(options: SweetAlertOptions): void {
|
|
Swal.fire({
|
|
position: 'top-end',
|
|
showConfirmButton: false,
|
|
timer: 1500,
|
|
...options
|
|
});
|
|
}
|
|
}
|