import Swal from "sweetalert2"; import withReactContent from "sweetalert2-react-content"; type SweetAlertIcon = "success" | "error" | "warning" | "info" | "question"; const MySwal = withReactContent(Swal); export function loading(): void { let timerInterval: NodeJS.Timeout; MySwal.fire({ title: '
Loading
', allowOutsideClick: false, timerProgressBar: true, didOpen: () => { MySwal.showLoading(); timerInterval = setInterval(() => {}, 100); }, willClose: () => { clearInterval(timerInterval); }, }); } export function error(msg: string): void { MySwal.fire({ title: 'Gagal
', html: `${msg}
`, icon: "error", }); } export function success(redirect: string): void { MySwal.fire({ title: 'Sukses
', icon: "success", confirmButtonColor: "#3085d6", confirmButtonText: 'OK', allowOutsideClick: false, }).then((result) => { if (result.isConfirmed) { window.location.href = redirect; } }); } export function successCallback(title?: string): Promise${title || "Sukses"}
`, icon: "success", confirmButtonColor: "#3085d6", confirmButtonText: 'OK', }).then((result) => result.isConfirmed); } export function successCallbackContent(title?: string): Promise${title || "Konten Telah Berhasil Disimpan"}
`, icon: "success", confirmButtonColor: "#3085d6", confirmButtonText: 'OK', }).then((result) => result.isConfirmed); } export function close(): void { MySwal.close(); } export function welcome(name: string): PromiseSelamat Datang ${name} \nDi Mediahub
`, icon: "success", confirmButtonColor: "#3085d6", confirmButtonText: 'OK', timer: 2000, timerProgressBar: false, willClose: () => { clearInterval(timerInterval); }, }).then((result) => result.isConfirmed); } export function welcomeGuest(name: string): PromiseSelamat Datang ${name} \nDi Mediahub
`, icon: "success", confirmButtonColor: "#3085d6", confirmButtonText: 'OK', timer: 2000, timerProgressBar: false, willClose: () => { clearInterval(timerInterval); }, }).then((result) => result.isConfirmed); } export function registerConfirm(): void { MySwal.fire({ title: 'Selamat Anda Telah Terdaftar
', html: 'Mohon Menunggu Email Konfirmasi Untuk Bisa Melakukan Login
', icon: "success", confirmButtonColor: "#3085d6", confirmButtonText: 'OK', }).then((result) => { if (result.isConfirmed) { window.location.href = "/auth"; } }); } export function warning(text: string, redirect?: string): Promise${text}
`, icon: "warning", confirmButtonColor: "#3085d6", confirmButtonText: 'OK', }).then((result) => { if (redirect && result.isConfirmed) { window.location.href = redirect; } return result.isConfirmed; }); }