Commit 0b2cf43e by feitianbubu Committed by GitHub

fix(web): hide wallet entry in profile dropdown when wallet module disabled (#5708)

The profile dropdown rendered the wallet item unconditionally, so it
still showed after an admin disabled the personal/topup (wallet) sidebar
module. Reuse the sidebar module visibility check so the dropdown honours
the same toggle as the sidebar.

Fixes #5696
parent de0d6ac9
...@@ -24,6 +24,7 @@ import { useAuthStore } from '@/stores/auth-store' ...@@ -24,6 +24,7 @@ import { useAuthStore } from '@/stores/auth-store'
import { getUserAvatarFallback, getUserAvatarStyle } from '@/lib/avatar' import { getUserAvatarFallback, getUserAvatarStyle } from '@/lib/avatar'
import { ROLE } from '@/lib/roles' import { ROLE } from '@/lib/roles'
import useDialogState from '@/hooks/use-dialog' import useDialogState from '@/hooks/use-dialog'
import { useIsSidebarModuleVisible } from '@/hooks/use-sidebar-config'
import { useUserDisplay } from '@/hooks/use-user-display' import { useUserDisplay } from '@/hooks/use-user-display'
import { Avatar, AvatarFallback } from '@/components/ui/avatar' import { Avatar, AvatarFallback } from '@/components/ui/avatar'
import { Button } from '@/components/ui/button' import { Button } from '@/components/ui/button'
...@@ -45,6 +46,7 @@ export function ProfileDropdown() { ...@@ -45,6 +46,7 @@ export function ProfileDropdown() {
const user = useAuthStore((state) => state.auth.user) const user = useAuthStore((state) => state.auth.user)
const { displayName, roleLabel } = useUserDisplay(user) const { displayName, roleLabel } = useUserDisplay(user)
const isSuperAdmin = user?.role === ROLE.SUPER_ADMIN const isSuperAdmin = user?.role === ROLE.SUPER_ADMIN
const isWalletVisible = useIsSidebarModuleVisible('/wallet')
const avatarName = user?.username || displayName const avatarName = user?.username || displayName
const avatarFallback = getUserAvatarFallback(avatarName) const avatarFallback = getUserAvatarFallback(avatarName)
const avatarFallbackStyle = useMemo( const avatarFallbackStyle = useMemo(
...@@ -104,10 +106,12 @@ export function ProfileDropdown() { ...@@ -104,10 +106,12 @@ export function ProfileDropdown() {
{t('Profile')} {t('Profile')}
</DropdownMenuItem> </DropdownMenuItem>
{isWalletVisible && (
<DropdownMenuItem onClick={() => navigate({ to: '/wallet' })}> <DropdownMenuItem onClick={() => navigate({ to: '/wallet' })}>
<Wallet className='size-4' /> <Wallet className='size-4' />
{t('Wallet')} {t('Wallet')}
</DropdownMenuItem> </DropdownMenuItem>
)}
{isSuperAdmin && ( {isSuperAdmin && (
<DropdownMenuItem <DropdownMenuItem
......
...@@ -308,3 +308,23 @@ export function useSidebarConfig(navGroups: NavGroup[]): NavGroup[] { ...@@ -308,3 +308,23 @@ export function useSidebarConfig(navGroups: NavGroup[]): NavGroup[] {
return filteredNavGroups 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)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment