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
+28
View File
@@ -1,5 +1,33 @@
import { allow, deny } from "@/lib/policy/assert"
import type { Notification } from "@/lib/types"
import { useAuthStore } from "@/store/auth"
import { useNotificationStore } from "@/store/notifications"
export function listNotifications() {
return useNotificationStore.getState().notifications
}
function isNotificationEnabled(type: Notification["type"]) {
const prefs = useAuthStore.getState().notificationPrefs
if (type === "order") return prefs.order
if (type === "community") return prefs.community
return prefs.system
}
export function addNotification(input: {
type: Notification["type"]
title: string
content: string
link?: string
}) {
if (!isNotificationEnabled(input.type)) {
return deny("IDEMPOTENT_NOOP", "该类通知已关闭")
}
useNotificationStore.getState().addNotification(input)
return allow()
}
export function markNotificationAsRead(notificationId: string) {
useNotificationStore.getState().markAsRead(notificationId)
}