Fix state sync for target exam tag in header
This commit is contained in:
@@ -67,6 +67,13 @@ export function useActiveUser() {
|
|||||||
}
|
}
|
||||||
}, [fetchUserProfile]);
|
}, [fetchUserProfile]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (typeof window === "undefined") return;
|
||||||
|
const handleUpdate = () => fetchUserProfile(userId);
|
||||||
|
window.addEventListener('pragativeer-user-updated', handleUpdate);
|
||||||
|
return () => window.removeEventListener('pragativeer-user-updated', handleUpdate);
|
||||||
|
}, [userId, fetchUserProfile]);
|
||||||
|
|
||||||
const switchUser = useCallback((newId: string) => {
|
const switchUser = useCallback((newId: string) => {
|
||||||
if (typeof window !== "undefined") {
|
if (typeof window !== "undefined") {
|
||||||
localStorage.setItem("activeUserId", newId);
|
localStorage.setItem("activeUserId", newId);
|
||||||
@@ -116,6 +123,9 @@ export function useActiveUser() {
|
|||||||
error,
|
error,
|
||||||
switchUser,
|
switchUser,
|
||||||
hasAccessTo,
|
hasAccessTo,
|
||||||
refreshUser: () => fetchUserProfile(userId)
|
refreshUser: async () => {
|
||||||
|
await fetchUserProfile(userId);
|
||||||
|
window.dispatchEvent(new CustomEvent('pragativeer-user-updated'));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user