108 lines
2.7 KiB
JavaScript
Raw Normal View History

2020-04-01 23:17:21 -04:00
import { me } from '../initial_state'
2020-04-11 18:29:19 -04:00
import { defineMessages, injectIntl } from 'react-intl'
2020-03-24 23:08:43 -04:00
import { openModal } from '../actions/modal'
2020-05-07 00:03:34 -04:00
import {
MODAL_GROUP_CREATE,
MODAL_PRO_UPGRADE,
} from '../constants'
2020-04-11 18:29:19 -04:00
import PageTitle from '../features/ui/util/page_title'
2020-02-22 18:26:23 -05:00
import LinkFooter from '../components/link_footer'
import GroupsPanel from '../components/panel/groups_panel'
2020-03-24 23:08:43 -04:00
import WhoToFollowPanel from '../components/panel/who_to_follow_panel'
2020-02-24 16:56:07 -05:00
import DefaultLayout from '../layouts/default_layout'
2020-02-22 18:26:23 -05:00
2020-04-11 18:29:19 -04:00
const messages = defineMessages({
groups: { id: 'groups', defaultMessage: 'Groups' },
featured: { id: 'featured', defaultMessage: 'Featured' },
2020-04-29 18:32:49 -04:00
new: { id: 'new', defaultMessage: 'Just Added' },
2020-04-11 18:29:19 -04:00
myGroups: { id: 'my_groups', defaultMessage: 'My Groups' },
admin: { id: 'admin', defaultMessage: 'Admin' },
})
2020-04-01 23:17:21 -04:00
2020-04-11 18:29:19 -04:00
const mapStateToProps = (state) => ({
isPro: state.getIn(['accounts', me, 'is_pro']),
})
2020-03-24 23:08:43 -04:00
2020-04-11 18:29:19 -04:00
const mapDispatchToProps = (dispatch) => ({
2020-05-07 00:03:34 -04:00
onOpenGroupCreateModal(isPro) {
if (!isPro) {
dispatch(openModal(MODAL_PRO_UPGRADE))
} else {
dispatch(openModal(MODAL_GROUP_CREATE))
}
2020-03-24 23:08:43 -04:00
},
})
export default
2020-04-11 18:29:19 -04:00
@injectIntl
2020-04-01 23:17:21 -04:00
@connect(mapStateToProps, mapDispatchToProps)
2020-03-24 23:08:43 -04:00
class GroupsPage extends PureComponent {
static propTypes = {
2020-04-11 18:29:19 -04:00
intl: PropTypes.object.isRequired,
children: PropTypes.node.isRequired,
2020-04-01 23:17:21 -04:00
isPro: PropTypes.bool,
2020-03-24 23:08:43 -04:00
onOpenGroupCreateModal: PropTypes.func.isRequired,
}
2020-02-22 18:26:23 -05:00
2020-05-07 00:03:34 -04:00
handleOnOpenGroupCreateModal = () => {
this.props.onOpenGroupCreateModal(this.props.isPro)
}
2020-02-22 18:26:23 -05:00
render() {
2020-04-11 18:29:19 -04:00
const {
intl,
children,
isPro,
onOpenGroupCreateModal,
} = this.props
2020-02-22 18:26:23 -05:00
2020-05-07 00:03:34 -04:00
const actions = [
{
icon: 'add',
onClick: this.handleOnOpenGroupCreateModal,
},
]
const tabs = !!me ? [
2020-02-22 18:26:23 -05:00
{
2020-04-29 18:32:49 -04:00
title: intl.formatMessage(messages.featured),
2020-04-07 21:06:59 -04:00
to: '/groups',
2020-02-22 18:26:23 -05:00
},
2020-03-05 10:44:17 -05:00
{
2020-04-11 18:29:19 -04:00
title: intl.formatMessage(messages.new),
2020-04-07 21:06:59 -04:00
to: '/groups/new',
2020-03-05 10:44:17 -05:00
},
2020-02-22 18:26:23 -05:00
{
2020-04-11 18:29:19 -04:00
title: intl.formatMessage(messages.myGroups),
2020-04-07 21:06:59 -04:00
to: '/groups/browse/member',
2020-02-22 18:26:23 -05:00
},
] : []
2020-04-01 23:17:21 -04:00
if (isPro) {
tabs.push({
2020-04-11 18:29:19 -04:00
title: intl.formatMessage(messages.admin),
2020-04-07 21:06:59 -04:00
to: '/groups/browse/admin',
2020-04-01 23:17:21 -04:00
})
}
2020-02-22 18:26:23 -05:00
2020-04-11 18:29:19 -04:00
const title = intl.formatMessage(messages.groups)
2020-02-22 18:26:23 -05:00
return (
<DefaultLayout
2020-04-11 18:29:19 -04:00
title={title}
2020-04-01 23:17:21 -04:00
actions={actions}
2020-04-28 01:33:58 -04:00
tabs={tabs}
page='groups'
layout={[
<WhoToFollowPanel key='groups-page-wtf-panel' />,
<GroupsPanel slim key='groups-page-groups-panel' />,
<LinkFooter key='groups-page-link-footer' />,
]}
2020-02-22 18:26:23 -05:00
>
2020-04-11 18:29:19 -04:00
<PageTitle path={title} />
2020-02-22 18:26:23 -05:00
{ children }
</DefaultLayout>
)
}
2020-04-07 21:06:59 -04:00
2020-02-22 18:26:23 -05:00
}