Sidebar.jsx
962 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import 'common/sidebar.scss'
import axios from 'axios'
import React from 'react'
import { Menu, Avatar } from 'antd'
import Menus from './Menus'
import userImg from '../../../images/photos/user1.png'
class Sidebar extends React.Component {
constructor() {
super()
this.state = {
user: {}
}
}
componentDidMount() {
this.fetchUser()
}
render() {
return <div className="sidebar">
<div className="sidebar-user">
<Avatar icon="user" size="large" src={userImg} />
<span className="username">{this.state.user.username}</span>
</div>
<Menus user={this.state.user} />
</div>
}
async fetchUser() {
const result = await axios.get('/login/info')
if (result.status === 200) {
this.setState({
user: result.data
})
}
}
}
export default Sidebar