diff --git a/frontend/src/stores/toastStore.ts b/frontend/src/stores/toastStore.ts new file mode 100644 index 0000000..9c23a1f --- /dev/null +++ b/frontend/src/stores/toastStore.ts @@ -0,0 +1,35 @@ +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; +} + +export const useToastStore = create((set) => ({ + toasts: [], + addToast: (message, type) => { + const id = Math.random().toString(36).substring(2, 9); + set((state) => ({ + toasts: [...state.toasts, { id, message, type }], + })); + // Auto remove after 5 seconds + setTimeout(() => { + set((state) => ({ + toasts: state.toasts.filter((t) => t.id !== id), + })); + }, 5000); + }, + removeToast: (id) => + set((state) => ({ + toasts: state.toasts.filter((t) => t.id !== id), + })), +}));