diff --git a/src/client/components/EditUserForm/EditUserForm.tsx b/src/client/components/EditUserForm/EditUserForm.tsx index eca3be6194..530c655be9 100644 --- a/src/client/components/EditUserForm/EditUserForm.tsx +++ b/src/client/components/EditUserForm/EditUserForm.tsx @@ -22,14 +22,14 @@ import TextInputField from './TextInputField' import UserRolePropsFields from './UserRolePropsFields' type Props = { - targetUser: User canEditPermissions?: boolean canEditRoles?: boolean canEditUser?: boolean + targetUser: User } const EditUserForm: React.FC = (props: Props) => { - const { targetUser, canEditPermissions, canEditRoles, canEditUser } = props + const { canEditPermissions, canEditRoles, canEditUser, targetUser } = props const dispatch = useAppDispatch() const assessment = useAssessment() const countryIso = useCountryIso() @@ -81,45 +81,49 @@ const EditUserForm: React.FC = (props: Props) => { const enabled = canEditUser const isAdmin = Users.isAdministrator(user) const isTargetAdmin = Users.isAdministrator(targetUser) - const showRoleSelector = !Areas.isGlobal(countryIso) && isAdmin && !isTargetAdmin + const isSelf = user.id === targetUser.id + const showRoleSelector = + !Areas.isGlobal(countryIso) && + !isSelf && + ((isAdmin && !isTargetAdmin) || Users.getRolesAllowedToEdit({ user, cycle, countryIso }).length > 0) return (
setProfilePicture(profilePicture)} userId={targetUser.id} - enabled={enabled} /> - + - {showRoleSelector && } + {showRoleSelector && } {[RoleName.NATIONAL_CORRESPONDENT, RoleName.ALTERNATE_NATIONAL_CORRESPONDENT, RoleName.COLLABORATOR].includes( userRole?.role ) && - roleToEdit && } + roleToEdit && }
{t('editUser.mandatoryFields')}
@@ -128,7 +132,7 @@ const EditUserForm: React.FC = (props: Props) => { )} {canEditRoles && } - {isAdmin && } + {isAdmin && }
) } diff --git a/src/client/components/EditUserForm/TextInputField/TextInputField.tsx b/src/client/components/EditUserForm/TextInputField/TextInputField.tsx index 6fb8acce0f..c67f189aea 100644 --- a/src/client/components/EditUserForm/TextInputField/TextInputField.tsx +++ b/src/client/components/EditUserForm/TextInputField/TextInputField.tsx @@ -43,7 +43,9 @@ const TextInputField: React.FC = (props) => { error: !valid, })} > - {editorLink && onChange(name, _value)} value={value} />} + {editorLink && ( + onChange(name, _value)} value={value} /> + )} {!editorLink && ( = (props: Props) => { - const { enabled, user } = props + const { enabled, target } = props const { countryIso } = useCountryRouteParams() const cycle = useCycle() - const userRole = Users.getRole(user, countryIso, cycle) + const userRole = Users.getRole(target, countryIso, cycle) const options = useOptions() - const onChange = useOnChange(user) + const onChange = useOnChange(target) - return + return } export default UserCountryRoleSelector diff --git a/src/client/components/EditUserForm/UserCountryRoleSelector/hooks/useOptions.tsx b/src/client/components/EditUserForm/UserCountryRoleSelector/hooks/useOptions.tsx index c80045a824..e10e329e07 100644 --- a/src/client/components/EditUserForm/UserCountryRoleSelector/hooks/useOptions.tsx +++ b/src/client/components/EditUserForm/UserCountryRoleSelector/hooks/useOptions.tsx @@ -1,26 +1,26 @@ 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' +import { useCountryRouteParams } from 'client/hooks/useRouteParams' import { Option } from 'client/components/Inputs/Select' type Returned = Array