Skip to content

feat: Add update user roles action #1361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
May 10, 2022
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
Do not display the success notification
  • Loading branch information
BrunoQuaresma committed May 9, 2022
commit 1e93bd2e04772a380a2a890760697a39c0d5e8ac
5 changes: 4 additions & 1 deletion site/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,7 @@ export const getSiteRoles = async (): Promise<Array<TypesGen.Role>> => {
export const updateUserRoles = async (
roles: TypesGen.Role["name"][],
userId: TypesGen.User["id"],
): Promise<TypesGen.User> => axios.put(`/api/v2/users/${userId}/roles`, { roles })
): Promise<TypesGen.User> => {
const response = await axios.put<TypesGen.User>(`/api/v2/users/${userId}/roles`, { roles })
return response.data
}
9 changes: 4 additions & 5 deletions site/src/xServices/users/usersXService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export const usersMachine = createMachine(
id: "updateUserRoles",
onDone: {
target: "idle",
actions: ["displayUpdateRolesSuccess", "updateUserRolesInTheList"],
actions: ["updateUserRolesInTheList"],
},
onError: {
target: "idle",
Expand Down Expand Up @@ -302,9 +302,6 @@ export const usersMachine = createMachine(
displayResetPasswordErrorMessage: () => {
displayError(Language.resetUserPasswordError)
},
displayUpdateRolesSuccess: () => {
displaySuccess(Language.updateUserRolesSuccess)
},
displayUpdateRolesErrorMessage: () => {
displayError(Language.updateUserRolesError)
},
Expand All @@ -317,7 +314,9 @@ export const usersMachine = createMachine(
return users
}

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