feat: add toast notification system with success, error, and info variants

This commit is contained in:
Your Name
2026-02-15 20:30:17 +02:00
parent 61a5f11f25
commit 6341897487
5 changed files with 76 additions and 1 deletions

33
src/stores/toast-store.ts Normal file
View File

@@ -0,0 +1,33 @@
import { create } from "zustand";
export type ToastType = "success" | "error" | "info";
interface Toast {
id: string;
message: string;
type: ToastType;
}
interface ToastState {
toasts: Toast[];
addToast: (message: string, type?: ToastType) => void;
removeToast: (id: string) => void;
}
let nextId = 0;
export const useToastStore = create<ToastState>((set) => ({
toasts: [],
addToast: (message, type = "info") => {
const id = String(++nextId);
set((s) => ({ toasts: [...s.toasts, { id, message, type }] }));
setTimeout(() => {
set((s) => ({ toasts: s.toasts.filter((t) => t.id !== id) }));
}, 3000);
},
removeToast: (id) => {
set((s) => ({ toasts: s.toasts.filter((t) => t.id !== id) }));
},
}));