MCPcopy Create free account
hub / github.com/Datakitpage/Datakit / UserMenu

Function UserMenu

frontend/src/components/auth/UserMenu.tsx:27–464  ·  view source on GitHub ↗
({
  variant = 'header',
  className = '',
})

Source from the content-addressed store, hash-verified

25}
26
27const UserMenu: React.FC<UserMenuProps> = ({
28 variant = 'header',
29 className = '',
30}) => {
31 const { t } = useTranslation();
32 const { user, isAuthenticated, logout, isLoading } = useAuth();
33 const { setActiveProvider } = useAIStore();
34 const { showSuccess } = useNotifications();
35
36 const [showAuthModal, setShowAuthModal] = useState(false);
37 const [authModalMode, setAuthModalMode] = useState<'login' | 'signup'>(
38 'login'
39 );
40 const [showDropdown, setShowDropdown] = useState(false);
41 const dropdownRef = useRef<HTMLDivElement>(null);
42
43 // Close dropdown when clicking outside
44 useEffect(() => {
45 const handleClickOutside = (event: MouseEvent) => {
46 if (
47 dropdownRef.current &&
48 !dropdownRef.current.contains(event.target as Node)
49 ) {
50 setShowDropdown(false);
51 }
52 };
53
54 document.addEventListener('mousedown', handleClickOutside);
55 return () => document.removeEventListener('mousedown', handleClickOutside);
56 }, []);
57
58 const handleLogout = async () => {
59 await logout();
60 setShowDropdown(false);
61
62 // Show success notification for signout
63 showSuccess(
64 t('auth.userMenu.signOutSuccess', { defaultValue: 'Signed out successfully' }),
65 t('auth.userMenu.signOutMessage', { defaultValue: "You've been securely signed out of DataKit." }),
66 {
67 icon: 'shield',
68 duration: 3000,
69 }
70 );
71 };
72
73 const goToSettings = () => {
74 setShowDropdown(false);
75 // Navigate to settings page
76 window.location.href = '/settings';
77 };
78
79 const handleOpenAuthModal = (mode: 'login' | 'signup') => {
80 setAuthModalMode(mode);
81 setShowAuthModal(true);
82 };
83
84 // Don't show auth buttons while auth status is loading

Callers

nothing calls this directly

Calls 3

useAuthFunction · 0.90
useNotificationsFunction · 0.90
handleOpenAuthModalFunction · 0.70

Tested by

no test coverage detected