Added promotions to redux and added selector for setting promotions if not PRO
• Added: - promotions to redux - selector for setting promotions if not PRO • Updated: - StatusList, SidebarPanelGroup to use promotions from redux
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { me, promotions } from '../initial_state'
|
||||
import { connect } from 'react-redux'
|
||||
import { me } from '../initial_state'
|
||||
import { getPromotions } from '../selectors'
|
||||
import Bundle from '../features/ui/util/bundle'
|
||||
import WrappedBundle from '../features/ui/util/wrapped_bundle'
|
||||
import {
|
||||
@@ -10,16 +12,20 @@ import {
|
||||
class SidebarPanelGroup extends React.PureComponent {
|
||||
|
||||
render() {
|
||||
const { layout, page } = this.props
|
||||
const {
|
||||
layout,
|
||||
page,
|
||||
promotions,
|
||||
} = this.props
|
||||
|
||||
if (Array.isArray(promotions) && Array.isArray(layout) && !!me) {
|
||||
if (!!promotions && promotions.count() > 0 && Array.isArray(layout) && !!me) {
|
||||
const sidebarPromotionPageId = `${page}.sidebar`
|
||||
const promotion = promotions.find(p => p.timeline_id === sidebarPromotionPageId)
|
||||
const promotion = promotions.find((p) => p.get('timeline_id') === sidebarPromotionPageId)
|
||||
|
||||
if (!!promotion) {
|
||||
const correctedPosition = promotion.position - 1 > layout.length ? layout.length - 1 : promotion.position
|
||||
const correctedPosition = promotion.get('position') - 1 > layout.length ? layout.length - 1 : promotion.get('position')
|
||||
if (!layout.find(p => p.key === 'status-promotion-panel')) {
|
||||
layout.splice(correctedPosition, 0, <WrappedBundle key='status-promotion-panel' component={StatusPromotionPanel} componentParams={{ statusId: promotion.status_id }} />)
|
||||
layout.splice(correctedPosition, 0, <WrappedBundle key='status-promotion-panel' component={StatusPromotionPanel} componentParams={{ statusId: promotion.get('status_id') }} />)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,10 +62,14 @@ class SidebarPanelGroup extends React.PureComponent {
|
||||
|
||||
}
|
||||
|
||||
const mapStateToProps = (state) => ({
|
||||
promotions: getPromotions()(state)
|
||||
})
|
||||
|
||||
SidebarPanelGroup.propTypes = {
|
||||
layout: PropTypes.array.isRequired,
|
||||
page: PropTypes.string.isRequired,
|
||||
promotion: PropTypes.object,
|
||||
}
|
||||
|
||||
export default SidebarPanelGroup
|
||||
export default connect(mapStateToProps)(SidebarPanelGroup)
|
||||
Reference in New Issue
Block a user