2018-10-03 10:11:44 -07:00
|
|
|
import React from 'react';
|
2018-10-30 07:40:21 -07:00
|
|
|
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';
|
2018-10-03 10:11:44 -07:00
|
|
|
import UserAvatar from 'components/UserAvatar';
|
2018-10-04 21:27:02 -07:00
|
|
|
import { SOCIAL_INFO, socialAccountToUrl } from 'utils/social';
|
2018-10-03 10:11:44 -07:00
|
|
|
import ShortAddress from 'components/ShortAddress';
|
2018-10-30 07:40:21 -07:00
|
|
|
import './ProfileUser.less';
|
|
|
|
import { AppState } from 'store/reducers';
|
2018-10-03 10:11:44 -07:00
|
|
|
|
|
|
|
interface OwnProps {
|
2018-10-30 07:40:21 -07:00
|
|
|
user: UserState;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface StateProps {
|
|
|
|
authUser: AppState['auth']['user'];
|
|
|
|
}
|
|
|
|
|
|
|
|
interface DispatchProps {
|
|
|
|
updateUser: typeof usersActions['updateUser'];
|
|
|
|
}
|
|
|
|
|
|
|
|
interface State {
|
|
|
|
isEditing: boolean;
|
2018-10-03 10:11:44 -07:00
|
|
|
}
|
|
|
|
|
2018-10-30 07:40:21 -07:00
|
|
|
type Props = OwnProps & StateProps & DispatchProps;
|
|
|
|
|
|
|
|
class ProfileUser extends React.Component<Props> {
|
|
|
|
state: State = {
|
|
|
|
isEditing: false,
|
|
|
|
};
|
|
|
|
|
2018-10-03 10:11:44 -07:00
|
|
|
render() {
|
|
|
|
const {
|
2018-10-30 07:40:21 -07:00
|
|
|
authUser,
|
2018-10-03 10:11:44 -07:00
|
|
|
user,
|
|
|
|
user: { socialAccounts },
|
|
|
|
} = this.props;
|
2018-10-30 07:40:21 -07:00
|
|
|
|
|
|
|
const isSelf = !!authUser && authUser.ethAddress === user.ethAddress;
|
|
|
|
|
|
|
|
if (this.state.isEditing) {
|
|
|
|
return (
|
|
|
|
<ProfileEdit
|
|
|
|
user={user}
|
|
|
|
onDone={() => this.setState({ isEditing: false })}
|
|
|
|
onEdit={this.props.updateUser}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-10-03 10:11:44 -07:00
|
|
|
return (
|
|
|
|
<div className="ProfileUser">
|
|
|
|
<div className="ProfileUser-avatar">
|
|
|
|
<UserAvatar className="ProfileUser-avatar-img" user={user} />
|
|
|
|
</div>
|
|
|
|
<div className="ProfileUser-info">
|
|
|
|
<div className="ProfileUser-info-name">{user.name}</div>
|
|
|
|
<div className="ProfileUser-info-title">{user.title}</div>
|
|
|
|
<div>
|
|
|
|
{user.emailAddress && (
|
|
|
|
<div className="ProfileUser-info-address">
|
|
|
|
<span>email address</span>
|
|
|
|
{user.emailAddress}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{user.ethAddress && (
|
|
|
|
<div className="ProfileUser-info-address">
|
|
|
|
<span>ethereum address</span>
|
|
|
|
<ShortAddress address={user.ethAddress} />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
2018-10-30 07:40:21 -07:00
|
|
|
{Object.keys(socialAccounts).length > 0 && (
|
|
|
|
<div className="ProfileUser-info-social">
|
|
|
|
{typedKeys(SOCIAL_INFO).map(
|
|
|
|
s =>
|
|
|
|
(socialAccounts[s] && (
|
|
|
|
<Social
|
|
|
|
key={s}
|
|
|
|
account={socialAccounts[s] as string}
|
|
|
|
info={SOCIAL_INFO[s]}
|
|
|
|
/>
|
|
|
|
)) ||
|
|
|
|
null,
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{isSelf && (
|
|
|
|
<div>
|
|
|
|
<Button onClick={() => this.setState({ isEditing: true })}>
|
|
|
|
Edit profile
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
)}
|
2018-10-03 10:11:44 -07:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const Social = ({ account, info }: { account: string; info: SocialInfo }) => {
|
|
|
|
return (
|
|
|
|
<a href={socialAccountToUrl(account, info.type)}>
|
|
|
|
<div className="ProfileUser-info-social-icon">{info.icon}</div>
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
};
|
2018-10-30 07:40:21 -07:00
|
|
|
|
|
|
|
const connectedProfileUser = connect<StateProps, DispatchProps, {}, AppState>(
|
|
|
|
state => ({
|
|
|
|
authUser: state.auth.user,
|
|
|
|
}),
|
|
|
|
{
|
|
|
|
updateUser: usersActions.updateUser,
|
|
|
|
},
|
|
|
|
)(ProfileUser);
|
|
|
|
|
|
|
|
export default connectedProfileUser;
|