refactor(notifications): fetch from backend API instead of local generation

Rewrite store/notifications.ts to fetch via listNotifications
API and remove local generateId-based notification creation.
The store now acts as a simple cache with fetch/invalidate methods.
Header unread count reads from this API-backed cache.
This commit is contained in:
zetaloop
2026-05-01 04:21:03 +08:00
parent d76866ac3b
commit cd469d3d54
4 changed files with 84 additions and 74 deletions
+8 -1
View File
@@ -34,7 +34,7 @@ import {
} from "lucide-react"
import Link from "next/link"
import { usePathname, useRouter } from "next/navigation"
import { useState } from "react"
import { useEffect, useState } from "react"
import { canAccessDashboard } from "@/components/role-guard"
@@ -59,6 +59,12 @@ export function Header() {
} = useAuthStore()
const canOpenDashboard = currentRole === "player" || currentRole === "owner"
const { shop: ownerShop } = useMyShop(isAuthenticated && currentRole === "owner")
const fetchNotifications = useNotificationStore((state) => state.fetchNotifications)
useEffect(() => {
if (!isAuthenticated) return
void fetchNotifications()
}, [fetchNotifications, isAuthenticated])
const navLinks =
currentRole === "consumer"
@@ -110,6 +116,7 @@ export function Header() {
notifyInfo(toApiError(error).msg)
} finally {
clearAuth()
useNotificationStore.getState().invalidate()
setMobileOpen(false)
router.push("/")
}