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-04-11 23:29:19 +01:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes'
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component'
|
2020-04-29 03:24:35 +01:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl'
|
2020-09-11 23:10:31 +01:00
|
|
|
import { openPopover } from '../actions/popover'
|
2020-09-02 23:53:57 +01:00
|
|
|
import {
|
|
|
|
addShortcut,
|
|
|
|
removeShortcut,
|
|
|
|
} from '../actions/shortcuts'
|
2020-05-09 03:17:19 +01:00
|
|
|
import {
|
|
|
|
PLACEHOLDER_MISSING_HEADER_SRC,
|
|
|
|
BREAKPOINT_EXTRA_SMALL,
|
|
|
|
} from '../constants'
|
2020-07-22 05:34:44 +01:00
|
|
|
import { me } from '../initial_state'
|
2020-05-09 03:17:19 +01:00
|
|
|
import Responsive from '../features/ui/util/responsive_component'
|
2020-09-11 23:10:31 +01:00
|
|
|
import GroupActionButton from './group_action_button'
|
2020-04-11 23:29:19 +01:00
|
|
|
import Button from './button'
|
|
|
|
import Block from './block'
|
2020-08-06 05:54:23 +01:00
|
|
|
import Heading from './heading'
|
2020-04-11 23:29:19 +01:00
|
|
|
import Image from './image'
|
2020-08-06 05:54:23 +01:00
|
|
|
import Icon from './icon'
|
2020-04-11 23:29:19 +01:00
|
|
|
import TabBar from './tab_bar'
|
2020-08-06 05:54:23 +01:00
|
|
|
import Pills from './pills'
|
2020-04-11 23:29:19 +01:00
|
|
|
import Text from './text'
|
|
|
|
|
|
|
|
class GroupHeader extends ImmutablePureComponent {
|
|
|
|
|
2020-05-07 06:55:24 +01:00
|
|
|
handleOnOpenGroupOptions = () => {
|
2020-07-22 05:34:44 +01:00
|
|
|
const { relationships } = this.props
|
2020-08-08 19:21:18 +01:00
|
|
|
const isAdmin = !!relationships ? relationships.get('admin') : false
|
2020-09-02 23:53:57 +01:00
|
|
|
const isModerator = !!relationships ? relationships.get('moderator') : false
|
|
|
|
this.props.onOpenGroupOptions(this.infoBtn, this.props.group, {
|
|
|
|
isAdmin,
|
|
|
|
isModerator,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
handleToggleShortcut = () => {
|
|
|
|
const { group, isShortcut } = this.props
|
|
|
|
const groupId = !!group ? group.get('id') : null
|
|
|
|
|
|
|
|
if (!groupId) return
|
|
|
|
|
|
|
|
if (isShortcut) {
|
|
|
|
this.props.onRemoveShortcut(groupId)
|
|
|
|
} else {
|
|
|
|
this.props.onAddShortcut(groupId)
|
|
|
|
}
|
2020-05-07 06:55:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
setInfoBtn = (c) => {
|
|
|
|
this.infoBtn = c;
|
|
|
|
}
|
|
|
|
|
2020-04-11 23:29:19 +01:00
|
|
|
render() {
|
2020-04-29 03:24:35 +01:00
|
|
|
const {
|
2020-05-09 03:17:19 +01:00
|
|
|
children,
|
2020-04-29 03:24:35 +01:00
|
|
|
group,
|
|
|
|
intl,
|
2020-08-06 05:54:23 +01:00
|
|
|
isXS,
|
2020-09-02 23:53:57 +01:00
|
|
|
isShortcut,
|
2020-04-29 03:24:35 +01:00
|
|
|
relationships,
|
|
|
|
} = this.props
|
2020-04-11 23:29:19 +01:00
|
|
|
|
2020-04-29 03:24:35 +01:00
|
|
|
const coverSrc = !!group ? group.get('cover_image_url') : ''
|
|
|
|
const coverSrcMissing = coverSrc.indexOf(PLACEHOLDER_MISSING_HEADER_SRC) > -1 || !coverSrc
|
2020-04-11 23:29:19 +01:00
|
|
|
const title = !!group ? group.get('title') : undefined
|
2020-08-06 05:54:23 +01:00
|
|
|
const slug = !!group ? !!group.get('slug') ? `g/${group.get('slug')}` : undefined : undefined
|
2020-09-02 23:53:57 +01:00
|
|
|
const isPrivate = !!group ? group.get('is_private') : false
|
2020-09-11 23:10:31 +01:00
|
|
|
const isAdminOrMod = !!relationships ? (relationships.get('admin') || relationships.get('moderator')) : false
|
2020-04-29 03:24:35 +01:00
|
|
|
|
2020-08-06 05:54:23 +01:00
|
|
|
const tabs = !group ? [] : [
|
|
|
|
{
|
|
|
|
to: `/groups/${group.get('id')}`,
|
|
|
|
title: 'Timeline',
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
2020-09-02 23:53:57 +01:00
|
|
|
if (isAdminOrMod && group) {
|
2020-08-06 05:54:23 +01:00
|
|
|
tabs.push({
|
|
|
|
to: `/groups/${group.get('id')}/members`,
|
|
|
|
title: 'Members',
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-09-02 23:53:57 +01:00
|
|
|
if (isAdminOrMod && group && isPrivate) {
|
|
|
|
tabs.push({
|
|
|
|
to: `/groups/${group.get('id')}/requests`,
|
|
|
|
title: 'Requests',
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-08-06 05:54:23 +01:00
|
|
|
if (isXS && group) {
|
|
|
|
tabs.push({
|
|
|
|
to: `/groups/${group.get('id')}/about`,
|
|
|
|
title: 'About',
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-04-29 03:24:35 +01:00
|
|
|
// : todo :
|
|
|
|
// {group.get('archived') && <Icon id='lock' title={intl.formatMessage(messages.group_archived)} />}
|
|
|
|
|
2020-04-11 23:29:19 +01:00
|
|
|
return (
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.z1, _s.w100PC, _s.mb15].join(' ')}>
|
2020-05-09 03:17:19 +01:00
|
|
|
<Responsive max={BREAKPOINT_EXTRA_SMALL}>
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.boxShadowBlock, _s.bgPrimary].join(' ')}>
|
|
|
|
<div className={[_s.d, _s.w100PC].join(' ')}>
|
2020-05-09 03:17:19 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
coverSrc && !coverSrcMissing &&
|
2020-08-18 21:43:06 +01:00
|
|
|
<Image className={_s.h200PX} src={coverSrc} alt={title} />
|
2020-05-09 03:17:19 +01:00
|
|
|
}
|
|
|
|
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.w100PC].join(' ')}>
|
2020-05-09 03:17:19 +01:00
|
|
|
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.w100PC, _s.px15, _s.mt10, _s.py10].join(' ')}>
|
2020-05-09 03:17:19 +01:00
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
|
2020-08-06 05:54:23 +01:00
|
|
|
{
|
|
|
|
!!me &&
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.flexRow, _s.jcCenter, _s.aiCenter, _s.mt5, _s.pb15, _s.pt5, _s.h100PC, _s.borderBottom1PX, _s.borderColorSecondary, _s.px15].join(' ')}>
|
2020-09-11 23:10:31 +01:00
|
|
|
<GroupActionButton
|
|
|
|
group={group}
|
|
|
|
relationships={relationships}
|
|
|
|
/>
|
2020-08-06 05:54:23 +01:00
|
|
|
|
2020-06-11 04:25:08 +01:00
|
|
|
<Button
|
|
|
|
color='primary'
|
|
|
|
backgroundColor='tertiary'
|
2020-09-11 23:10:31 +01:00
|
|
|
className={[_s.px10, _s.mr5, _s.ml5].join(' ')}
|
2020-06-11 04:25:08 +01:00
|
|
|
icon='ellipsis'
|
|
|
|
onClick={this.handleOnOpenGroupOptions}
|
|
|
|
buttonRef={this.setInfoBtn}
|
|
|
|
/>
|
2020-08-06 05:54:23 +01:00
|
|
|
</div>
|
|
|
|
}
|
2020-05-09 03:17:19 +01:00
|
|
|
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.flexRow, _s.h100PC, _s.mt5, _s.pt10, _s.pb5, _s.mb5, _s.px10].join(' ')}>
|
2020-05-09 03:17:19 +01:00
|
|
|
|
2020-08-06 05:54:23 +01:00
|
|
|
<Pills pills={tabs} />
|
2020-05-09 03:17:19 +01:00
|
|
|
|
|
|
|
</div>
|
2020-04-11 23:29:19 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-05-09 03:17:19 +01:00
|
|
|
</Responsive>
|
|
|
|
|
|
|
|
{ /** desktop */}
|
|
|
|
<Responsive min={BREAKPOINT_EXTRA_SMALL}>
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.boxShadowBlock, _s.bgPrimary, _s.bottomLeftRadiusSmall, _s.bottomRightRadiusSmall].join(' ')}>
|
|
|
|
<div className={[_s.d, _s.w100PC].join(' ')}>
|
2020-05-09 03:17:19 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
coverSrc && !coverSrcMissing &&
|
2020-08-18 21:43:06 +01:00
|
|
|
<Image className={_s.h350PX} src={coverSrc} alt={title} />
|
2020-05-09 03:17:19 +01:00
|
|
|
}
|
2020-08-06 05:54:23 +01:00
|
|
|
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d].join(' ')}>
|
|
|
|
<div className={[_s.d, _s.flexRow, _s.py10, _s.px10].join(' ')}>
|
|
|
|
<div className={[_s.d, _s.w100PC].join(' ')}>
|
|
|
|
<div className={[_s.d, _s.flexRow].join(' ')}>
|
2020-08-06 05:54:23 +01:00
|
|
|
<Icon id='group' size='28px' />
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.ml7, _s.flexNormal].join(' ')}>
|
2020-08-06 05:54:23 +01:00
|
|
|
<Heading>
|
|
|
|
{title}
|
|
|
|
</Heading>
|
|
|
|
{
|
|
|
|
!!slug &&
|
|
|
|
<Heading size='h4'>
|
|
|
|
{slug}
|
|
|
|
</Heading>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.h53PX, _s.w100PC].join(' ')}>
|
|
|
|
<div className={[_s.d, _s.flexRow, _s.h100PC, _s.px10].join(' ')}>
|
2020-08-06 05:54:23 +01:00
|
|
|
|
|
|
|
<TabBar tabs={tabs} isLarge />
|
2020-05-09 03:17:19 +01:00
|
|
|
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.flexRow, _s.aiCenter, _s.h100PC, _s.mlAuto].join(' ')}>
|
2020-08-06 05:54:23 +01:00
|
|
|
{
|
|
|
|
!!me &&
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.flexRow, _s.jcCenter, _s.aiCenter].join(' ')}>
|
2020-08-06 05:54:23 +01:00
|
|
|
<Button
|
|
|
|
iconSize='18px'
|
|
|
|
color='brand'
|
|
|
|
backgroundColor='none'
|
|
|
|
className={[_s.mr10, _s.px10].join(' ')}
|
2020-09-02 23:53:57 +01:00
|
|
|
icon={isShortcut ? 'star' : 'star-outline'}
|
|
|
|
onClick={this.handleToggleShortcut}
|
2020-08-06 05:54:23 +01:00
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
color='primary'
|
|
|
|
backgroundColor='tertiary'
|
2020-09-02 23:53:57 +01:00
|
|
|
className={[_s.mr15, _s.px10].join(' ')}
|
2020-08-06 05:54:23 +01:00
|
|
|
icon='ellipsis'
|
|
|
|
onClick={this.handleOnOpenGroupOptions}
|
|
|
|
buttonRef={this.setInfoBtn}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
}
|
2020-09-11 23:10:31 +01:00
|
|
|
|
|
|
|
<GroupActionButton
|
|
|
|
group={group}
|
|
|
|
relationships={relationships}
|
|
|
|
/>
|
|
|
|
|
2020-08-06 05:54:23 +01:00
|
|
|
</div>
|
2020-05-09 03:17:19 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-08-06 05:54:23 +01:00
|
|
|
</div>
|
2020-05-09 03:17:19 +01:00
|
|
|
</Responsive>
|
2020-04-11 23:29:19 +01:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-08-18 01:57:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
removed_accounts: { id: 'groups.removed_accounts', defaultMessage: 'Removed Accounts' },
|
|
|
|
group_archived: { id: 'group.detail.archived_group', defaultMessage: 'Archived group' },
|
|
|
|
group_admin: { id: 'groups.detail.role_admin', defaultMessage: 'You\'re an admin' }
|
|
|
|
})
|
|
|
|
|
2020-09-02 23:53:57 +01:00
|
|
|
const mapStateToProps = (state, { group }) => {
|
|
|
|
const groupId = group ? group.get('id') : null
|
|
|
|
const shortcuts = state.getIn(['shortcuts', 'items'])
|
|
|
|
const isShortcut = !!shortcuts.find((s) => {
|
|
|
|
return s.get('shortcut_id') == groupId && s.get('shortcut_type') === 'group'
|
|
|
|
})
|
|
|
|
return { isShortcut }
|
|
|
|
}
|
|
|
|
|
2020-08-18 01:57:35 +01:00
|
|
|
const mapDispatchToProps = (dispatch, { intl }) => ({
|
|
|
|
|
2020-09-02 23:53:57 +01:00
|
|
|
onOpenGroupOptions(targetRef, group, options) {
|
2020-08-18 01:57:35 +01:00
|
|
|
dispatch(openPopover('GROUP_OPTIONS', {
|
|
|
|
targetRef,
|
|
|
|
group,
|
2020-09-02 23:53:57 +01:00
|
|
|
...options,
|
2020-08-18 01:57:35 +01:00
|
|
|
position: 'left',
|
|
|
|
}))
|
|
|
|
},
|
2020-09-02 23:53:57 +01:00
|
|
|
onAddShortcut(groupId) {
|
|
|
|
dispatch(addShortcut('group', groupId))
|
|
|
|
},
|
|
|
|
onRemoveShortcut(groupId) {
|
|
|
|
dispatch(removeShortcut(null, 'group', groupId))
|
|
|
|
},
|
2020-08-18 01:57:35 +01:00
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
GroupHeader.propTypes = {
|
|
|
|
group: ImmutablePropTypes.map,
|
|
|
|
children: PropTypes.any,
|
|
|
|
intl: PropTypes.object.isRequired,
|
2020-09-02 23:53:57 +01:00
|
|
|
isShortcut: PropTypes.bool.isRequired,
|
2020-08-18 01:57:35 +01:00
|
|
|
isXS: PropTypes.bool,
|
2020-09-02 23:53:57 +01:00
|
|
|
onAddShortcut: PropTypes.func.isRequired,
|
|
|
|
onRemoveShortcut: PropTypes.func.isRequired,
|
2020-08-18 01:57:35 +01:00
|
|
|
onOpenGroupOptions: PropTypes.func.isRequired,
|
|
|
|
relationships: ImmutablePropTypes.map,
|
|
|
|
}
|
|
|
|
|
2020-09-02 23:53:57 +01:00
|
|
|
export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(GroupHeader))
|