2020-08-17 21:07:16 +01:00
|
|
|
import React from 'react'
|
2020-08-17 21:59:29 +01:00
|
|
|
import PropTypes from 'prop-types'
|
2020-08-17 21:39:25 +01:00
|
|
|
import { connect } from 'react-redux'
|
2020-02-22 23:26:23 +00:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes'
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component'
|
|
|
|
import { NavLink } from 'react-router-dom'
|
|
|
|
import { defineMessages, injectIntl } from 'react-intl'
|
2020-08-19 01:39:06 +01:00
|
|
|
import { PLACEHOLDER_MISSING_HEADER_SRC, CX } from '../constants'
|
2020-02-22 23:26:23 +00:00
|
|
|
import { shortNumberFormat } from '../utils/numbers'
|
2020-04-02 04:17:21 +01:00
|
|
|
import Image from './image'
|
|
|
|
import Text from './text'
|
2020-09-14 17:41:10 +01:00
|
|
|
import GroupActionButton from './group_action_button'
|
2020-02-22 23:26:23 +00:00
|
|
|
|
|
|
|
class GroupCollectionItem extends ImmutablePureComponent {
|
2020-04-08 02:06:59 +01:00
|
|
|
|
2020-02-22 23:26:23 +00:00
|
|
|
render() {
|
2020-04-28 06:33:58 +01:00
|
|
|
const {
|
|
|
|
intl,
|
|
|
|
group,
|
|
|
|
relationships,
|
|
|
|
isHidden,
|
2020-09-14 17:41:10 +01:00
|
|
|
isAddable,
|
2020-04-28 06:33:58 +01:00
|
|
|
} = this.props
|
2020-02-22 23:26:23 +00:00
|
|
|
|
|
|
|
if (!relationships) return null
|
|
|
|
|
2020-04-02 04:17:21 +01:00
|
|
|
const isMember = relationships.get('member')
|
2020-04-08 02:06:59 +01:00
|
|
|
const isAdmin = relationships.get('admin')
|
2020-09-03 00:06:38 +01:00
|
|
|
const isModerator = relationships.get('moderator')
|
2020-04-28 06:33:58 +01:00
|
|
|
const coverSrc = group.get('cover_image_url') || ''
|
|
|
|
const coverMissing = coverSrc.indexOf(PLACEHOLDER_MISSING_HEADER_SRC) > -1 || !coverSrc
|
|
|
|
|
|
|
|
if (isHidden) {
|
|
|
|
return (
|
2020-08-17 21:07:16 +01:00
|
|
|
<React.Fragment>
|
2020-04-28 06:33:58 +01:00
|
|
|
{group.get('title')}
|
|
|
|
{isMember && intl.formatMessage(messages.member)}
|
|
|
|
{isAdmin && intl.formatMessage(messages.admin)}
|
2020-09-03 00:06:38 +01:00
|
|
|
{isModerator && intl.formatMessage(messages.moderator)}
|
2020-08-17 21:07:16 +01:00
|
|
|
</React.Fragment>
|
2020-04-28 06:33:58 +01:00
|
|
|
)
|
|
|
|
}
|
2020-02-22 23:26:23 +00:00
|
|
|
|
2020-08-19 01:39:06 +01:00
|
|
|
const navLinkClasses = CX({
|
2020-08-18 21:49:11 +01:00
|
|
|
d: 1,
|
2020-02-22 23:26:23 +00:00
|
|
|
noUnderline: 1,
|
|
|
|
overflowHidden: 1,
|
|
|
|
borderColorSecondary: 1,
|
2020-04-25 18:00:51 +01:00
|
|
|
boxShadowBlock: 1,
|
2020-02-22 23:26:23 +00:00
|
|
|
radiusSmall: 1,
|
2020-04-25 18:00:51 +01:00
|
|
|
borderTop1PX: 1,
|
2020-03-11 23:56:18 +00:00
|
|
|
mb10: 1,
|
|
|
|
ml5: 1,
|
|
|
|
mr5: 1,
|
2020-04-29 23:32:49 +01:00
|
|
|
bgPrimary: 1,
|
|
|
|
bgSubtle_onHover: isMember,
|
2020-02-22 23:26:23 +00:00
|
|
|
})
|
|
|
|
|
2020-09-14 17:41:10 +01:00
|
|
|
let groupTitle = group.get('title') || ''
|
|
|
|
if (isAddable && groupTitle.length > 52) groupTitle = `${groupTitle.substring(0, 52).trim()}...`
|
|
|
|
|
2020-02-22 23:26:23 +00:00
|
|
|
return (
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={_s.d}>
|
2020-02-22 23:26:23 +00:00
|
|
|
<NavLink
|
|
|
|
to={`/groups/${group.get('id')}`}
|
|
|
|
className={navLinkClasses}
|
|
|
|
>
|
2020-04-08 02:06:59 +01:00
|
|
|
{
|
2020-04-28 06:33:58 +01:00
|
|
|
!!coverSrc && !coverMissing &&
|
2020-04-08 02:06:59 +01:00
|
|
|
<Image
|
|
|
|
src={coverSrc}
|
|
|
|
alt={group.get('title')}
|
2020-08-18 21:43:06 +01:00
|
|
|
className={_s.h158PX}
|
2020-04-08 02:06:59 +01:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2020-09-03 00:06:38 +01:00
|
|
|
(!coverSrc || coverMissing) && (isMember || isAdmin || isModerator) &&
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.h40PX, _s.bgSubtle, _s.borderColorSecondary, _s.borderBottom1PX].join(' ')} />
|
2020-04-08 02:06:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2020-09-03 00:06:38 +01:00
|
|
|
(isMember || isAdmin || isModerator) &&
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.flexRow, _s.posAbs, _s.top0, _s.right0, _s.pt10, _s.mr10].join(' ')}>
|
2020-04-08 02:06:59 +01:00
|
|
|
{
|
|
|
|
isMember &&
|
|
|
|
<Text
|
2020-04-23 07:13:29 +01:00
|
|
|
isBadge
|
2020-04-29 23:32:49 +01:00
|
|
|
className={_s.bgWhite}
|
2020-04-08 02:06:59 +01:00
|
|
|
size='extraSmall'
|
|
|
|
color='brand'
|
|
|
|
>
|
|
|
|
{intl.formatMessage(messages.member)}
|
|
|
|
</Text>
|
|
|
|
}
|
|
|
|
{
|
|
|
|
isAdmin &&
|
|
|
|
<Text
|
2020-04-23 07:13:29 +01:00
|
|
|
isBadge
|
2020-04-29 23:32:49 +01:00
|
|
|
className={[_s.bgBlack, _s.ml5].join(' ')}
|
2020-04-08 02:06:59 +01:00
|
|
|
size='extraSmall'
|
|
|
|
color='white'
|
|
|
|
>
|
|
|
|
{intl.formatMessage(messages.admin)}
|
|
|
|
</Text>
|
|
|
|
}
|
2020-09-03 00:06:38 +01:00
|
|
|
{
|
|
|
|
isModerator &&
|
|
|
|
<Text
|
|
|
|
isBadge
|
|
|
|
className={[_s.bgBlack, _s.ml5].join(' ')}
|
|
|
|
size='extraSmall'
|
|
|
|
color='white'
|
|
|
|
>
|
|
|
|
{intl.formatMessage(messages.moderator)}
|
|
|
|
</Text>
|
|
|
|
}
|
2020-04-08 02:06:59 +01:00
|
|
|
</div>
|
|
|
|
}
|
2020-04-02 04:17:21 +01:00
|
|
|
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.px10, _s.my10].join(' ')}>
|
2020-02-22 23:26:23 +00:00
|
|
|
<Text color='primary' size='medium' weight='bold'>
|
2020-09-14 17:41:10 +01:00
|
|
|
{groupTitle}
|
2020-02-22 23:26:23 +00:00
|
|
|
</Text>
|
|
|
|
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.flexRow, _s.aiCenter, _s.mt5, _s.mb5].join(' ')}>
|
2020-02-22 23:26:23 +00:00
|
|
|
<Text color='secondary' size='small'>
|
|
|
|
{shortNumberFormat(group.get('member_count'))}
|
|
|
|
|
2020-04-08 02:06:59 +01:00
|
|
|
{intl.formatMessage(messages.members)}
|
2020-02-22 23:26:23 +00:00
|
|
|
</Text>
|
|
|
|
</div>
|
2020-09-14 17:41:10 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
isAddable &&
|
|
|
|
<div className={[_s.d, _s.pt10].join(' ')}>
|
|
|
|
<GroupActionButton group={group} relationships={relationships} />
|
|
|
|
</div>
|
|
|
|
}
|
2020-02-22 23:26:23 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
</NavLink>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2020-04-08 02:06:59 +01:00
|
|
|
|
2020-08-18 01:57:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
members: { id: 'groups.card.members', defaultMessage: 'Members' },
|
|
|
|
viewGroup: { id: 'view_group', defaultMessage: 'View Group' },
|
|
|
|
member: { id: 'member', defaultMessage: 'Member' },
|
|
|
|
admin: { id: 'admin', defaultMessage: 'Admin' },
|
2020-09-03 00:06:38 +01:00
|
|
|
moderator: { id: 'moderator', defaultMessage: 'Moderator' },
|
2020-08-18 01:57:35 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
const mapStateToProps = (state, { id }) => ({
|
|
|
|
group: state.getIn(['groups', id]),
|
|
|
|
relationships: state.getIn(['group_relationships', id]),
|
|
|
|
})
|
|
|
|
|
|
|
|
GroupCollectionItem.propTypes = {
|
|
|
|
group: ImmutablePropTypes.map,
|
|
|
|
relationships: ImmutablePropTypes.map,
|
|
|
|
isHidden: PropTypes.bool,
|
2020-09-14 17:41:10 +01:00
|
|
|
isAddable: PropTypes.bool,
|
2020-08-18 01:57:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export default injectIntl(connect(mapStateToProps)(GroupCollectionItem))
|