API & Client : replace id with username to fetch a user

This commit is contained in:
Sam
2020-02-08 13:09:01 +01:00
parent 33ed19a7e7
commit 2c3bc0f9bc
10 changed files with 28 additions and 49 deletions

View File

@ -7,12 +7,12 @@ import { getOrUpdateData } from '../../actions'
class UserProfile extends React.Component {
componentDidMount() {
this.props.loadUser(this.props.match.params.userId)
this.props.loadUser(this.props.match.params.userName)
}
componentDidUpdate(prevProps) {
if (prevProps.match.params.userId !== this.props.match.params.userId) {
this.props.loadUser(this.props.match.params.userId)
if (prevProps.match.params.userName !== this.props.match.params.userName) {
this.props.loadUser(this.props.match.params.userName)
}
}
@ -40,8 +40,8 @@ export default withTranslation()(
users: state.users.data,
}),
dispatch => ({
loadUser: userId => {
dispatch(getOrUpdateData('getData', 'users', { id: userId }))
loadUser: userName => {
dispatch(getOrUpdateData('getData', 'users', { username: userName }))
},
})
)(UserProfile)