API & Client : add a link to display user detail in admin - #15

This commit is contained in:
Sam
2020-02-08 12:36:03 +01:00
parent f1257f98a4
commit 33ed19a7e7
8 changed files with 165 additions and 98 deletions

View File

@ -0,0 +1,48 @@
import React from 'react'
import { withTranslation } from 'react-i18next'
import { connect } from 'react-redux'
import ProfileDetail from './ProfileDetail'
import { getOrUpdateData } from '../../actions'
class UserProfile extends React.Component {
componentDidMount() {
this.props.loadUser(this.props.match.params.userId)
}
componentDidUpdate(prevProps) {
if (prevProps.match.params.userId !== this.props.match.params.userId) {
this.props.loadUser(this.props.match.params.userId)
}
}
render() {
const { t, currentUser, users } = this.props
const [user] = users
return (
<div>
{user && (
<ProfileDetail
editable={currentUser.id === user.id}
t={t}
user={user}
/>
)}
</div>
)
}
}
export default withTranslation()(
connect(
state => ({
currentUser: state.user,
users: state.users.data,
}),
dispatch => ({
loadUser: userId => {
dispatch(getOrUpdateData('getData', 'users', { id: userId }))
},
})
)(UserProfile)
)