File size: 2,445 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// @flow
import * as React from 'react';
import { withRouter } from 'react-router';
import compose from 'recompose/compose';
import { connect } from 'react-redux';
import type { UserInfoType } from 'shared/graphql/fragments/user/userInfo';
import { UserAvatar } from 'src/components/avatar';
import Badge from 'src/components/badges';
import type { Dispatch } from 'redux';
import ConditionalWrap from 'src/components/conditionalWrap';
import {
  RowWithAvatar,
  UserAvatarContainer,
  Content,
  Label,
  Sublabel,
  Description,
  CardLink,
} from './style';

type Props = {
  userObject: UserInfoType,
  id: string,
  avatarSize?: number,
  profilePhoto?: string,
  name?: string,
  username?: ?string,
  description?: ?string,
  website?: ?string,
  badges?: Array<string>,
  isCurrentUser?: boolean,
  multiAction?: boolean,
  children?: React$Node,
  history: Object,
  dispatch: Dispatch<Object>,
  showHoverProfile?: boolean,
  isLink?: boolean,
  onClick?: (user: UserInfoType) => any,
};

// eslint-disable-next-line
const noop = (user: UserInfoType) => {};

const User = (props: Props) => {
  const {
    userObject,
    profilePhoto,
    name,
    username,
    description,
    avatarSize = 40,
    badges,
    showHoverProfile = true,
    isLink = true,
    onClick = noop,
  } = props;

  if (!userObject.username) return null;

  return (
    <ConditionalWrap
      condition={isLink}
      wrap={children => (
        <CardLink to={`/users/${userObject.username}`}>{children}</CardLink>
      )}
    >
      <RowWithAvatar onClick={() => onClick(userObject)}>
        {profilePhoto && (
          <UserAvatarContainer>
            <UserAvatar
              user={userObject}
              size={avatarSize}
              showHoverProfile={showHoverProfile}
              isClickable={false}
            />
          </UserAvatarContainer>
        )}

        <Content>
          {name && (
            <Label title={name}>
              {name}
              {badges &&
                badges.map((b, i) => (
                  <Badge style={{ marginLeft: '8px' }} key={i} type={b} />
                ))}
            </Label>
          )}

          {username && <Sublabel title={username}>@{username}</Sublabel>}

          {description && <Description>{description}</Description>}
        </Content>
      </RowWithAvatar>
    </ConditionalWrap>
  );
};

export const UserListItem = compose(
  withRouter,
  connect()
)(User);