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