forked from alan2207/bulletproof-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotifications.ts
More file actions
27 lines (24 loc) · 781 Bytes
/
notifications.ts
File metadata and controls
27 lines (24 loc) · 781 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { nanoid } from 'nanoid';
import create from 'zustand';
export type Notification = {
id: string;
type: 'info' | 'warning' | 'success' | 'error';
title: string;
message?: string;
};
type NotificationsStore = {
notifications: Notification[];
addNotification: (notification: Omit<Notification, 'id'>) => void;
dismissNotification: (id: string) => void;
};
export const useNotificationStore = create<NotificationsStore>((set) => ({
notifications: [],
addNotification: (notification) =>
set((state) => ({
notifications: [...state.notifications, { id: nanoid(), ...notification }],
})),
dismissNotification: (id) =>
set((state) => ({
notifications: state.notifications.filter((notification) => notification.id !== id),
})),
}));