Personal Dashboard

UserPic.jsx 1.4KB

123456789101112131415161718192021222324252627282930313233343536
  1. import React from 'react'
  2. import firebase from 'firebase'
  3. import { connect } from 'react-redux'
  4. import { Card, ProfilePic } from '../../Shared/Components'
  5. import UserPicChange from './UserPicChange'
  6. import { CHANGE_PIC } from '../../Store/Actions'
  7. import AppToaster from '../../Shared/Toaster'
  8. const UserPicTemplate = ({ pic, dialogOpen, toggleDialog, changePic }) =>
  9. <Card className="profile-pic" interactive onClick={toggleDialog}>
  10. <ProfilePic src={pic} />
  11. <UserPicChange save={changePic} cancel={toggleDialog} open={dialogOpen}/>
  12. </Card>
  13. class UserPicContainer extends React.Component {
  14. state = { dialogOpen: false }
  15. toggleDialog = () => this.setState({ dialogOpen: !this.state.dialogOpen })
  16. changePic = url => firebase.auth().currentUser.updateProfile({ photoURL: url })
  17. .then(() => this.props.updatePic(url))
  18. .then(this.toggleDialog)
  19. .then(AppToaster.show({ message: 'Picture updated'}))
  20. render() {
  21. return <UserPicTemplate pic={this.props.pic} dialogOpen={this.state.dialogOpen}
  22. toggleDialog={this.toggleDialog} changePic={this.changePic}/>
  23. }
  24. }
  25. const UserPic = connect(
  26. state => ({ pic: state.user.photoURL }),
  27. dispatch => ({ updatePic: url => dispatch(CHANGE_PIC(url)) })
  28. )(UserPicContainer)
  29. export default UserPic;