File tree Expand file tree Collapse file tree 2 files changed +29
-9
lines changed Expand file tree Collapse file tree 2 files changed +29
-9
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,14 @@ const Administration = ({ match }) => {
8
8
return (
9
9
< >
10
10
< 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
+ />
12
19
</ >
13
20
)
14
21
}
Original file line number Diff line number Diff line change @@ -3,12 +3,20 @@ import PropTypes from 'prop-types'
3
3
4
4
import api from '@/_api'
5
5
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 ( { } )
8
14
9
15
useEffect ( ( ) => {
16
+ if ( ! userId ) {
17
+ return
18
+ }
10
19
async function fetchUser ( ) {
11
- const userId = match . params . userId ;
12
20
try {
13
21
const userDataRes = await api . users . getOne ( userId )
14
22
setUser ( userDataRes )
@@ -17,15 +25,20 @@ const UserEditor = ({ match }) => {
17
25
}
18
26
}
19
27
fetchUser ( )
20
- } , [ ] )
28
+ } , [ userId ] )
21
29
22
30
return (
23
- < >
24
- UserEditor
25
- </ >
31
+ < BasePageContainer >
32
+ < BasePageToolbar title = { 'Edit user' } > </ BasePageToolbar >
33
+ < Grid container spacing = { 3 } >
34
+ UserEditor
35
+ </ Grid >
36
+ </ BasePageContainer >
26
37
)
27
38
}
28
39
29
- UserEditor . propTypes = { }
40
+ UserEditor . propTypes = {
41
+ userId : PropTypes . number
42
+ }
30
43
31
44
export default UserEditor
You can’t perform that action at this time.
0 commit comments