pmtool / src /components /toast-utils.ts
devarshia5's picture
Upload 487 files
d97b8f9 verified
Raw
History Blame Contribute Delete
3.16 kB
import { toast } from "@/hooks/use-toast";
import { toast as sonnerToast } from "sonner";
type ToastOptions = {
title: string;
description?: string;
duration?: number;
};
// Base styles for all toasts
const baseToastStyles = "p-4 rounded-lg border shadow-lg font-medium";
/**
* Enhanced toast utilities for consistent toast styling across the application
*/
export const toastUtils = {
/**
* Show a success toast message
*/
success: (options: ToastOptions) => {
return toast({
title: options.title,
description: options.description,
duration: options.duration || 5000,
className: `${baseToastStyles} bg-green-50 border-green-200 text-green-800 dark:bg-green-950 dark:border-green-800 dark:text-green-200`,
});
},
/**
* Show an error toast message
*/
error: (options: ToastOptions) => {
return toast({
title: options.title,
description: options.description,
duration: options.duration || 6000, // Longer duration for errors
className: `${baseToastStyles} bg-red-50 border-red-200 text-red-800 dark:bg-red-950 dark:border-red-800 dark:text-red-200`,
variant: "destructive",
});
},
/**
* Show a warning toast message
*/
warning: (options: ToastOptions) => {
return toast({
title: options.title,
description: options.description,
duration: options.duration || 5000,
className: `${baseToastStyles} bg-yellow-50 border-yellow-200 text-yellow-800 dark:bg-yellow-950 dark:border-yellow-800 dark:text-yellow-200`,
});
},
/**
* Show an info toast message
*/
info: (options: ToastOptions) => {
return toast({
title: options.title,
description: options.description,
duration: options.duration || 4000,
className: `${baseToastStyles} bg-blue-50 border-blue-200 text-blue-800 dark:bg-blue-950 dark:border-blue-800 dark:text-blue-200`,
});
},
/**
* Show a default toast message
*/
default: (options: ToastOptions) => {
return toast({
title: options.title,
description: options.description,
duration: options.duration || 5000,
className: baseToastStyles,
});
},
};
/**
* Simplified toast utility function that works with Sonner toast
* @param type The type of toast: success, error, warning, info
* @param title The toast title
* @param message Optional toast message
*/
export const showToast = (
type: "success" | "error" | "warning" | "info",
title: string,
message?: string
) => {
switch (type) {
case "success":
sonnerToast.success(title, {
description: message,
});
break;
case "error":
sonnerToast.error(title, {
description: message,
});
break;
case "warning":
sonnerToast.warning(title, {
description: message,
});
break;
case "info":
sonnerToast.info(title, {
description: message,
});
break;
default:
sonnerToast(title, {
description: message,
});
}
};