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:
@@ -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("/")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user