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 NotificationProvider = ({ children }) => {
|
||||||
const [api, contextHolder] = notification.useNotification()
|
const [api, contextHolder] = notification.useNotification()
|
||||||
const location = useLocation()
|
const location = useLocation()
|
||||||
const { authenticated } = useContext(AuthContext)
|
const { authenticated, token } = useContext(AuthContext)
|
||||||
const {
|
const {
|
||||||
showError,
|
showError,
|
||||||
fetchNotificationsApi,
|
fetchNotificationsApi,
|
||||||
@ -118,6 +118,12 @@ const NotificationProvider = ({ children }) => {
|
|||||||
}
|
}
|
||||||
}, [authenticated, notificationCenterVisible, fetchNotifications])
|
}, [authenticated, notificationCenterVisible, fetchNotifications])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (authenticated && token) {
|
||||||
|
fetchNotifications()
|
||||||
|
}
|
||||||
|
}, [authenticated, token, fetchNotifications])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setNotificationCenterVisible(false)
|
setNotificationCenterVisible(false)
|
||||||
}, [location.pathname])
|
}, [location.pathname])
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user