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