feat(notifications): add notification system and wire order/dispute events

This commit is contained in:
zetaloop
2026-02-23 11:05:04 +08:00
parent 2222dccbb7
commit c986539954
7 changed files with 214 additions and 17 deletions
+33
View File
@@ -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 })),