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-02 04:17:21 +01:00
|
|
|
import { me } from '../initial_state'
|
2020-04-11 23:29:19 +01:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl'
|
|
|
|
import PageTitle from '../features/ui/util/page_title'
|
2020-08-07 23:59:39 +01:00
|
|
|
import Text from '../components/text'
|
2020-02-24 21:56:07 +00:00
|
|
|
import DefaultLayout from '../layouts/default_layout'
|
2020-08-07 23:59:39 +01:00
|
|
|
import GroupsCollection from '../features/groups_collection'
|
2020-08-12 23:52:46 +01:00
|
|
|
import WrappedBundle from '../features/ui/util/wrapped_bundle'
|
2020-09-02 19:06:18 +01:00
|
|
|
import { openModal } from '../actions/modal'
|
|
|
|
import { MODAL_PRO_UPGRADE } from '../constants'
|
2020-08-12 23:52:46 +01:00
|
|
|
import {
|
|
|
|
GroupsPanel,
|
|
|
|
LinkFooter,
|
|
|
|
} from '../features/ui/util/async_components'
|
2020-02-22 23:26:23 +00:00
|
|
|
|
2020-08-17 21:07:16 +01:00
|
|
|
class GroupsPage extends React.PureComponent {
|
2020-03-25 03:08:43 +00:00
|
|
|
|
2020-09-02 19:06:18 +01:00
|
|
|
handleOpenProUpgradeModal = () => {
|
|
|
|
this.props.dispatch(openModal(MODAL_PRO_UPGRADE))
|
|
|
|
}
|
|
|
|
|
2020-02-22 23:26:23 +00:00
|
|
|
render() {
|
2020-04-11 23:29:19 +01:00
|
|
|
const {
|
2020-08-07 23:59:39 +01:00
|
|
|
activeTab,
|
2020-04-11 23:29:19 +01:00
|
|
|
intl,
|
|
|
|
children,
|
|
|
|
isPro,
|
|
|
|
} = this.props
|
2020-02-22 23:26:23 +00:00
|
|
|
|
2020-08-07 23:59:39 +01:00
|
|
|
const dontShowChildren = (activeTab === 'timeline' && !me)
|
|
|
|
|
2020-07-25 03:41:50 +01:00
|
|
|
const tabs = !!me ? [
|
2020-02-22 23:26:23 +00:00
|
|
|
{
|
2020-08-08 19:08:48 +01:00
|
|
|
title: intl.formatMessage(messages.myGroupsTimeline),
|
2020-04-08 02:06:59 +01:00
|
|
|
to: '/groups',
|
2020-02-22 23:26:23 +00:00
|
|
|
},
|
|
|
|
{
|
2020-04-11 23:29:19 +01:00
|
|
|
title: intl.formatMessage(messages.myGroups),
|
2020-04-08 02:06:59 +01:00
|
|
|
to: '/groups/browse/member',
|
2020-02-22 23:26:23 +00:00
|
|
|
},
|
2020-08-06 06:13:19 +01:00
|
|
|
{
|
|
|
|
title: intl.formatMessage(messages.featured),
|
|
|
|
to: '/groups/browse/featured',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: intl.formatMessage(messages.new),
|
|
|
|
to: '/groups/browse/new',
|
|
|
|
},
|
2020-09-10 23:15:35 +01:00
|
|
|
{
|
|
|
|
title: intl.formatMessage(messages.categories),
|
|
|
|
to: '/groups/browse/categories',
|
|
|
|
},
|
2020-07-25 03:41:50 +01:00
|
|
|
] : []
|
2020-04-02 04:17:21 +01:00
|
|
|
|
|
|
|
if (isPro) {
|
|
|
|
tabs.push({
|
2020-04-11 23:29:19 +01:00
|
|
|
title: intl.formatMessage(messages.admin),
|
2020-04-08 02:06:59 +01:00
|
|
|
to: '/groups/browse/admin',
|
2020-04-02 04:17:21 +01:00
|
|
|
})
|
|
|
|
}
|
2020-02-22 23:26:23 +00:00
|
|
|
|
2020-04-11 23:29:19 +01:00
|
|
|
const title = intl.formatMessage(messages.groups)
|
2020-08-14 18:45:59 +01:00
|
|
|
|
2020-08-07 23:59:39 +01:00
|
|
|
const layout = []
|
|
|
|
if (!!me) {
|
2020-08-12 23:52:46 +01:00
|
|
|
layout.push(<WrappedBundle component={GroupsPanel} componentParams={{ groupType: 'member' }} />)
|
2020-08-07 23:59:39 +01:00
|
|
|
}
|
2020-08-12 23:52:46 +01:00
|
|
|
layout.push(LinkFooter)
|
2020-04-11 23:29:19 +01:00
|
|
|
|
2020-02-22 23:26:23 +00:00
|
|
|
return (
|
|
|
|
<DefaultLayout
|
2020-04-11 23:29:19 +01:00
|
|
|
title={title}
|
2020-08-14 18:45:59 +01:00
|
|
|
actions={[
|
|
|
|
{
|
2020-11-03 21:10:22 +00:00
|
|
|
attrTitle: 'Create',
|
2020-08-14 18:45:59 +01:00
|
|
|
icon: 'add',
|
2020-09-02 19:06:18 +01:00
|
|
|
to: isPro ? '/groups/create' : undefined,
|
|
|
|
onClick: isPro ? undefined : this.handleOpenProUpgradeModal,
|
2020-08-14 18:45:59 +01:00
|
|
|
},
|
|
|
|
]}
|
2020-04-28 06:33:58 +01:00
|
|
|
tabs={tabs}
|
2020-07-16 05:05:08 +01:00
|
|
|
page='groups'
|
2020-08-07 23:59:39 +01:00
|
|
|
layout={layout}
|
2020-02-22 23:26:23 +00:00
|
|
|
>
|
2020-04-11 23:29:19 +01:00
|
|
|
<PageTitle path={title} />
|
2020-08-07 23:59:39 +01:00
|
|
|
|
2020-08-14 18:45:59 +01:00
|
|
|
{
|
|
|
|
!dontShowChildren && children
|
|
|
|
}
|
2020-08-07 23:59:39 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
dontShowChildren &&
|
|
|
|
<GroupsCollection activeTab='featured' />
|
|
|
|
}
|
2020-02-22 23:26:23 +00:00
|
|
|
</DefaultLayout>
|
|
|
|
)
|
|
|
|
}
|
2020-04-08 02:06:59 +01:00
|
|
|
|
2020-08-06 06:13:19 +01:00
|
|
|
}
|
2020-08-14 18:45:59 +01:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
groups: { id: 'groups', defaultMessage: 'Groups' },
|
|
|
|
new: { id: 'new', defaultMessage: 'Recently Added Groups' },
|
|
|
|
featured: { id: 'featured', defaultMessage: 'Featured Groups' },
|
|
|
|
myGroupsTimeline: { id: 'my_groups_timeline', defaultMessage: 'Timeline' },
|
|
|
|
myGroups: { id: 'my_groups', defaultMessage: 'My Groups' },
|
2020-09-10 23:15:35 +01:00
|
|
|
categories: { id: 'categories', defaultMessage: 'Categories' },
|
2020-08-14 18:45:59 +01:00
|
|
|
admin: { id: 'admin', defaultMessage: 'Admin' },
|
|
|
|
})
|
|
|
|
|
|
|
|
const mapStateToProps = (state) => ({
|
|
|
|
isPro: state.getIn(['accounts', me, 'is_pro']),
|
|
|
|
})
|
|
|
|
|
|
|
|
GroupsPage.propTypes = {
|
|
|
|
activeTab: PropTypes.string.isRequired,
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
children: PropTypes.node.isRequired,
|
|
|
|
isPro: PropTypes.bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
export default injectIntl(connect(mapStateToProps)(GroupsPage))
|