1
|
import Swal, { SweetAlertIcon, SweetAlertPosition } from 'sweetalert2';
|
2
|
import withReactContent from 'sweetalert2-react-content';
|
3
|
import { AxiosResponse } from 'axios';
|
4
|
|
5
|
const MySwal = withReactContent(Swal);
|
6
|
|
7
|
export function ShowToast(
|
8
|
text: string,
|
9
|
icon: SweetAlertIcon = 'success',
|
10
|
timer = 3000,
|
11
|
position: SweetAlertPosition = 'top-right'
|
12
|
) {
|
13
|
const Toast = Swal.mixin({
|
14
|
toast: true,
|
15
|
position: position,
|
16
|
showConfirmButton: false,
|
17
|
timer: timer,
|
18
|
timerProgressBar: true,
|
19
|
didOpen: (toast) => {
|
20
|
toast.addEventListener('mouseenter', Swal.stopTimer);
|
21
|
toast.addEventListener('mouseleave', Swal.resumeTimer);
|
22
|
},
|
23
|
});
|
24
|
|
25
|
Toast.fire({
|
26
|
icon: icon,
|
27
|
title: text,
|
28
|
});
|
29
|
}
|
30
|
|
31
|
export function ShowConfirmDelete(deleteAction: () => void, deleteSubjectLabel: string) {
|
32
|
Swal.fire({
|
33
|
icon: 'question',
|
34
|
title: 'Opravdu si přejete smazat ' + deleteSubjectLabel + '?',
|
35
|
showCancelButton: true,
|
36
|
confirmButtonText: 'Smazat',
|
37
|
confirmButtonColor: '#d33',
|
38
|
cancelButtonText: 'Zrušit',
|
39
|
cancelButtonColor: '#c0c0c0',
|
40
|
}).then((result) => {
|
41
|
if (result.isConfirmed) {
|
42
|
deleteAction();
|
43
|
}
|
44
|
});
|
45
|
}
|