Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions web/default/src/components/profile-dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { useAuthStore } from '@/stores/auth-store'
import { getUserAvatarFallback, getUserAvatarStyle } from '@/lib/avatar'
import { ROLE } from '@/lib/roles'
import useDialogState from '@/hooks/use-dialog'
import { useIsSidebarModuleVisible } from '@/hooks/use-sidebar-config'
import { useUserDisplay } from '@/hooks/use-user-display'
import { Avatar, AvatarFallback } from '@/components/ui/avatar'
import { Button } from '@/components/ui/button'
Expand All @@ -45,6 +46,7 @@ export function ProfileDropdown() {
const user = useAuthStore((state) => state.auth.user)
const { displayName, roleLabel } = useUserDisplay(user)
const isSuperAdmin = user?.role === ROLE.SUPER_ADMIN
const isWalletVisible = useIsSidebarModuleVisible('/wallet')
const avatarName = user?.username || displayName
const avatarFallback = getUserAvatarFallback(avatarName)
const avatarFallbackStyle = useMemo(
Expand Down Expand Up @@ -104,10 +106,12 @@ export function ProfileDropdown() {
{t('Profile')}
</DropdownMenuItem>

<DropdownMenuItem onClick={() => navigate({ to: '/wallet' })}>
<Wallet className='size-4' />
{t('Wallet')}
</DropdownMenuItem>
{isWalletVisible && (
<DropdownMenuItem onClick={() => navigate({ to: '/wallet' })}>
<Wallet className='size-4' />
{t('Wallet')}
</DropdownMenuItem>
)}

{isSuperAdmin && (
<DropdownMenuItem
Expand Down
20 changes: 20 additions & 0 deletions web/default/src/hooks/use-sidebar-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,3 +308,23 @@ export function useSidebarConfig(navGroups: NavGroup[]): NavGroup[] {

return filteredNavGroups
}

/**
* Check whether a single route is visible under the current sidebar_modules
* config. Used by entries living outside the sidebar (e.g. the profile
* dropdown's wallet link) so they honour the same "wallet display" toggle.
*/
export function useIsSidebarModuleVisible(url: string): boolean {
const { status } = useStatus()
const { auth } = useAuthStore()

const adminConfig = parseSidebarConfig(
status?.SidebarModulesAdmin as string | null | undefined
)
const userConfig =
auth?.user?.permissions?.sidebar_settings === false
? null
: parseUserSidebarConfig(auth?.user?.sidebar_modules)

return isModuleEnabled(url, adminConfig, userConfig)
}