feat(notifications): add notification system and wire order/dispute events
This commit is contained in:
@@ -1,14 +1,47 @@
|
||||
import { create } from "zustand"
|
||||
import { generateId } from "@/lib/id"
|
||||
import { mockNotifications } from "@/lib/mock"
|
||||
import type { Notification } from "@/lib/types"
|
||||
|
||||
interface CreateNotificationInput {
|
||||
type: Notification["type"]
|
||||
title: string
|
||||
content: string
|
||||
link?: string
|
||||
}
|
||||
|
||||
interface NotificationState {
|
||||
notifications: Notification[]
|
||||
addNotification: (input: CreateNotificationInput) => Notification
|
||||
markAsRead: (notificationId: string) => void
|
||||
markAllAsRead: () => void
|
||||
}
|
||||
|
||||
export const useNotificationStore = create<NotificationState>((set) => ({
|
||||
notifications: mockNotifications,
|
||||
addNotification: (input) => {
|
||||
const notification: Notification = {
|
||||
id: generateId("notif"),
|
||||
type: input.type,
|
||||
title: input.title,
|
||||
content: input.content,
|
||||
link: input.link,
|
||||
read: false,
|
||||
createdAt: new Date().toISOString(),
|
||||
}
|
||||
|
||||
set((state) => ({
|
||||
notifications: [notification, ...state.notifications],
|
||||
}))
|
||||
|
||||
return notification
|
||||
},
|
||||
markAsRead: (notificationId) =>
|
||||
set((state) => ({
|
||||
notifications: state.notifications.map((notification) =>
|
||||
notification.id === notificationId ? { ...notification, read: true } : notification,
|
||||
),
|
||||
})),
|
||||
markAllAsRead: () =>
|
||||
set((state) => ({
|
||||
notifications: state.notifications.map((notification) => ({ ...notification, read: true })),
|
||||
|
||||
Reference in New Issue
Block a user