Enhance NotificationProvider to fetch notifications based on authentication and token presence, improving notification handling logic.
This commit is contained in:
parent
128cf603e7
commit
6d839ebe9c
@ -19,7 +19,7 @@ const NotificationContext = createContext()
|
||||
const NotificationProvider = ({ children }) => {
|
||||
const [api, contextHolder] = notification.useNotification()
|
||||
const location = useLocation()
|
||||
const { authenticated } = useContext(AuthContext)
|
||||
const { authenticated, token } = useContext(AuthContext)
|
||||
const {
|
||||
showError,
|
||||
fetchNotificationsApi,
|
||||
@ -118,6 +118,12 @@ const NotificationProvider = ({ children }) => {
|
||||
}
|
||||
}, [authenticated, notificationCenterVisible, fetchNotifications])
|
||||
|
||||
useEffect(() => {
|
||||
if (authenticated && token) {
|
||||
fetchNotifications()
|
||||
}
|
||||
}, [authenticated, token, fetchNotifications])
|
||||
|
||||
useEffect(() => {
|
||||
setNotificationCenterVisible(false)
|
||||
}, [location.pathname])
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user