Merge pull request #942 from chaotixkilla/fix-user-management-issues

Fix styling and URL creation issues in user management page
This commit is contained in:
Rafael Taranto 2021-11-24 17:44:08 +00:00 committed by GitHub
commit e830624e1e
3 changed files with 46 additions and 48 deletions

View file

@ -53,6 +53,11 @@ const reducer = (_, action) => {
} }
} }
const roleMapper = {
user: 'Regular',
superuser: 'Superuser'
}
const Users = () => { const Users = () => {
const classes = useStyles() const classes = useStyles()
const { userData } = useContext(AppContext) const { userData } = useContext(AppContext)
@ -65,63 +70,44 @@ const Users = () => {
const elements = [ const elements = [
{ {
header: 'Login', header: 'Login',
width: 257, width: 307,
textAlign: 'left', textAlign: 'left',
size: 'sm', size: 'sm',
view: u => { view: u => {
if (userData.id === u.id) if (userData.id === u.id)
return ( return (
<> <div className={classes.loginWrapper}>
{u.username} <span className={classes.username}>{u.username}</span>
<Chip size="small" label="You" className={classes.chip} /> <Chip size="small" label="You" className={classes.chip} />
</> </div>
) )
return u.username return <span className={classes.username}>{u.username}</span>
} }
}, },
{ {
header: 'Role', header: 'Role',
width: 105, width: 160,
textAlign: 'center', textAlign: 'left',
size: 'sm',
view: u => {
switch (u.role) {
case 'user':
return 'Regular'
case 'superuser':
return 'Superuser'
default:
return u.role
}
}
},
{
header: '',
width: 80,
textAlign: 'center',
size: 'sm', size: 'sm',
view: u => ( view: u => (
<Switch <div className={classes.loginWrapper}>
disabled={userData.id === u.id} <span>{roleMapper[u.role]}</span>
checked={u.role === 'superuser'} <Switch
onClick={() => { className={classes.roleSwitch}
setUserInfo(u) disabled={userData.id === u.id}
dispatch({ checked={u.role === 'superuser'}
type: 'open', onClick={() => {
payload: 'showRoleModal' setUserInfo(u)
}) dispatch({
}} type: 'open',
value={u.role === 'superuser'} payload: 'showRoleModal'
/> })
}}
value={u.role === 'superuser'}
/>
</div>
) )
}, },
{
header: '',
width: 25,
textAlign: 'center',
size: 'sm',
view: u => {}
},
{ {
header: 'Actions', header: 'Actions',
width: 565, width: 565,

View file

@ -50,13 +50,11 @@ const styles = {
chip: { chip: {
backgroundColor: subheaderColor, backgroundColor: subheaderColor,
fontFamily: fontPrimary, fontFamily: fontPrimary,
marginLeft: 15, marginLeft: 10
marginTop: -5
}, },
actionChip: { actionChip: {
backgroundColor: subheaderColor, backgroundColor: subheaderColor,
marginRight: 15, marginRight: 15
marginTop: -5
}, },
info: { info: {
fontFamily: fontSecondary, fontFamily: fontSecondary,
@ -105,6 +103,21 @@ const styles = {
height: '100%', height: '100%',
overflow: 'hidden', overflow: 'hidden',
position: 'relative' position: 'relative'
},
loginWrapper: {
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between'
},
username: {
overflow: 'hidden',
whiteSpace: 'nowrap',
textOverflow: 'ellipsis',
width: '100%'
},
roleSwitch: {
marginLeft: 15
} }
} }

View file

@ -1,5 +1,4 @@
const url = const url = `https://${window.location.hostname}`
process.env.NODE_ENV === 'development' ? 'https://localhost:3001' : ''
const urlResolver = content => `${url}${content}` const urlResolver = content => `${url}${content}`