Fix state sync for target exam tag in header

This commit is contained in:
2026-07-08 15:09:19 +05:30
parent db22448086
commit 8f9bef9744

View File

@@ -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'));
}
};
}