File size: 2,028 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
// @flow
import React from 'react';
import compose from 'recompose/compose';
import type { Dispatch } from 'redux';
import { connect } from 'react-redux';
import type { CommunityInfoType } from 'shared/graphql/fragments/community/communityInfo';
import { openModal } from 'src/actions/modals';
import Icon from 'src/components/icon';
import {
  SidebarSectionHeader,
  SidebarSectionHeading,
  List,
  ListItem,
  ListItemLink,
  ListItemLabel,
  ListItemContent,
  NameWarn,
} from '../style';

type Props = {
  dispatch: Dispatch<Object>,
  community: CommunityInfoType,
};

const Component = (props: Props) => {
  const { community, dispatch } = props;
  const { communityPermissions } = community;
  const { isMember, isOwner, isModerator } = communityPermissions;
  const isTeamMember = isOwner || isModerator;

  const leaveCommunity = () =>
    dispatch(
      openModal('DELETE_DOUBLE_CHECK_MODAL', {
        id: community.id,
        entity: 'team-member-leaving-community',
        message: 'Are you sure you want to leave this community?',
        buttonLabel: 'Leave Community',
      })
    );

  if (!isMember && !isOwner && !isModerator) return null;

  return (
    <React.Fragment>
      <SidebarSectionHeader>
        <SidebarSectionHeading>More</SidebarSectionHeading>
      </SidebarSectionHeader>

      <List>
        {isTeamMember && (
          <ListItemLink to={`/${community.slug}/settings`}>
            <ListItemContent>
              <ListItemLabel>Community settings</ListItemLabel>
            </ListItemContent>
            <Icon glyph="view-forward" size={24} />
          </ListItemLink>
        )}

        {!isOwner && isMember && (
          <ListItem onClick={leaveCommunity}>
            <ListItemContent>
              <NameWarn>Leave community</NameWarn>
            </ListItemContent>
            <Icon glyph="door-leave" size={24} />
          </ListItem>
        )}
      </List>
    </React.Fragment>
  );
};

export const MobileCommunityInfoActions = compose(connect())(Component);