File size: 2,462 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
// @flow
import React, { Component } from 'react';
import compose from 'recompose/compose';
import { connect } from 'react-redux';
import { withRouter } from 'react-router';
import AvatarImage from 'src/components/avatar/image';
import { Link } from 'react-router-dom';
import { Button, OutlineButton } from 'src/components/button';
import type { GetCommunityType } from 'shared/graphql/queries/community/getCommunity';
import renderTextWithLinks from 'src/helpers/render-text-with-markdown-links';
import type { Dispatch } from 'redux';
import { withCurrentUser } from 'src/components/withCurrentUser';
import {
  HoverWrapper,
  ProfileCard,
  CoverContainer,
  CoverPhoto,
  ProfilePhotoContainer,
  Content,
  Title,
  Description,
  Actions,
} from './style';

type ProfileProps = {
  community: GetCommunityType,
  dispatch: Dispatch<Object>,
  currentUser: ?Object,
  ref: (?HTMLElement) => void,
  style: CSSStyleDeclaration,
};

class HoverProfile extends Component<ProfileProps> {
  render() {
    const { community, ref, style } = this.props;

    const { communityPermissions } = community;
    const { isOwner, isModerator } = communityPermissions;

    return (
      <HoverWrapper popperStyle={style} ref={ref}>
        <ProfileCard>
          <Link to={`/${community.slug}`}>
            <CoverContainer>
              <CoverPhoto src={community.coverPhoto} />
              <ProfilePhotoContainer>
                <AvatarImage
                  src={community.profilePhoto}
                  type={'community'}
                  size={40}
                  isClickable={false}
                  alt={community.name}
                />
              </ProfilePhotoContainer>
            </CoverContainer>
          </Link>

          <Content>
            <Link to={`/${community.slug}`}>
              <Title>{community.name}</Title>
            </Link>
            {community.description && (
              <Description>
                {renderTextWithLinks(community.description)}
              </Description>
            )}
          </Content>

          <Actions>
            {(isModerator || isOwner) && (
              <Link to={`/${community.slug}/settings`}>
                <OutlineButton icon={'settings'}>Settings</OutlineButton>
              </Link>
            )}
          </Actions>
        </ProfileCard>
      </HoverWrapper>
    );
  }
}

export default compose(
  withCurrentUser,
  withRouter,
  connect()
)(HoverProfile);