Update Fix
This commit is contained in:
29
resources/js/admin/tailadmin/lib/toast.ts
Normal file
29
resources/js/admin/tailadmin/lib/toast.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
export type ToastVariant = "success" | "error" | "warning" | "info";
|
||||
|
||||
export type ToastPayload = {
|
||||
variant?: ToastVariant;
|
||||
title?: string;
|
||||
message: string;
|
||||
durationMs?: number;
|
||||
};
|
||||
|
||||
export function emitToast(payload: ToastPayload) {
|
||||
if (typeof window === "undefined") return;
|
||||
window.dispatchEvent(new CustomEvent<ToastPayload>("app-toast", { detail: payload }));
|
||||
}
|
||||
|
||||
export function toastError(message: string, title = "Gagal") {
|
||||
emitToast({ variant: "error", title, message });
|
||||
}
|
||||
|
||||
export function toastSuccess(message: string, title = "Berhasil") {
|
||||
emitToast({ variant: "success", title, message });
|
||||
}
|
||||
|
||||
export function toastInfo(message: string, title = "Info") {
|
||||
emitToast({ variant: "info", title, message });
|
||||
}
|
||||
|
||||
export function toastWarning(message: string, title = "Perhatian") {
|
||||
emitToast({ variant: "warning", title, message });
|
||||
}
|
||||
Reference in New Issue
Block a user