'use client' import React, { useEffect, useMemo } from 'react' import styled from 'styled-components' import Link from 'next/link' import { Package2, Settings, Crown, Shield, User, Users, Building, LogOut, User as UserIcon, Home, ChevronDown } from 'lucide-react' import UserAvatar from '@components/Objects/UserAvatar' import useAdminStatus from '@components/Hooks/useAdminStatus' import { useLHSession } from '@components/Contexts/LHSessionContext' import { useOrg } from '@components/Contexts/OrgContext' import { getUriWithoutOrg } from '@services/config/config' import Tooltip from '@components/Objects/StyledElements/Tooltip/Tooltip' import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@components/ui/dropdown-menu" import { signOut } from 'next-auth/react' interface RoleInfo { name: string; icon: React.ReactNode; bgColor: string; textColor: string; description: string; } interface CustomRoleInfo { name: string; description?: string; } export const HeaderProfileBox = () => { const session = useLHSession() as any const { isAdmin, loading, userRoles, rights } = useAdminStatus() const org = useOrg() as any useEffect(() => { } , [session]) const userRoleInfo = useMemo((): RoleInfo | null => { if (!userRoles || userRoles.length === 0) return null; // Find the highest priority role for the current organization const orgRoles = userRoles.filter((role: any) => role.org.id === org?.id); if (orgRoles.length === 0) return null; // Sort by role priority (admin > maintainer > instructor > user) const sortedRoles = orgRoles.sort((a: any, b: any) => { const getRolePriority = (role: any) => { if (role.role.role_uuid === 'role_global_admin' || role.role.id === 1) return 4; if (role.role.role_uuid === 'role_global_maintainer' || role.role.id === 2) return 3; if (role.role.role_uuid === 'role_global_instructor' || role.role.id === 3) return 2; return 1; }; return getRolePriority(b) - getRolePriority(a); }); const highestRole = sortedRoles[0]; // Define role configurations based on actual database roles const roleConfigs: { [key: string]: RoleInfo } = { 'role_global_admin': { name: 'ADMIN', icon: , bgColor: 'bg-purple-600', textColor: 'text-white', description: 'Full platform control with all permissions' }, 'role_global_maintainer': { name: 'MAINTAINER', icon: , bgColor: 'bg-blue-600', textColor: 'text-white', description: 'Mid-level manager with wide permissions' }, 'role_global_instructor': { name: 'INSTRUCTOR', icon: , bgColor: 'bg-green-600', textColor: 'text-white', description: 'Can manage their own content' }, 'role_global_user': { name: 'USER', icon: , bgColor: 'bg-gray-500', textColor: 'text-white', description: 'Read-Only Learner' } }; // Determine role based on role_uuid or id let roleKey = 'role_global_user'; // default if (highestRole.role.role_uuid) { roleKey = highestRole.role.role_uuid; } else if (highestRole.role.id === 1) { roleKey = 'role_global_admin'; } else if (highestRole.role.id === 2) { roleKey = 'role_global_maintainer'; } else if (highestRole.role.id === 3) { roleKey = 'role_global_instructor'; } return roleConfigs[roleKey] || roleConfigs['role_global_user']; }, [userRoles, org?.id]); const customRoles = useMemo((): CustomRoleInfo[] => { if (!userRoles || userRoles.length === 0) return []; // Find roles for the current organization const orgRoles = userRoles.filter((role: any) => role.org.id === org?.id); if (orgRoles.length === 0) return []; // Filter for custom roles (not system roles) const customRoles = orgRoles.filter((role: any) => { // Check if it's a system role const isSystemRole = role.role.role_uuid?.startsWith('role_global_') || [1, 2, 3, 4].includes(role.role.id) || ['Admin', 'Maintainer', 'Instructor', 'User'].includes(role.role.name); return !isSystemRole; }); return customRoles.map((role: any) => ({ name: role.role.name || 'Custom Role', description: role.role.description })); }, [userRoles, org?.id]); return ( {session.status == 'unauthenticated' && (
  • Login
  • Sign up
)} {session.status == 'authenticated' && (

{session.data.user.username}

{session.data.user.email}

{rights?.dashboard?.action_access && ( Dashboard )} User Settings My Courses signOut({ callbackUrl: '/' })} className="flex items-center space-x-2 text-red-600 focus:text-red-600" > Sign Out
)}
) } const AccountArea = styled.div` display: flex; place-items: center; img { width: 29px; } ` const ProfileArea = styled.div` display: flex; place-items: stretch; place-items: center; ` const UnidentifiedArea = styled.div` display: flex; place-items: stretch; grow: 1; `