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-08-06 05:54:23 +01:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl'
|
2020-02-28 15:20:47 +00:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component'
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes'
|
2020-08-06 05:54:23 +01:00
|
|
|
import moment from 'moment-mini'
|
2020-02-28 15:20:47 +00:00
|
|
|
import { shortNumberFormat } from '../../utils/numbers'
|
|
|
|
import PanelLayout from './panel_layout'
|
2020-02-29 15:42:47 +00:00
|
|
|
import Button from '../button'
|
|
|
|
import Divider from '../divider'
|
2020-08-06 05:54:23 +01:00
|
|
|
import Heading from '../heading'
|
2020-02-29 15:42:47 +00:00
|
|
|
import Icon from '../icon'
|
|
|
|
import Text from '../text'
|
2020-08-06 05:54:23 +01:00
|
|
|
import DotTextSeperator from '../dot_text_seperator'
|
|
|
|
import ProfileInfoPanelPlaceholder from '../placeholder/profile_info_panel_placeholder'
|
2020-02-28 15:20:47 +00:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
title: { id: 'about', defaultMessage: 'About' },
|
2020-02-29 15:42:47 +00:00
|
|
|
members: { id: 'members', defaultMessage: 'Members' },
|
2020-08-06 05:54:23 +01:00
|
|
|
created: { id: 'created', defaultMessage: 'Created' },
|
|
|
|
category: { id: 'category', defaultMessage: 'Category' },
|
|
|
|
tags: { id: 'tags', defaultMessage: 'Tags' },
|
|
|
|
privateGroup: { id: 'group.private', defaultMessage: 'Private' },
|
|
|
|
publicGroup: { id: 'group.public', defaultMessage: 'Public' },
|
|
|
|
visibleGroup: { id: 'group.visible', defaultMessage: 'Visible' },
|
|
|
|
invisibleGroup: { id: 'group.invisible', defaultMessage: 'Invisible' },
|
2020-02-28 15:20:47 +00:00
|
|
|
})
|
|
|
|
|
2020-08-06 05:54:23 +01:00
|
|
|
const mapStateToProps = (state, { group }) => {
|
|
|
|
const groupId = group ? group.get('id') : -1
|
|
|
|
const relationships = group === -1 ? null : state.getIn(['group_relationships', groupId])
|
|
|
|
|
|
|
|
return { relationships }
|
|
|
|
}
|
2020-05-07 06:55:24 +01:00
|
|
|
|
2020-02-28 15:20:47 +00:00
|
|
|
export default
|
|
|
|
@injectIntl
|
2020-08-06 05:54:23 +01:00
|
|
|
@connect(mapStateToProps)
|
2020-02-28 15:20:47 +00:00
|
|
|
class GroupInfoPanel extends ImmutablePureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
2020-05-07 06:55:24 +01:00
|
|
|
group: ImmutablePropTypes.map.isRequired,
|
2020-02-28 15:20:47 +00:00
|
|
|
intl: PropTypes.object.isRequired,
|
2020-05-09 03:17:19 +01:00
|
|
|
noPanel: PropTypes.bool,
|
2020-08-06 05:54:23 +01:00
|
|
|
relationships: ImmutablePropTypes.map,
|
2020-02-28 15:20:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2020-08-06 05:54:23 +01:00
|
|
|
const {
|
|
|
|
intl,
|
|
|
|
group,
|
|
|
|
noPanel,
|
|
|
|
relationships,
|
|
|
|
} = this.props
|
2020-05-09 03:17:19 +01:00
|
|
|
|
2020-08-06 05:54:23 +01:00
|
|
|
if (!group && !noPanel) {
|
|
|
|
return (
|
|
|
|
<div title={intl.formatMessage(messages.title)}>
|
|
|
|
<ProfileInfoPanelPlaceholder />
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const isAdmin = relationships ? relationships.get('admin') : false
|
|
|
|
const groupId = !!group ? group.get('id') : ''
|
|
|
|
const slug = !!group ? !!group.get('slug') ? `g/${group.get('slug')}` : undefined : undefined
|
|
|
|
const isPrivate = !!group ? group.get('is_private') : false
|
|
|
|
const isVisible = !!group ? group.get('is_visible') : false
|
|
|
|
const tags = !!group ? group.get('tags') : []
|
|
|
|
|
|
|
|
if (noPanel) {
|
|
|
|
return (
|
|
|
|
<div className={[_s.default].join(' ')}>
|
|
|
|
{
|
|
|
|
!!group &&
|
2020-08-17 21:07:16 +01:00
|
|
|
<React.Fragment>
|
2020-08-06 05:54:23 +01:00
|
|
|
<Heading isCentered>
|
|
|
|
{group.get('title')}
|
|
|
|
</Heading>
|
|
|
|
{
|
|
|
|
!!slug &&
|
|
|
|
<Text className={_s.mt5} size='small' color='secondary' align='center'>
|
|
|
|
{slug}
|
|
|
|
</Text>
|
|
|
|
}
|
|
|
|
<Text className={[_s.mt10, _s.py2].join(' ')} color='secondary' size='small' align='center'>
|
|
|
|
{group.get('description')}
|
|
|
|
</Text>
|
|
|
|
<div className={[_s.default, _s.mt10, _s.flexRow, _s.justifyContentCenter, _s.alignItemsCenter].join(' ')}>
|
|
|
|
<Text color='secondary' size='small' align='center'>
|
|
|
|
<Icon
|
|
|
|
id={isPrivate ? 'lock-filled' : 'globe'}
|
|
|
|
size='10px'
|
2020-08-17 17:56:52 +01:00
|
|
|
className={_s.colorSecondary}
|
2020-08-06 05:54:23 +01:00
|
|
|
/>
|
|
|
|
<span className={_s.ml5}>
|
|
|
|
{intl.formatMessage(isPrivate ? messages.privateGroup : messages.publicGroup)}
|
|
|
|
</span>
|
|
|
|
</Text>
|
|
|
|
<DotTextSeperator />
|
|
|
|
<Text className={_s.ml5} color='secondary' size='small' align='center'>
|
|
|
|
{shortNumberFormat(group.get('member_count'))}
|
|
|
|
|
|
|
|
{intl.formatMessage(messages.members)}
|
|
|
|
</Text>
|
|
|
|
</div>
|
2020-08-17 21:07:16 +01:00
|
|
|
</React.Fragment>
|
2020-08-06 05:54:23 +01:00
|
|
|
}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2020-02-28 15:20:47 +00:00
|
|
|
|
|
|
|
return (
|
2020-08-06 05:54:23 +01:00
|
|
|
<PanelLayout title={intl.formatMessage(messages.title)}>
|
2020-02-29 15:42:47 +00:00
|
|
|
{
|
|
|
|
!!group &&
|
2020-08-17 21:07:16 +01:00
|
|
|
<React.Fragment>
|
2020-02-29 15:42:47 +00:00
|
|
|
|
2020-08-06 05:54:23 +01:00
|
|
|
<Text className={_s.mb5}>
|
|
|
|
{group.get('description')}
|
|
|
|
</Text>
|
2020-02-29 15:42:47 +00:00
|
|
|
|
2020-04-23 07:13:29 +01:00
|
|
|
<Divider isSmall />
|
2020-02-29 15:42:47 +00:00
|
|
|
|
2020-08-06 05:54:23 +01:00
|
|
|
<GroupInfoPanelRow
|
|
|
|
title={intl.formatMessage(isPrivate ? messages.privateGroup : messages.publicGroup)}
|
|
|
|
icon={isPrivate ? 'lock-filled' : 'globe'}
|
|
|
|
>
|
|
|
|
<Button
|
|
|
|
isNarrow
|
|
|
|
backgroundColor='secondary'
|
|
|
|
color='secondary'
|
|
|
|
className={[_s.px5, _s.py2].join(' ')}
|
|
|
|
>
|
|
|
|
<Text size='small' color='inherit' className={_s.px5}>?</Text>
|
|
|
|
</Button>
|
|
|
|
</GroupInfoPanelRow>
|
2020-02-29 15:42:47 +00:00
|
|
|
|
2020-08-06 05:54:23 +01:00
|
|
|
<Divider isSmall />
|
2020-02-29 15:42:47 +00:00
|
|
|
|
2020-08-06 05:54:23 +01:00
|
|
|
<GroupInfoPanelRow
|
|
|
|
title={intl.formatMessage(isVisible ? messages.visibleGroup : messages.invisibleGroup)}
|
2020-08-17 17:40:17 +01:00
|
|
|
icon={isVisible ? 'visible' : 'hidden'}
|
2020-08-06 05:54:23 +01:00
|
|
|
>
|
|
|
|
<Button
|
|
|
|
isNarrow
|
|
|
|
backgroundColor='secondary'
|
2020-04-28 06:33:58 +01:00
|
|
|
color='secondary'
|
2020-08-06 05:54:23 +01:00
|
|
|
className={[_s.px5, _s.py2].join(' ')}
|
2020-04-28 06:33:58 +01:00
|
|
|
>
|
2020-08-06 05:54:23 +01:00
|
|
|
<Text size='small' color='inherit' className={_s.px5}>?</Text>
|
|
|
|
</Button>
|
|
|
|
</GroupInfoPanelRow>
|
|
|
|
|
|
|
|
<Divider isSmall />
|
|
|
|
|
|
|
|
<GroupInfoPanelRow title={intl.formatMessage(messages.members)} icon='group'>
|
|
|
|
<Button
|
|
|
|
isText
|
|
|
|
color={isAdmin ? 'brand' : 'primary'}
|
|
|
|
backgroundColor='none'
|
|
|
|
className={_s.mlAuto}
|
|
|
|
to={isAdmin ? `/groups/${groupId}/members` : undefined}
|
|
|
|
>
|
|
|
|
<Text color='inherit' weight={isAdmin ? 'medium' : 'normal'} size='normal' className={isAdmin ? _s.underline_onHover : undefined}>
|
|
|
|
{shortNumberFormat(group.get('member_count'))}
|
|
|
|
|
|
|
|
{intl.formatMessage(messages.members)}
|
|
|
|
</Text>
|
|
|
|
</Button>
|
|
|
|
</GroupInfoPanelRow>
|
2020-04-28 06:33:58 +01:00
|
|
|
|
|
|
|
<Divider isSmall />
|
|
|
|
|
2020-08-06 05:54:23 +01:00
|
|
|
<GroupInfoPanelRow title={intl.formatMessage(messages.category)} icon='apps'>
|
|
|
|
<Text>General</Text>
|
|
|
|
</GroupInfoPanelRow>
|
|
|
|
|
|
|
|
<Divider isSmall />
|
|
|
|
|
|
|
|
<GroupInfoPanelRow title={intl.formatMessage(messages.created)} icon='calendar'>
|
|
|
|
<Text>
|
|
|
|
{moment(group.get('created_at')).format('LL')}
|
|
|
|
</Text>
|
|
|
|
</GroupInfoPanelRow>
|
|
|
|
|
|
|
|
{
|
|
|
|
!!tags &&
|
2020-08-17 21:07:16 +01:00
|
|
|
<React.Fragment>
|
2020-08-06 05:54:23 +01:00
|
|
|
<Divider isSmall />
|
|
|
|
<GroupInfoPanelRow title={intl.formatMessage(messages.tags)} icon='shop'>
|
|
|
|
<div className={[_s.default, _s.flexRow, _s.justifyContentEnd, _s.flexWrap, _s.pl5].join(' ')}>
|
|
|
|
{
|
|
|
|
tags.map((tag) => (
|
|
|
|
<div className={[_s.mr5, _s.mb5].join(' ')}>
|
|
|
|
<Text size='small' className={[_s.bgSecondary, _s.radiusSmall, _s.px10, _s.py2, _s.lineHeight15].join(' ')}>
|
|
|
|
{tag}
|
|
|
|
</Text>
|
|
|
|
</div>
|
|
|
|
))
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
</GroupInfoPanelRow>
|
2020-08-17 21:07:16 +01:00
|
|
|
</React.Fragment>
|
2020-08-06 05:54:23 +01:00
|
|
|
}
|
|
|
|
|
2020-08-17 21:07:16 +01:00
|
|
|
</React.Fragment>
|
2020-02-29 15:42:47 +00:00
|
|
|
}
|
2020-08-06 05:54:23 +01:00
|
|
|
</PanelLayout>
|
2020-02-28 15:20:47 +00:00
|
|
|
)
|
|
|
|
}
|
2020-08-06 05:54:23 +01:00
|
|
|
}
|
|
|
|
|
2020-08-17 21:07:16 +01:00
|
|
|
class GroupInfoPanelRow extends React.PureComponent {
|
2020-08-06 05:54:23 +01:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
icon: PropTypes.string,
|
|
|
|
title: PropTypes.string.isRequired,
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { icon, title } = this.props
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={[_s.default, _s.flexRow, _s.py2].join(' ')}>
|
|
|
|
<div className={[_s.default, _s.flexRow, _s.justifyContentCenter].join(' ')}>
|
|
|
|
<Icon id={icon} size='16px' />
|
|
|
|
<Text weight='bold' size='medium' className={_s.ml10}>
|
|
|
|
{title}
|
|
|
|
</Text>
|
|
|
|
</div>
|
|
|
|
<div className={_s.mlAuto}>
|
|
|
|
{this.props.children}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-02-28 15:20:47 +00:00
|
|
|
}
|