Skip to content

Commit

Permalink
add superadmin compare
Browse files Browse the repository at this point in the history
  • Loading branch information
KelvinTegelaar committed Apr 16, 2024
1 parent 98a2d31 commit eeee870
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions src/hooks/useRouteNavCompare.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,33 @@ import routes from 'src/routes'
export const useRouteNavCompare = (navigation) => {
const dispatch = useDispatch()
const { data: profile, isFetching } = useLoadClientPrincipalQuery()

if (isFetching) {
return { isLoading: true, component: null }
}

dispatch(updateAccessToken(profile))
let roles = profile?.clientPrincipal?.userRoles || []
let newNavigation = navigation.map((nav) => {
if (nav.items) {
nav.items = nav.items.filter((item) => {
const route = routes.find((r) => r.path === item.to)
if (
!route ||
(route.allowedRoles && route.allowedRoles.some((role) => roles.includes(role)))
) {
return true
} else {
//console.log('Removing route', item)
return false
}
})
}
return nav
})
const roles = profile?.clientPrincipal?.userRoles || []

if (roles.includes('superadmin')) {
// For 'superadmin', simplify to Dashboard and /cipp/ routes directly so people don't work under this account.
return navigation.filter((nav) => nav.to === '/home' || nav.to?.startsWith('/cipp'))
}

return newNavigation
// For other roles, use existing filtering logic
return navigation
.map((nav) => {
if (nav.items) {
nav.items = nav.items.filter((item) => {
const route = routes.find((r) => r.path === item.to)
return (
route &&
(!route.allowedRoles || route.allowedRoles.some((role) => roles.includes(role)))
)
})
return nav
}
return nav
})
.filter((nav) => nav.items && nav.items.length > 0) // Remove empty navigation groups
}

0 comments on commit eeee870

Please sign in to comment.