Projekt

Obecné

Profil

Stáhnout (1.25 KB) Statistiky
| Větev: | Tag: | Revize:
1 8c45ccb0 hrubyjar
import Swal, { SweetAlertIcon, SweetAlertPosition } from 'sweetalert2';
2
import withReactContent from 'sweetalert2-react-content';
3 43d49a98 Jaroslav Hrubý
import { AxiosResponse } from 'axios';
4 8c45ccb0 hrubyjar
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 43d49a98 Jaroslav Hrubý
31
export function ShowConfirmDelete(deleteAction: () => void, deleteSubjectLabel: string) {
32
    Swal.fire({
33 d7167305 Jaroslav Hrubý
        icon: 'question',
34 43d49a98 Jaroslav Hrubý
        title: 'Opravdu si přejete smazat ' + deleteSubjectLabel + '?',
35
        showCancelButton: true,
36
        confirmButtonText: 'Smazat',
37 d7167305 Jaroslav Hrubý
        confirmButtonColor: '#d33',
38
        cancelButtonText: 'Zrušit',
39
        cancelButtonColor: '#c0c0c0',
40 43d49a98 Jaroslav Hrubý
    }).then((result) => {
41
        if (result.isConfirmed) {
42
            deleteAction();
43
        }
44
    });
45
}