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-05-01 06:50:27 +01:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component'
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes'
|
|
|
|
import { defineMessages, injectIntl } from 'react-intl'
|
2020-12-30 17:26:55 +00:00
|
|
|
import { isStaff } from '../../initial_state'
|
2020-07-22 04:24:26 +01:00
|
|
|
import {
|
|
|
|
addShortcut,
|
|
|
|
removeShortcut,
|
|
|
|
} from '../../actions/shortcuts'
|
2020-12-24 18:27:55 +00:00
|
|
|
import {
|
|
|
|
openPopover,
|
|
|
|
closePopover,
|
|
|
|
} from '../../actions/popover'
|
|
|
|
import { POPOVER_SHARE } from '../../constants'
|
2020-04-28 06:33:58 +01:00
|
|
|
import PopoverLayout from './popover_layout'
|
2020-05-01 06:50:27 +01:00
|
|
|
import List from '../list'
|
|
|
|
|
|
|
|
class GroupOptionsPopover extends ImmutablePureComponent {
|
|
|
|
|
2020-07-06 21:13:44 +01:00
|
|
|
handleOnClosePopover = () => {
|
|
|
|
this.props.onClosePopover()
|
|
|
|
}
|
|
|
|
|
2020-07-22 04:24:26 +01:00
|
|
|
handleOnToggleShortcut = () => {
|
|
|
|
this.handleOnClosePopover()
|
|
|
|
if (this.props.isShortcut) {
|
|
|
|
this.props.onRemoveShortcut(this.props.group.get('id'))
|
|
|
|
} else {
|
|
|
|
this.props.onAddShortcut(this.props.group.get('id'))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-24 18:27:55 +00:00
|
|
|
handleOnShare = () => {
|
|
|
|
this.props.onShare(this.props.group)
|
|
|
|
}
|
|
|
|
|
2020-04-28 06:33:58 +01:00
|
|
|
render() {
|
2020-07-22 04:24:26 +01:00
|
|
|
const {
|
2020-08-06 06:03:41 +01:00
|
|
|
group,
|
2020-07-22 04:24:26 +01:00
|
|
|
intl,
|
|
|
|
isAdmin,
|
|
|
|
isShortcut,
|
|
|
|
isXS,
|
|
|
|
} = this.props
|
2020-05-01 06:50:27 +01:00
|
|
|
|
2020-08-06 06:03:41 +01:00
|
|
|
if (!group) return <div/>
|
|
|
|
|
|
|
|
const groupId = group.get('id')
|
|
|
|
|
2020-08-08 19:21:18 +01:00
|
|
|
const listItems = []
|
|
|
|
if (isAdmin) {
|
|
|
|
listItems.push({
|
2020-05-01 06:50:27 +01:00
|
|
|
hideArrow: true,
|
2020-05-07 06:55:24 +01:00
|
|
|
icon: 'group',
|
|
|
|
title: intl.formatMessage(messages.groupMembers),
|
2020-08-06 06:03:41 +01:00
|
|
|
onClick: this.handleOnClosePopover,
|
|
|
|
to: `/groups/${groupId}/members`,
|
2020-07-22 04:24:26 +01:00
|
|
|
isHidden: !isAdmin,
|
2020-08-08 19:21:18 +01:00
|
|
|
})
|
|
|
|
listItems.push({
|
2020-05-07 06:55:24 +01:00
|
|
|
hideArrow: true,
|
|
|
|
icon: 'block',
|
|
|
|
title: intl.formatMessage(messages.removedMembers),
|
2020-08-06 06:03:41 +01:00
|
|
|
onClick: this.handleOnClosePopover,
|
|
|
|
to: `/groups/${groupId}/removed-accounts`,
|
2020-07-22 04:24:26 +01:00
|
|
|
isHidden: !isAdmin,
|
2020-08-08 19:21:18 +01:00
|
|
|
})
|
|
|
|
listItems.push({
|
2020-05-01 06:50:27 +01:00
|
|
|
hideArrow: true,
|
|
|
|
icon: 'pencil',
|
2020-05-07 06:55:24 +01:00
|
|
|
title: intl.formatMessage(messages.editGroup),
|
2020-08-06 06:03:41 +01:00
|
|
|
onClick: this.handleOnClosePopover,
|
|
|
|
to: `/groups/${groupId}/edit`,
|
2020-07-22 04:24:26 +01:00
|
|
|
isHidden: !isAdmin,
|
2020-08-08 19:21:18 +01:00
|
|
|
})
|
2020-12-24 18:27:55 +00:00
|
|
|
listItems.push({})
|
2020-08-08 19:21:18 +01:00
|
|
|
}
|
|
|
|
|
2020-12-24 18:27:55 +00:00
|
|
|
listItems.push({
|
|
|
|
hideArrow: true,
|
|
|
|
icon: 'share',
|
|
|
|
title: 'Share group',
|
|
|
|
onClick: this.handleOnShare,
|
|
|
|
})
|
|
|
|
listItems.push({})
|
2020-08-08 19:21:18 +01:00
|
|
|
listItems.push({
|
|
|
|
hideArrow: true,
|
|
|
|
icon: 'star',
|
|
|
|
title: intl.formatMessage(isShortcut ? messages.remove_from_shortcuts : messages.add_to_shortcuts),
|
|
|
|
onClick: this.handleOnToggleShortcut,
|
|
|
|
})
|
2020-05-01 06:50:27 +01:00
|
|
|
|
2020-12-30 17:26:55 +00:00
|
|
|
if (isStaff) {
|
|
|
|
listItems.push({})
|
|
|
|
listItems.push({
|
|
|
|
title: intl.formatMessage(messages.open_in_admin, { name: group.getIn('title') }),
|
|
|
|
href: `/admin/groups/${groupId}`
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-04-28 06:33:58 +01:00
|
|
|
return (
|
2020-07-06 21:13:44 +01:00
|
|
|
<PopoverLayout
|
2020-07-22 04:24:26 +01:00
|
|
|
width={240}
|
2020-07-06 21:13:44 +01:00
|
|
|
isXS={isXS}
|
|
|
|
onClose={this.handleOnClosePopover}
|
|
|
|
>
|
2020-05-01 06:50:27 +01:00
|
|
|
<List
|
2020-05-07 06:55:24 +01:00
|
|
|
scrollKey='group_options'
|
2020-05-01 06:50:27 +01:00
|
|
|
items={listItems}
|
2020-07-25 00:54:44 +01:00
|
|
|
size={isXS ? 'large' : 'small'}
|
2020-05-01 06:50:27 +01:00
|
|
|
/>
|
2020-04-28 06:33:58 +01:00
|
|
|
</PopoverLayout>
|
|
|
|
)
|
|
|
|
}
|
2020-05-01 06:50:27 +01:00
|
|
|
|
2020-08-19 01:22:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
groupMembers: { id: 'group_members', defaultMessage: 'Group members' },
|
|
|
|
removedMembers: { id: 'group_removed_members', defaultMessage: 'Removed accounts' },
|
|
|
|
editGroup: { id: 'edit_group', defaultMessage: 'Edit group' },
|
|
|
|
add_to_shortcuts: { id: 'account.add_to_shortcuts', defaultMessage: 'Add to shortcuts' },
|
|
|
|
remove_from_shortcuts: { id: 'account.remove_from_shortcuts', defaultMessage: 'Remove from shortcuts' },
|
2020-12-30 17:26:55 +00:00
|
|
|
open_in_admin: { id: 'status.admin_account', defaultMessage: 'Open moderation interface for @{name}' },
|
2020-08-19 01:22:15 +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-12-24 18:27:55 +00:00
|
|
|
const mapDispatchToProps = (dispatch, { innerRef }) => ({
|
2020-08-19 01:22:15 +01:00
|
|
|
onClosePopover: () => dispatch(closePopover()),
|
|
|
|
onAddShortcut(groupId) {
|
|
|
|
dispatch(addShortcut('group', groupId))
|
|
|
|
},
|
|
|
|
onRemoveShortcut(groupId) {
|
|
|
|
dispatch(removeShortcut(null, 'group', groupId))
|
|
|
|
},
|
2020-12-24 18:27:55 +00:00
|
|
|
onShare(group) {
|
|
|
|
dispatch(openPopover(POPOVER_SHARE, {
|
|
|
|
innerRef,
|
|
|
|
group,
|
|
|
|
position: 'top',
|
|
|
|
}))
|
|
|
|
},
|
2020-08-19 01:22:15 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
GroupOptionsPopover.defaultProps = {
|
|
|
|
group: ImmutablePropTypes.map.isRequired,
|
|
|
|
isAdmin: PropTypes.bool,
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
isXS: PropTypes.bool,
|
|
|
|
isShortcut: PropTypes.bool,
|
|
|
|
onAddShortcut: PropTypes.func.isRequired,
|
|
|
|
onRemoveShortcut: PropTypes.func.isRequired,
|
|
|
|
onClosePopover: PropTypes.func.isRequired,
|
|
|
|
}
|
|
|
|
|
|
|
|
export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(GroupOptionsPopover))
|