Skip to content
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

Updated User Management Section #1557

170 changes: 115 additions & 55 deletions client/src/components/user-admin/UserManagement.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
import React, { useState } from 'react';
import {Box, Button, ButtonGroup, TextField, Typography, List, ListItem, ListItemButton} from '@mui/material';


import '../../sass/UserAdmin.scss';

// const h3sx = {
freaky4wrld marked this conversation as resolved.
Show resolved Hide resolved
// fontFamily: 'aliseoregular',
// fontSize: {xs: "1.6rem"},
// marginBottom: `1rem`,
// marginTop: `1rem`,
// textAlign: "center",
// }
const Buttonsx = {
p: "0.1rem",
fontSize: {xs: '14.52px', sm: '18px'}
}

const UserManagement = ({ users, setUserToEdit }) => {
let searchResults = [];
const [searchResultType, setSearchResultType] = useState('name'); // Which results will diplay
Expand Down Expand Up @@ -43,67 +58,112 @@ const UserManagement = ({ users, setUserToEdit }) => {
}
return (
<div className="container--usermanagement">
trillium marked this conversation as resolved.
Show resolved Hide resolved
<div>
<h3>User Management</h3>
<input
<Box sx={{
freaky4wrld marked this conversation as resolved.
Show resolved Hide resolved
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
width: '75%',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a few other comments in here about width being used. This is another case where I'd prefer to see the boundaries of the box maintained by margin or padding eg:

sx={{
  mx: 2 // This is just an example value
        // mx being mui's system for marginLeft and marginRight
}}

If we do need to limit the width of this Box, I'd prefer we go with a maxWidth property so that the size is properly restrained on wider screens.

pt: '40px',
freaky4wrld marked this conversation as resolved.
Show resolved Hide resolved
height: '100%',
}}>
<Typography variant='h1'>User Management</Typography>

<div className="tab-buttons">
freaky4wrld marked this conversation as resolved.
Show resolved Hide resolved
<ButtonGroup sx={{
display: 'flex',
flexDirection: 'row',
justifyContent: 'center',
minWidth: '127%',
whiteSpace: 'nowrap',
}}>
<Button
sx={Buttonsx}
type="button"
variant={
searchResultType === 'name'
? 'contained'
: 'secondary'
}
onClick={buttonSwap
}
freaky4wrld marked this conversation as resolved.
Show resolved Hide resolved
>
Results by Name
</Button>
<Button
sx={Buttonsx}
type="button"
variant={
searchResultType === 'email'
? 'contained'
: 'secondary'
}
onClick={buttonSwap
freaky4wrld marked this conversation as resolved.
Show resolved Hide resolved
}
>
Results by Email
</Button>
</ButtonGroup>
</div>
freaky4wrld marked this conversation as resolved.
Show resolved Hide resolved
<TextField
trillium marked this conversation as resolved.
Show resolved Hide resolved
type="text"
placeholder="Search by name and email..."
placeholder="Enter name and / or email to find a user."
variant='standard'
value={searchTerm}
onChange={handleChange}
/>
<div className="tab-buttons">
<div>
<button
type="button"
className={
searchResultType === 'name'
? 'select-button selected'
: 'select-button'
}
onClick={buttonSwap}
disabled={searchResultType === 'name'}
>
Results by Name
</button>
</div>
<div>
<button
type="button"
className={
searchResultType === 'email'
? 'select-button selected'
: 'select-button'
}
onClick={buttonSwap}
disabled={searchResultType === 'email'}
>
Results by Email
</button>
</div>
</div>
<Box sx={{
freaky4wrld marked this conversation as resolved.
Show resolved Hide resolved
bgcolor: searchResults.length>0? '#F5F5F5': 'transparent',
trillium marked this conversation as resolved.
Show resolved Hide resolved
my: 1.2,
width: '120%',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you find a different way to get the Box's width correct? This is happening in a few places, but overall using a width over 100% is going to cause issues for the box modle and future refactoring down the line.

A good approach would be to assume that the width of the container is going to 100% unless otherwise specified, and add the necessary margin/padding to the Box or div to get things to render properly.

borderRadius: '1%',
freaky4wrld marked this conversation as resolved.
Show resolved Hide resolved
display: 'flex',
freaky4wrld marked this conversation as resolved.
Show resolved Hide resolved
flexGrow: 1,
}}>
<Box sx={{width: '120%'}}>
<List className="search-results disablePadding">
{searchResults.map((u) => {
return (
// eslint-disable-next-line no-underscore-dangle
<ListItem
sx={{
px: '1.2rem',
freaky4wrld marked this conversation as resolved.
Show resolved Hide resolved
py: '0.25rem',
borderBottom: 1.6,
borderBottomColor: 'grey.300'
freaky4wrld marked this conversation as resolved.
Show resolved Hide resolved
}}
key={`result_${u._id}`}>
<ListItemButton
sx={{
px: '0.12rem',
freaky4wrld marked this conversation as resolved.
Show resolved Hide resolved
py: '0.18rem',
color: 'primary.main',
}}
className="search-results-button"
type="button"
onClick={() => setUserToEdit(u)}
>
{searchResultType === 'name'
? `${u.name?.firstName} ${u.name?.lastName} ( ${u.email} )`
: `${u.email} ( ${u.name?.firstName} ${u.name?.lastName} )`}
</ListItemButton>
</ListItem>
);
})}
</List>
</Box>
</Box>
<div>
<div>
<ul className="search-results">
{searchResults.map((u) => {
return (
// eslint-disable-next-line no-underscore-dangle
<li key={`result_${u._id}`}>
<button
className="search-results-button"
type="button"
onClick={() => setUserToEdit(u)}
>
{searchResultType === 'name'
? `${u.name?.firstName} ${u.name?.lastName} ( ${u.email} )`
: `${u.email} ( ${u.name?.firstName} ${u.name?.lastName} )`}
</button>
</li>
);
})}
</ul>
</div>
<Button
sx={{
freaky4wrld marked this conversation as resolved.
Show resolved Hide resolved

}}
type='button'
variant='secondary'
>
Add a New User
</Button>
</div>
</div>
</Box>
</div>
freaky4wrld marked this conversation as resolved.
Show resolved Hide resolved
);
};
Expand Down
1 change: 1 addition & 0 deletions client/src/sass/UserAdmin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
align-items: center;
z-index: 1;
margin-bottom: 200px;
height: 100%;
}

.edit-users {
Expand Down
Loading