"use client"; import { useEffect } from "react"; export type ToastMessage = { type: "success" | "error"; message: string; }; /** * Simple top-centered toast. Auto-dismisses after `durationMs` (default * 3s). Owners hold the ToastMessage state; this component reads it and * calls onDismiss when the timer fires (or when the toast object * changes — useEffect's cleanup clears any in-flight timer). */ export default function Toast({ toast, onDismiss, durationMs = 3000, }: { toast: ToastMessage | null; onDismiss: () => void; durationMs?: number; }) { useEffect(() => { if (!toast) return; const id = setTimeout(onDismiss, durationMs); return () => clearTimeout(id); }, [toast, onDismiss, durationMs]); if (!toast) return null; const styles = toast.type === "success" ? "bg-emerald-50 text-emerald-800 ring-emerald-200" : "bg-red-50 text-red-800 ring-red-200"; return (
{toast.message}
); }