Skip to content

Commit 57da681

Browse files
committed
user edit styles in progress
1 parent 718adeb commit 57da681

File tree

2 files changed

+108
-5
lines changed

2 files changed

+108
-5
lines changed

src/Administration/Users/UsersEditor/UsersEditor.js

Lines changed: 103 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,32 @@ import api from '@/_api'
55

66
import BasePageContainer from '@/_common/BasePageContainer'
77
import BasePageToolbar from '@/_common/BasePageToolbar'
8-
import Grid from "@material-ui/core/Grid";
8+
import { Save as SaveIcon } from '@material-ui/icons/'
9+
import {
10+
Input,
11+
Select,
12+
MenuItem,
13+
Paper,
14+
Button,
15+
FormControl,
16+
InputLabel,
17+
makeStyles,
18+
Grid
19+
} from '@material-ui/core'
920

1021
const UserEditor = (props) => {
22+
const classes = useStyles()
1123

1224
const { userId } = props
13-
const [user, setUser] = useState({})
25+
const [user, setUser] = useState({
26+
avatarUrl: '',
27+
email: '',
28+
firstName: '',
29+
globalRole: '',
30+
lastName: '',
31+
userToOrganizations: [{}],
32+
username: ''
33+
})
1434

1535
useEffect(() => {
1636
if(!userId) {
@@ -27,11 +47,78 @@ const UserEditor = (props) => {
2747
fetchUser()
2848
}, [userId])
2949

50+
const onChangeHandler = (e) => setUser({
51+
...user,
52+
[e.target.name]: e.target.value
53+
})
54+
55+
const setGlobalRole = (e) => setUser({
56+
...user,
57+
globalRole: e.target.value
58+
})
59+
60+
const handleSubmit = async (e) => {
61+
e.preventDefault();
62+
try {
63+
if(userId) {
64+
await api.users.update(userId, user)
65+
} else {
66+
await api.users.create(user)
67+
}
68+
} catch (e) {
69+
console.log(e)
70+
}
71+
}
72+
3073
return (
3174
<BasePageContainer>
3275
<BasePageToolbar title={'Edit user'}></BasePageToolbar>
33-
<Grid container spacing={3}>
34-
UserEditor
76+
<Grid container xs={12}>
77+
<Grid item xs={6}>
78+
<Paper>
79+
<form onSubmit={handleSubmit}>
80+
<FormControl className={classes.control}>
81+
<InputLabel>First Name</InputLabel>
82+
<Input value={user.firstName} name="firstName" className={classes.width} onChange={e => onChangeHandler(e)}/>
83+
</FormControl>
84+
<FormControl className={classes.control}>
85+
<InputLabel>Last Name</InputLabel>
86+
<Input value={user.lastName} name="lastName" className={classes.width} onChange={e => onChangeHandler(e)}/>
87+
</FormControl>
88+
<FormControl className={classes.control}>
89+
<InputLabel>User Name</InputLabel>
90+
<Input value={user.username} name="username" className={classes.width} onChange={e => onChangeHandler(e)}/>
91+
</FormControl>
92+
<FormControl className={classes.control}>
93+
<InputLabel>Email</InputLabel>
94+
<Input value={user.email} name="email" className={classes.width} onChange={e => onChangeHandler(e)}/>
95+
</FormControl>
96+
<FormControl className={classes.control}>
97+
<InputLabel>Global Role</InputLabel>
98+
<Select
99+
labelId="Set Global Role"
100+
id="globalRole"
101+
value={user.globalRole}
102+
onChange={setGlobalRole}
103+
className={classes.width}
104+
>
105+
<MenuItem value={user.globalRole}>{user.globalRole}</MenuItem>
106+
<MenuItem value='user'>user</MenuItem>
107+
<MenuItem value='support'>support</MenuItem>
108+
</Select>
109+
</FormControl>
110+
<Button
111+
variant="contained"
112+
color="primary"
113+
type="submit"
114+
className={`${classes.margin} ${classes.width}`}
115+
startIcon={<SaveIcon />}
116+
>
117+
Edit User
118+
</Button>
119+
</form>
120+
</Paper>
121+
</Grid>
35122
</Grid>
36123
</BasePageContainer>
37124
)
@@ -41,4 +128,16 @@ UserEditor.propTypes = {
41128
userId: PropTypes.number
42129
}
43130

131+
const useStyles = makeStyles(theme => ({
132+
control: {
133+
display: 'block'
134+
},
135+
margin: {
136+
marginTop: 16
137+
},
138+
width: {
139+
minWidth: 200
140+
}
141+
}))
142+
44143
export default UserEditor

src/Administration/Users/UsersList/UsersListTableItems.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Skeleton } from '@material-ui/lab'
88
import { Edit as EditIcon, Delete as DeleteIcon } from '@material-ui/icons/'
99

1010
const UsersListTableItems = ({ users, rowsPerPage = 10, rowsExpected = 10 }) => {
11+
const classes = useStyles()
1112
// Count how many empty rows needs to be filled
1213
const usersVisible = users.length || rowsExpected
1314
const usersArrayExpected = Array.from({ length: usersVisible }).map(
@@ -60,7 +61,7 @@ const UsersListTableItems = ({ users, rowsPerPage = 10, rowsExpected = 10 }) =>
6061
/>
6162
</TableCell>
6263
<TableCell>
63-
<Link to={{ pathname: `users/${row.id}/edit` }}>
64+
<Link to={{ pathname: `users/${row.id}/edit` }} className={classes.link}>
6465
<EditIcon />
6566
</Link>
6667
<DeleteIcon />
@@ -83,6 +84,9 @@ const useStyles = makeStyles(theme => ({
8384
flexShrink: 0,
8485
marginLeft: theme.spacing(2.5),
8586
},
87+
link: {
88+
color: 'inherit'
89+
}
8690
}))
8791

8892
export default UsersListTableItems

0 commit comments

Comments
 (0)