Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix UI to update user roles
  • Loading branch information
BrunoQuaresma committed May 9, 2022
commit 16d1e7b0b54e08c86ce1a31eb500696e5f90c118
5 changes: 3 additions & 2 deletions site/src/components/UsersTable/RoleSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const RoleSelect: React.FC<RoleSelectProps> = ({ roles, selectedRoles, lo
const styles = useStyles()
const value = selectedRoles.map((r) => r.name)
const renderValue = () => selectedRoles.map((r) => r.display_name).join(", ")
const sortedRoles = roles.sort((a, b) => a.display_name.localeCompare(b.display_name))

return (
<Select
Expand All @@ -25,11 +26,11 @@ export const RoleSelect: React.FC<RoleSelectProps> = ({ roles, selectedRoles, lo
variant="outlined"
className={styles.select}
onChange={(e) => {
const { value } = e.currentTarget
const { value } = e.target
onChange(value as string[])
}}
>
{roles.map((r) => {
{sortedRoles.map((r) => {
const isChecked = selectedRoles.some((selectedRole) => selectedRole.name === r.name)

return (
Expand Down
5 changes: 2 additions & 3 deletions site/src/xServices/users/usersXService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ export const usersMachine = createMachine(
displayError(Language.resetUserPasswordError)
},
displayUpdateRolesSuccess: () => {
displayError(Language.updateUserRolesSuccess)
displaySuccess(Language.updateUserRolesSuccess)
},
displayUpdateRolesErrorMessage: () => {
displayError(Language.updateUserRolesError)
Expand All @@ -317,8 +317,7 @@ export const usersMachine = createMachine(
return users
}

const updatedUser = event.data
return users.map((u) => (u.id === updatedUser.id ? updatedUser : u))
return users.map((u) => (u.id === event.data.id ? event.data : u))
},
}),
},
Expand Down