Skip to content

Commit

Permalink
4032 - update roles logic in /UserCountryRoleSelector/hooks/useOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
minotogna committed Dec 18, 2024
1 parent 0768ad2 commit 695e7cb
Showing 1 changed file with 4 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useMemo } from 'react'
import { useTranslation } from 'react-i18next'

import { RoleName, Users } from 'meta/user'
import { Users } from 'meta/user'

import { useCycle } from 'client/store/assessment'
import { useUser } from 'client/store/user'
Expand All @@ -17,20 +17,10 @@ export const useOptions = (): Returned => {
const user = useUser()

return useMemo<Returned>(() => {
const roles = Users.isAdministrator(user)
? Object.keys(RoleName)
: Users.getRolesAllowedToEdit({ user, countryIso, cycle })
const roleNames = Users.getRolesAllowedToEdit({ user, countryIso, cycle })

const options = roles.reduce<Returned>((acc, key) => {
if (key !== RoleName.ADMINISTRATOR) {
acc.push({
label: t(Users.getI18nRoleLabelKey(key)),
value: key,
})
}
return acc
return roleNames.map<Option>((roleName) => {
return { label: t(Users.getI18nRoleLabelKey(roleName)), value: roleName }
}, [])

return options
}, [countryIso, cycle, t, user])
}

0 comments on commit 695e7cb

Please sign in to comment.