31 lines
779 B
TypeScript
31 lines
779 B
TypeScript
import { useNotificationStore } from "@/lib/stores/notification-store";
|
|
import type { NotificationType } from "@/lib/stores/notification-store";
|
|
|
|
type ToastVariant = "default" | "destructive";
|
|
|
|
interface ToastProps {
|
|
title?: string;
|
|
description: string;
|
|
variant?: ToastVariant;
|
|
duration?: number;
|
|
}
|
|
|
|
function variantToType(variant: ToastVariant): NotificationType {
|
|
return variant === "destructive" ? "error" : "success";
|
|
}
|
|
|
|
export function useToast() {
|
|
const addNotification = useNotificationStore((s) => s.addNotification);
|
|
|
|
const toast = ({ title, description, variant = "default", duration }: ToastProps) => {
|
|
addNotification({
|
|
type: variantToType(variant),
|
|
message: description,
|
|
title,
|
|
duration,
|
|
});
|
|
};
|
|
|
|
return { toast };
|
|
}
|