import React from 'react'; import { connect } from 'react-redux'; import { Button } from 'antd'; import { SocialInfo } from 'types'; import { usersActions } from 'modules/users'; import { UserState } from 'modules/users/reducers'; import { typedKeys } from 'utils/ts'; import ProfileEdit from './ProfileEdit'; import UserAvatar from 'components/UserAvatar'; import { SOCIAL_INFO, socialAccountToUrl } from 'utils/social'; import ShortAddress from 'components/ShortAddress'; import './ProfileUser.less'; import { AppState } from 'store/reducers'; interface OwnProps { user: UserState; } interface StateProps { authUser: AppState['auth']['user']; } interface DispatchProps { updateUser: typeof usersActions['updateUser']; } interface State { isEditing: boolean; } type Props = OwnProps & StateProps & DispatchProps; class ProfileUser extends React.Component { state: State = { isEditing: false, }; render() { const { authUser, user, user: { socialAccounts }, } = this.props; const isSelf = !!authUser && authUser.ethAddress === user.ethAddress; if (this.state.isEditing) { return ( this.setState({ isEditing: false })} onEdit={this.props.updateUser} /> ); } return (
{user.name}
{user.title}
{user.emailAddress && (
email address {user.emailAddress}
)} {user.ethAddress && (
ethereum address
)}
{Object.keys(socialAccounts).length > 0 && (
{typedKeys(SOCIAL_INFO).map( s => (socialAccounts[s] && ( )) || null, )}
)} {isSelf && (
)}
); } } const Social = ({ account, info }: { account: string; info: SocialInfo }) => { return (
{info.icon}
); }; const connectedProfileUser = connect( state => ({ authUser: state.auth.user, }), { updateUser: usersActions.updateUser, }, )(ProfileUser); export default connectedProfileUser;