Personal Dashboard

UserInfo.jsx 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import React from 'react'
  2. import { connect } from 'react-redux'
  3. import FontAwesome from 'react-fontawesome'
  4. import firebase from 'firebase'
  5. import { EditableText, Button, Intent } from "@blueprintjs/core"
  6. import { Card } from '../../Shared/Components'
  7. import AppToaster from '../../Shared/Toaster'
  8. const SocialLink = ({ iconName, ...otherProps }) => <h4><FontAwesome name={iconName} /><EditableText {...otherProps}/></h4>
  9. const UserInfoTemplate = ({ user, changeProfile, changeEmail, save }) =>
  10. <Card className="profile-info">
  11. <h3><EditableText placeholder="Display Name" value={user.displayName}
  12. onChange={value => changeProfile({ displayName: value})}/></h3>
  13. <h3><EditableText placeholder="Email" value={user.email}
  14. onChange={value => changeEmail(value)}/></h3>
  15. <div className="social-columns">
  16. <SocialLink iconName="twitter" placeholder="Twitter" />
  17. <SocialLink iconName="facebook" placeholder="Facebook"/>
  18. <SocialLink iconName="linkedin" placeholder="LinkedIn"/>
  19. <SocialLink iconName="stack-overflow" placeholder="StackOverflow"/>
  20. <SocialLink iconName="github" placeholder="Github"/>
  21. <SocialLink iconName="globe" placeholder="Website"/>
  22. </div>
  23. <div className="actions">
  24. <Button onClick={save} intent={Intent.PRIMARY}>Save</Button>
  25. </div>
  26. </Card>
  27. class UserInfoContainer extends React.Component {
  28. state = { user: this.props.user }
  29. changeEmail = email => this.setState({ user: {...this.state.user, email } })
  30. changeProfile = profile => this.setState({ user: {...this.state.user, ...profile } })
  31. save = () => {
  32. if (this.state.user.email != this.props.user.email)
  33. firebase.auth().currentUser.updateEmail(this.state.user.email)
  34. .then(AppToaster.show({ message: 'Email updated'}))
  35. if (this.state.user.displayName != this.props.user.displayName)
  36. firebase.auth().currentUser.updateProfile({ displayName: this.state.user.displayName })
  37. .then(AppToaster.show({ message: 'Display name updated'}))
  38. }
  39. render() {
  40. return <UserInfoTemplate user={this.state.user} save={this.save}
  41. changeEmail={this.changeEmail} changeProfile={this.changeProfile}
  42. />
  43. }
  44. }
  45. const UserInfo = connect(state => ({ user: state.user }))(UserInfoContainer)
  46. export default UserInfo