From d7bde65cd07c681b4a0cdea95034840e7ad4786d Mon Sep 17 00:00:00 2001 From: alma Date: Sat, 3 May 2025 12:44:29 +0200 Subject: [PATCH] cleaning hard 2 --- components/navbar/user-menu.tsx | 181 -------------------------------- 1 file changed, 181 deletions(-) delete mode 100644 components/navbar/user-menu.tsx diff --git a/components/navbar/user-menu.tsx b/components/navbar/user-menu.tsx deleted file mode 100644 index 536f72f9..00000000 --- a/components/navbar/user-menu.tsx +++ /dev/null @@ -1,181 +0,0 @@ -"use client"; - -import { useState } from "react"; -import { Circle, LogOut } from "lucide-react"; -import { useSession, signIn, signOut } from "next-auth/react"; -import { - DropdownMenu, - DropdownMenuContent, - DropdownMenuItem, - DropdownMenuLabel, - DropdownMenuSeparator, - DropdownMenuTrigger, -} from "@/components/ui/dropdown-menu"; -import { Session } from "next-auth"; - -interface UserMenuProps { - session: Session | null; - status: "loading" | "authenticated" | "unauthenticated"; -} - -const requestNotificationPermission = async () => { - try { - const permission = await Notification.requestPermission(); - return permission === "granted"; - } catch (error) { - console.error("Error requesting notification permission:", error); - return false; - } -}; - -export default function UserMenu({ session, status }: UserMenuProps) { - const [userStatus, setUserStatus] = useState<'online' | 'busy' | 'away'>('online'); - - // Get user initials - const getUserInitials = () => { - if (session?.user?.name) { - // Split the full name and get initials - const names = session.user.name.split(' '); - if (names.length >= 2) { - return `${names[0][0]}${names[names.length - 1][0]}`.toUpperCase(); - } - // If only one name, use first two letters - return names[0].slice(0, 2).toUpperCase(); - } - return "?"; - }; - - // Function to get display name - const getDisplayName = () => { - return session?.user?.name || "User"; - }; - - // Status configurations - const statusConfig = { - online: { - color: 'text-green-500', - label: 'Online', - notifications: true - }, - busy: { - color: 'text-orange-500', - label: 'Busy', - notifications: false - }, - away: { - color: 'text-gray-500', - label: 'Away', - notifications: false - }, - }; - - // Handle status change - const handleStatusChange = async (newStatus: 'online' | 'busy' | 'away') => { - setUserStatus(newStatus); - - if (newStatus !== 'online') { - const hasPermission = await requestNotificationPermission(); - - if (hasPermission) { - // Disable notifications - if ('serviceWorker' in navigator) { - const registration = await navigator.serviceWorker.ready; - await registration.pushManager.getSubscription()?.then(subscription => { - if (subscription) { - subscription.unsubscribe(); - } - }); - } - } - } else { - // Re-enable notifications if going back online - requestNotificationPermission(); - } - }; - - if (status === "authenticated" && session?.user) { - return ( - - -
- {getUserInitials()} -
-
- - -
- {getDisplayName()} - - -
- - {statusConfig[userStatus].label} -
-
- - handleStatusChange('online')}> - - Online - - handleStatusChange('busy')}> - - Busy - - handleStatusChange('away')}> - - Away - - -
-
-
- - { - try { - // First sign out from NextAuth - await signOut({ - callbackUrl: '/signin', - redirect: false - }); - - // Then redirect to Keycloak logout with proper parameters - const keycloakLogoutUrl = new URL( - `${process.env.NEXT_PUBLIC_KEYCLOAK_ISSUER}/protocol/openid-connect/logout` - ); - - // Add required parameters - keycloakLogoutUrl.searchParams.append( - 'post_logout_redirect_uri', - window.location.origin - ); - keycloakLogoutUrl.searchParams.append( - 'id_token_hint', - session?.accessToken || '' - ); - - // Redirect to Keycloak logout - window.location.href = keycloakLogoutUrl.toString(); - } catch (error) { - console.error('Error during logout:', error); - // Fallback to simple redirect if something goes wrong - window.location.href = '/signin'; - } - }} - > - - Sign out - -
-
- ); - } - - return ( -
- signIn("keycloak", { callbackUrl: "/" })}> - Login - -
- ); -} \ No newline at end of file