({ primaryColor = '' }: { primaryColor?: string })
| 42 | } |
| 43 | |
| 44 | export const HeaderProfileBox = ({ primaryColor = '' }: { primaryColor?: string }) => { |
| 45 | const session = useLHSession() as any |
| 46 | const { isAdmin, loading, userRoles, rights } = useAdminStatus() |
| 47 | const org = useOrg() as any |
| 48 | const { t, i18n } = useTranslation() |
| 49 | const colors = getMenuColorClasses(primaryColor) |
| 50 | |
| 51 | |
| 52 | const userRoleInfo = useMemo((): RoleInfo | null => { |
| 53 | if (!userRoles || userRoles.length === 0) return null; |
| 54 | |
| 55 | // Find the highest priority role for the current organization |
| 56 | const orgRoles = userRoles.filter((role: any) => role.org.id === org?.id); |
| 57 | |
| 58 | if (orgRoles.length === 0) return null; |
| 59 | |
| 60 | // Sort by role priority (admin > maintainer > instructor > user) |
| 61 | const sortedRoles = [...orgRoles].sort((a: any, b: any) => { |
| 62 | const getRolePriority = (role: any) => { |
| 63 | if (role.role.role_uuid === 'role_global_admin' || role.role.id === 1) return 4; |
| 64 | if (role.role.role_uuid === 'role_global_maintainer' || role.role.id === 2) return 3; |
| 65 | if (role.role.role_uuid === 'role_global_instructor' || role.role.id === 3) return 2; |
| 66 | return 1; |
| 67 | }; |
| 68 | return getRolePriority(b) - getRolePriority(a); |
| 69 | }); |
| 70 | |
| 71 | const highestRole = sortedRoles[0]; |
| 72 | |
| 73 | // Define role configurations based on actual database roles |
| 74 | const roleConfigs: { [key: string]: RoleInfo } = { |
| 75 | 'role_global_admin': { |
| 76 | name: t('roles.role_admin'), |
| 77 | icon: <Crown size={12} weight="fill" />, |
| 78 | bgColor: 'bg-purple-600', |
| 79 | textColor: 'text-white', |
| 80 | description: t('roles.role_admin_desc') |
| 81 | }, |
| 82 | 'role_global_maintainer': { |
| 83 | name: t('roles.role_maintainer'), |
| 84 | icon: <Shield size={12} weight="fill" />, |
| 85 | bgColor: 'bg-blue-600', |
| 86 | textColor: 'text-white', |
| 87 | description: t('roles.role_maintainer_desc') |
| 88 | }, |
| 89 | 'role_global_instructor': { |
| 90 | name: t('roles.role_instructor'), |
| 91 | icon: <Users size={12} weight="fill" />, |
| 92 | bgColor: 'bg-green-600', |
| 93 | textColor: 'text-white', |
| 94 | description: t('roles.role_instructor_desc') |
| 95 | }, |
| 96 | 'role_global_user': { |
| 97 | name: t('roles.role_user'), |
| 98 | icon: <User size={12} weight="fill" />, |
| 99 | bgColor: 'bg-gray-500', |
| 100 | textColor: 'text-white', |
| 101 | description: t('roles.role_user_desc') |
nothing calls this directly
no test coverage detected