Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement followUser in RecommendedUsers component #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 72 additions & 23 deletions src/brands/peapods/lib/PeaPersonListItem.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import React from 'react';
import React, { useState } from 'react';
import PropTypes from 'prop-types';

import ListItem from '@material-ui/core/ListItem';
import ListItemText from '@material-ui/core/ListItemText';
import Popover from '@material-ui/core/Popover';

import PeaButton from './PeaButton';
import PeaAvatar from './PeaAvatar';
import PeaGroupSelector from './PeaGroupSelector';

const PeaPersonListItem = ({
src,
Expand All @@ -16,28 +19,68 @@ const PeaPersonListItem = ({
ListItemTextProps,
ButtonProps,
isButtonShown,
}) => (
<ListItem {...ListItemProps} onClick={!isButtonShown ? onClick : null}>
<PeaAvatar src={src} {...AvatarProps} />
<ListItemText
primaryTypographyProps={{ noWrap: true }}
secondaryTypographyProps={{ noWrap: true }}
primary={name}
secondary={tag}
{...ListItemTextProps}
/>
{isButtonShown && (
<PeaButton
variant={'contained'}
color={'primary'}
onClick={onClick}
{...ButtonProps}
>
Follow
</PeaButton>
)}
</ListItem>
);
followableGroups,
followLoading,
onCreateGroupClicked,
onFollow,
}) => {
const [followAnchorEl, setFollowAnchorEl] = useState(null);
const followAriaId = followAnchorEl ? 'follow-popover' : undefined;
const groupSelectorOpen = Boolean(followAnchorEl);

const onFollowBtnClick = event => {
setFollowAnchorEl(event.currentTarget);
};

const onFollowPopClose = () => {
setFollowAnchorEl(null);
};

const handleOnFollow = async groupIds => {
await onFollow(groupIds);
onFollowPopClose();
};

return (
<ListItem {...ListItemProps} onClick={!isButtonShown ? onClick : null}>
<PeaAvatar src={src} {...AvatarProps} />
<ListItemText
primaryTypographyProps={{ noWrap: true }}
secondaryTypographyProps={{ noWrap: true }}
primary={name}
secondary={tag}
{...ListItemTextProps}
/>
{isButtonShown && (
<>
<PeaButton
variant={'contained'}
color={'primary'}
onClick={onFollowBtnClick}
loading={followLoading}
{...ButtonProps}
>
Follow
</PeaButton>
<Popover
id={followAriaId}
open={groupSelectorOpen}
anchorEl={followAnchorEl}
onClose={onFollowPopClose}
>
<PeaGroupSelector
followButtonText={'Follow'}
followableGroups={followableGroups}
followLoading={followLoading}
onCreateGroupClicked={onCreateGroupClicked}
onSubmit={handleOnFollow}
/>
</Popover>
</>
)}
</ListItem>
);
};

PeaPersonListItem.propTypes = {
src: PropTypes.string.isRequired,
Expand All @@ -49,13 +92,19 @@ PeaPersonListItem.propTypes = {
ListItemTextProps: PropTypes.shape({}),
ButtonProps: PropTypes.shape({}),
isButtonShown: PropTypes.bool,
followableGroups: PropTypes.arrayOf(PropTypes.shape({})),
onCreateGroupClicked: PropTypes.func,
onFollow: PropTypes.func,
};
PeaPersonListItem.defaultProps = {
ListItemProps: {},
AvatarProps: {},
ListItemTextProps: {},
ButtonProps: {},
isButtonShown: true,
followableGroups: [],
onCreateGroupClicked: () => {},
onFollow: () => {},
};
PeaPersonListItem.metadata = {
name: 'Pea Person List Item',
Expand Down