import { Router } from "next/router"; 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(router: Router, redirect: string): void { MySwal.fire({ title: '

Sukses

', icon: "success", confirmButtonColor: "#3085d6", confirmButtonText: 'OK', allowOutsideClick: false, }).then((result) => { if (result.isConfirmed) { router.push(redirect); } }); } export function successCallback(title?: string): Promise { return MySwal.fire({ title: `

${title || "Sukses"}

`, icon: "success", confirmButtonColor: "#3085d6", confirmButtonText: 'OK', }).then((result) => result.isConfirmed); } export function successCallbackContent(title?: string): Promise { return MySwal.fire({ title: `

${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): Promise { let timerInterval: NodeJS.Timeout; timerInterval = setInterval(() => {}, 100); return MySwal.fire({ title: `

Selamat 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): Promise { let timerInterval: NodeJS.Timeout; timerInterval = setInterval(() => {}, 100); return MySwal.fire({ title: `

Selamat 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 { return MySwal.fire({ title: `

${text}

`, icon: "warning", confirmButtonColor: "#3085d6", confirmButtonText: 'OK', }).then((result) => { if (redirect && result.isConfirmed) { window.location.href = redirect; } return result.isConfirmed; }); }