Skip to content

Commit 718adeb

Browse files
committed
user edit change router
1 parent 54c7dc2 commit 718adeb

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

src/Administration/Administration.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ const Administration = ({ match }) => {
88
return (
99
<>
1010
<Route exact path={`${match.path}/users`} component={UsersList} />
11-
<Route path={`${match.path}/users/:userId/edit`} component={UserEditor} />
11+
<Route
12+
path={`${match.path}/users/new`}
13+
render={(props) => <UserEditor {...props} />}
14+
/>
15+
<Route
16+
path={`${match.path}/users/:userId/edit`}
17+
render={(props) => <UserEditor {...props} userId={parseInt(props.match.params.userId)} />}
18+
/>
1219
</>
1320
)
1421
}

src/Administration/Users/UsersEditor/UsersEditor.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,20 @@ import PropTypes from 'prop-types'
33

44
import api from '@/_api'
55

6-
const UserEditor = ({ match }) => {
7-
const [user, setUser] = useState([])
6+
import BasePageContainer from '@/_common/BasePageContainer'
7+
import BasePageToolbar from '@/_common/BasePageToolbar'
8+
import Grid from "@material-ui/core/Grid";
9+
10+
const UserEditor = (props) => {
11+
12+
const { userId } = props
13+
const [user, setUser] = useState({})
814

915
useEffect(() => {
16+
if(!userId) {
17+
return
18+
}
1019
async function fetchUser() {
11-
const userId = match.params.userId;
1220
try {
1321
const userDataRes = await api.users.getOne(userId)
1422
setUser(userDataRes)
@@ -17,15 +25,20 @@ const UserEditor = ({ match }) => {
1725
}
1826
}
1927
fetchUser()
20-
}, [])
28+
}, [userId])
2129

2230
return (
23-
<>
24-
UserEditor
25-
</>
31+
<BasePageContainer>
32+
<BasePageToolbar title={'Edit user'}></BasePageToolbar>
33+
<Grid container spacing={3}>
34+
UserEditor
35+
</Grid>
36+
</BasePageContainer>
2637
)
2738
}
2839

29-
UserEditor.propTypes = {}
40+
UserEditor.propTypes = {
41+
userId: PropTypes.number
42+
}
3043

3144
export default UserEditor

0 commit comments

Comments
 (0)