Skip to content

Commit

Permalink
preliminary implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jue-henry committed Dec 21, 2024
1 parent 7220aa6 commit 1a2cf6b
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 17 deletions.
72 changes: 55 additions & 17 deletions src/features/projects/ManageUsersTable.jsx
Original file line number Diff line number Diff line change
@@ -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);

Expand Down Expand Up @@ -45,19 +59,43 @@ const ManageUsersTable = () => {
<TableRow key={email}>
<TableCell>{email}</TableCell>
<TableCell>{roles.join(', ')}</TableCell>
<TableCell>
<Tooltip>
<TooltipTrigger asChild>
<IconButton variant="ghost" size="large" onClick={() => dispatch(editUser(email))}>
<Pencil1Icon />
</IconButton>
</TooltipTrigger>
<TooltipContent side="top" sideOffset={5}>
Edit user roles
<TooltipArrow />
</TooltipContent>
</Tooltip>
</TableCell>
{hasRole(currentUserRoles, MANAGE_USERS_ROLES) && (
<TableCell>
<Tooltip>
<TooltipTrigger asChild>
<IconButton
variant="ghost"
size="med"
onClick={() => dispatch(editUser(email))}
>
<Pencil1Icon />
</IconButton>
</TooltipTrigger>
<TooltipContent side="top" sideOffset={5}>
Edit user roles
<TooltipArrow />
</TooltipContent>
</Tooltip>
<Tooltip>
<TooltipTrigger asChild>
<IconButton
variant="ghost"
size="med"
onClick={() => {
dispatch(editUser(email));
dispatch(resetUserPassword());
}}
>
<ResetIcon />
</IconButton>
</TooltipTrigger>
<TooltipContent side="top" sideOffset={5}>
Reset Password
<TooltipArrow />
</TooltipContent>
</Tooltip>
</TableCell>
)}
</TableRow>
))}
</tbody>
Expand Down
11 changes: 11 additions & 0 deletions src/features/projects/usersSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1a2cf6b

Please sign in to comment.