-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(edit profile): users can edit their profiles
- enables users to edit their profiles [Delivers #161820823]
- Loading branch information
Showing
12 changed files
with
371 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
import EditProfileForm from './EditProfileForm'; | ||
import { updateProfile } from '../../actions/userActions'; | ||
|
||
class EditProfile extends Component { | ||
constructor(props) { | ||
super(props); | ||
const { username, bio } = this.props; | ||
this.state = { | ||
username, | ||
bio, | ||
}; | ||
} | ||
|
||
handleSubmit = event => { | ||
event.preventDefault(); | ||
const { avatar } = this.props; | ||
const { username, bio } = this.state; | ||
const profileData = { | ||
profile: { | ||
username, | ||
bio, | ||
avatar, | ||
}, | ||
}; | ||
const { updateProfile } = this.props; | ||
updateProfile(profileData); | ||
}; | ||
|
||
handleChange = event => { | ||
const { name, value } = event.target; | ||
this.setState({ [name]: value }); | ||
} | ||
|
||
render() { | ||
const { username, bio } = this.state; | ||
return ( | ||
<div> | ||
<EditProfileForm | ||
handleSubmit={this.handleSubmit} | ||
handleChange={this.handleChange} | ||
username={username} | ||
bio={bio} | ||
/> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
EditProfile.propTypes = { | ||
username: PropTypes.string, | ||
bio: PropTypes.string, | ||
avatar: PropTypes.string, | ||
updateProfile: PropTypes.func.isRequired, | ||
}; | ||
EditProfile.defaultProps = { | ||
username: '', | ||
bio: '', | ||
avatar: '', | ||
}; | ||
|
||
const mapStateToProps = state => ({ | ||
profileUpdateSuccessful: state.user.profileUpdateSuccessful, | ||
}); | ||
|
||
export { EditProfile as EditProfileTest }; | ||
export default connect(mapStateToProps, { updateProfile })(EditProfile); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const EditProfileForm = (props) => { | ||
const { | ||
username, bio, handleChange, handleSubmit, | ||
} = props; | ||
return ( | ||
<div className="container"> | ||
<div className="row"> | ||
<div className="modal fade" id="editProfileModal" role="dialog" aria-hidden="true" style={{ marginTop: 100 }}> | ||
<div className="modal-dialog" role="document"> | ||
<div className="modal-content"> | ||
<div className="modal-header"> | ||
<h5 className="modal-title" id="editProfileModal"> | ||
Personal information | ||
</h5> | ||
<button type="button" className="close" data-dismiss="modal" aria-label="Close"> | ||
<span aria-hidden="true">×</span> | ||
</button> | ||
</div> | ||
<div className="modal-body"> | ||
<form onSubmit={handleSubmit} id="edit-profile-form"> | ||
<div className="form-group"> | ||
<label className="control-label" htmlFor="username">Username</label> | ||
<div className="input-group mb-2"> | ||
<div className="input-group-prepend"> | ||
<div className="input-group-text"><i className="fa fa-user" /></div> | ||
</div> | ||
<input type="text" name="username" className="form-control" id="username" value={username} onChange={handleChange} /> | ||
</div> | ||
</div> | ||
<div className="form-group"> | ||
<label className="control-label" htmlFor="bio">Bio</label> | ||
<div className="input-group mb-2"> | ||
<textarea name="bio" className="form-control" id="bio" value={bio} onChange={handleChange} /> | ||
</div> | ||
</div> | ||
<div className="modal-footer"> | ||
<button type="button" className="btn btn-danger" data-dismiss="modal">Cancel</button> | ||
<button type="submit" className="btn btn-outline-primary">Save changes</button> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
EditProfileForm.propTypes = { | ||
username: PropTypes.string.isRequired, | ||
bio: PropTypes.string.isRequired, | ||
handleChange: PropTypes.func.isRequired, | ||
handleSubmit: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default EditProfileForm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import configureMockStore from 'redux-mock-store'; | ||
import thunk from 'redux-thunk'; | ||
import { EditProfileTest } from '../../components/profiles/EditProfile'; | ||
|
||
const middlewares = [thunk]; | ||
const mockStore = configureMockStore(middlewares); | ||
describe('EditProfile component', () => { | ||
let wrapper; | ||
const props = { | ||
username: 'testuser', | ||
bio: 'bio', | ||
avatar: 'avatar', | ||
updateProfile: jest.fn(), | ||
handleChange: jest.fn(), | ||
}; | ||
|
||
const getEvent = (name = '', value = '') => ({ | ||
preventDefault: jest.fn(), | ||
target: { | ||
name, | ||
value, | ||
}, | ||
}); | ||
|
||
beforeEach(() => { | ||
const store = mockStore({ intitialState: {} }); | ||
wrapper = shallow(<EditProfileTest {...props} store={store} />); | ||
}); | ||
|
||
it('should render correctly', () => { | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
it('should call updateProfile when handleSubmit is called', () => { | ||
wrapper.instance().handleSubmit(getEvent()); | ||
expect(props.updateProfile).toBeCalled(); | ||
}); | ||
it('should set state when handleChange event is called', () => { | ||
wrapper.instance().handleChange(getEvent('username', 'testuser')); | ||
expect(wrapper.state().username).toEqual('testuser'); | ||
}); | ||
}); |
Oops, something went wrong.