gab-social/app/javascript/gabsocial/components/popover/group_options_popover.js

103 lines
2.7 KiB
JavaScript
Raw Normal View History

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-05-07 06:55:24 +01:00
import {
MODAL_GROUP_CREATE,
MODAL_GROUP_MEMBERS,
MODAL_GROUP_REMOVED_ACCOUNTS,
} from '../../constants'
2020-05-01 06:50:27 +01:00
import { openModal } from '../../actions/modal'
2020-05-07 06:55:24 +01:00
import { closePopover } from '../../actions/popover'
import { me } from '../../initial_state'
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'
const messages = defineMessages({
2020-05-07 06:55:24 +01:00
groupMembers: { id: 'group_members', defaultMessage: 'Group members' },
removedMembers: { id: 'group_removed_members', defaultMessage: 'Removed accounts' },
editGroup: { id: 'edit_group', defaultMessage: 'Edit group' },
2020-05-01 06:50:27 +01:00
});
2020-05-07 06:55:24 +01:00
const mapDispatchToProps = (dispatch) => ({
onOpenEditGroup(groupId) {
2020-05-07 06:55:24 +01:00
dispatch(closePopover())
dispatch(openModal(MODAL_GROUP_CREATE, { groupId }))
2020-05-01 06:50:27 +01:00
},
2020-05-07 06:55:24 +01:00
onOpenRemovedMembers(groupId) {
dispatch(closePopover())
dispatch(openModal(MODAL_GROUP_REMOVED_ACCOUNTS, { groupId }))
},
2020-05-01 06:50:27 +01:00
2020-05-07 06:55:24 +01:00
onOpenGroupMembers(groupId) {
dispatch(closePopover())
dispatch(openModal(MODAL_GROUP_MEMBERS, { groupId }))
2020-05-01 06:50:27 +01:00
},
2020-05-07 06:55:24 +01:00
});
2020-05-01 06:50:27 +01:00
export default
@injectIntl
@connect(null, mapDispatchToProps)
class GroupOptionsPopover extends ImmutablePureComponent {
static defaultProps = {
intl: PropTypes.object.isRequired,
2020-05-07 06:55:24 +01:00
group: ImmutablePropTypes.map.isRequired,
onOpenEditGroup: PropTypes.func.isRequired,
onOpenRemovedMembers: PropTypes.func.isRequired,
onOpenGroupMembers: PropTypes.func.isRequired,
isXS: PropTypes.bool,
2020-05-01 06:50:27 +01:00
}
2020-05-07 06:55:24 +01:00
updateOnProps = ['group']
2020-05-01 06:50:27 +01:00
2020-05-07 06:55:24 +01:00
handleEditGroup = () => {
this.props.onOpenEditGroup(this.props.group.get('id'))
2020-05-01 06:50:27 +01:00
}
2020-05-07 06:55:24 +01:00
handleOnOpenRemovedMembers = () => {
this.props.onOpenRemovedMembers(this.props.group.get('id'))
}
handleOnOpenGroupMembers = () => {
this.props.onOpenGroupMembers(this.props.group.get('id'))
2020-05-01 06:50:27 +01:00
}
2020-04-28 06:33:58 +01:00
render() {
const { intl, isXS } = this.props
2020-05-01 06:50:27 +01:00
const listItems = [
{
hideArrow: true,
2020-05-07 06:55:24 +01:00
icon: 'group',
title: intl.formatMessage(messages.groupMembers),
onClick: this.handleOnOpenGroupMembers,
},
{
hideArrow: true,
icon: 'block',
title: intl.formatMessage(messages.removedMembers),
onClick: this.handleOnOpenRemovedMembers,
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),
onClick: this.handleEditGroup,
2020-05-01 06:50:27 +01:00
}
]
2020-04-28 06:33:58 +01:00
return (
<PopoverLayout width={210} isXS={isXS}>
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}
size='large'
/>
2020-04-28 06:33:58 +01:00
</PopoverLayout>
)
}
2020-05-01 06:50:27 +01:00
2020-04-28 06:33:58 +01:00
}