import toast, { Toast, Toaster, useToasterStore } from "react-hot-toast"; import React, { useEffect } from "react"; import { CheckCircleIcon, XCircleIcon } from "@heroicons/react/20/solid"; import Card from "@/components/Card"; interface NotificationOptions { duration?: number; // Add other options as needed } const ToastContent = ({ icon, message, t, }: { icon: React.ReactNode; message: string; t: Toast; }) => (
{icon}

{message}

); const notifications = { success: (message: string, options?: NotificationOptions) => { return toast.custom( t => ( } message={message} t={t} /> ), { duration: 2000, ...options }, ); }, error: (message: string, options?: NotificationOptions) => { return toast.custom( t => ( } message={message} t={t} /> ), { duration: 2000, ...options }, ); }, }; function useMaxToasts(max: number) { const { toasts } = useToasterStore(); useEffect(() => { toasts .filter(t => t.visible) // Only consider visible toasts .filter((_, i) => i >= max) // Is toast index over limit? .forEach(t => toast.dismiss(t.id)); // Dismiss – Use toast.remove(t.id) for no exit animation }, [toasts, max]); } export function Notifications({ max = 10, ...props }: React.ComponentProps & { max?: number; }) { useMaxToasts(max); return ; } // eslint-disable-next-line react-refresh/only-export-components export default Object.assign(Notifications, { success: notifications.success, error: notifications.error, });