import get from "lodash.get"; import { AlertTriangle, Check, Loader2 } from "lucide-react"; import { toast } from "sonner"; export const actionToast = async (data: { task: () => Promise; before?: () => any; success?: () => any; after?: () => any; msg_succes?: string; msg_error?: string; msg_load?: string; }) => { const { task, before, after, success, msg_succes, msg_error, msg_load } = data; try { if (typeof before === "function") before(); toast.info( <> {msg_load ? msg_load : " Load..."} ); if (typeof task === "function") await task(); setTimeout(() => { toast.success(
{ toast.dismiss(); }} >
{msg_succes ? msg_succes : "Success"}
); if (typeof after === "function") after(); if (typeof success === "function") success(); }, 1000); } catch (ex: any) { toast.error(
{msg_error ? msg_error : "Failed"}{" "} {get(ex, "response.data.meta.message") || ex.message}.
, { dismissible: true, className: css` background: #ffecec; border: 2px solid red; `, } ); } };