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
This commit is contained in:
+8
-4
@@ -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() {
|
|||||||
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() {
|
|||||||
{t('Profile')}
|
{t('Profile')}
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
|
|
||||||
<DropdownMenuItem onClick={() => navigate({ to: '/wallet' })}>
|
{isWalletVisible && (
|
||||||
<Wallet className='size-4' />
|
<DropdownMenuItem onClick={() => navigate({ to: '/wallet' })}>
|
||||||
{t('Wallet')}
|
<Wallet className='size-4' />
|
||||||
</DropdownMenuItem>
|
{t('Wallet')}
|
||||||
|
</DropdownMenuItem>
|
||||||
|
)}
|
||||||
|
|
||||||
{isSuperAdmin && (
|
{isSuperAdmin && (
|
||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
|
|||||||
+20
@@ -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)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user