feat(notifications): add notification system and wire order/dispute events
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user