diff --git a/src/features/projects/ManageUsersTable.jsx b/src/features/projects/ManageUsersTable.jsx index 7ddddfa..7f4dcbb 100644 --- a/src/features/projects/ManageUsersTable.jsx +++ b/src/features/projects/ManageUsersTable.jsx @@ -1,17 +1,31 @@ import React, { useEffect, useMemo } from 'react'; import { useSelector, useDispatch } from 'react-redux'; import { styled } from '@stitches/react'; -import { Pencil1Icon } from '@radix-ui/react-icons'; - +import { Pencil1Icon, ResetIcon } from '@radix-ui/react-icons'; import Button from '../../components/Button'; import IconButton from '../../components/IconButton.jsx'; -import { Tooltip, TooltipContent, TooltipArrow, TooltipTrigger } from '../../components/Tooltip.jsx'; +import { + Tooltip, + TooltipContent, + TooltipArrow, + TooltipTrigger, +} from '../../components/Tooltip.jsx'; import { ButtonRow } from '../../components/Form'; import { SimpleSpinner, SpinnerOverlay } from '../../components/Spinner.jsx'; -import { addUser, editUser, fetchUsers, selectUsers, selectUsersLoading } from './usersSlice.js'; +import { selectUserCurrentRoles } from '../auth/authSlice'; +import { + addUser, + editUser, + fetchUsers, + selectUsers, + selectUsersLoading, + resetUserPassword, +} from './usersSlice.js'; +import { hasRole, MANAGE_USERS_ROLES } from '../auth/roles'; const ManageUsersTable = () => { const dispatch = useDispatch(); + const currentUserRoles = useSelector(selectUserCurrentRoles); const users = useSelector(selectUsers); const isLoading = useSelector(selectUsersLoading); @@ -45,19 +59,43 @@ const ManageUsersTable = () => { {email} {roles.join(', ')} - - - - dispatch(editUser(email))}> - - - - - Edit user roles - - - - + {hasRole(currentUserRoles, MANAGE_USERS_ROLES) && ( + + + + dispatch(editUser(email))} + > + + + + + Edit user roles + + + + + + { + dispatch(editUser(email)); + dispatch(resetUserPassword()); + }} + > + + + + + Reset Password + + + + + )} ))} diff --git a/src/features/projects/usersSlice.js b/src/features/projects/usersSlice.js index 3f995a9..858ae06 100644 --- a/src/features/projects/usersSlice.js +++ b/src/features/projects/usersSlice.js @@ -205,6 +205,17 @@ export const createUser = (values) => { }; }; +export const resetUserPassword = () => { + return async (dispatch, getState) => { + try { + const selectedUser = getState().users.selectedUser; + Auth.resetUserPassword(selectedUser.username); + } catch (err) { + console.error(err); + } + }; +}; + export const selectUsers = (state) => state.users.users; export const selectMode = (state) => state.users.mode; export const selectSelectedUser = (state) => state.users.selectedUser;