|
| 1 | +/** |
| 2 | + * Connects the Redux store to the PolicyPages component. |
| 3 | + */ |
| 4 | +import _ from 'lodash'; |
| 5 | +import React from 'react'; |
| 6 | +import { connect } from 'react-redux'; |
| 7 | +import PT from 'prop-types'; |
| 8 | +import actions from 'actions/contentful'; |
| 9 | +import PolicyPages from 'components/PolicyPages'; |
| 10 | +import LoadingIndicator from 'components/LoadingIndicator'; |
| 11 | +import Header from 'containers/TopcoderHeader'; |
| 12 | +import Footer from 'components/TopcoderFooter'; |
| 13 | + |
| 14 | +const HEADE_MENU = [ |
| 15 | + { |
| 16 | + id: 'business', |
| 17 | + title: 'BUSINESS', |
| 18 | + href: 'https://www.topcoder.com', |
| 19 | + }, |
| 20 | + { |
| 21 | + id: 'community-123', |
| 22 | + title: 'COMMUNITY', |
| 23 | + href: '/community/learn', |
| 24 | + }, |
| 25 | +]; |
| 26 | + |
| 27 | +class PolicyPagesContainer extends React.Component { |
| 28 | + componentDidMount() { |
| 29 | + const { loadingPolicyPages, policyData, getPolicyPages } = this.props; |
| 30 | + if (!loadingPolicyPages && !policyData) { |
| 31 | + getPolicyPages(); |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + render() { |
| 36 | + const { |
| 37 | + loadingPolicyPages, policyData, |
| 38 | + } = this.props; |
| 39 | + if (loadingPolicyPages || !policyData) return <LoadingIndicator />; |
| 40 | + if (_.isEmpty(policyData)) { |
| 41 | + return ( |
| 42 | + <h1 style={{ 'text-align': 'center' }}>Please, publish Policy Pages in Contentful space to see this page.</h1> |
| 43 | + ); |
| 44 | + } |
| 45 | + return ( |
| 46 | + <div> |
| 47 | + <Header headerMenu={HEADE_MENU} /> |
| 48 | + <PolicyPages {...this.props} /> |
| 49 | + <Footer /> |
| 50 | + </div> |
| 51 | + ); |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +PolicyPagesContainer.defaultProps = { |
| 56 | + loadingPolicyPages: false, |
| 57 | + policyData: null, |
| 58 | +}; |
| 59 | + |
| 60 | +PolicyPagesContainer.propTypes = { |
| 61 | + loadingPolicyPages: PT.bool, |
| 62 | + match: PT.shape().isRequired, |
| 63 | + policyData: PT.shape(), |
| 64 | + getPolicyPages: PT.func.isRequired, |
| 65 | +}; |
| 66 | + |
| 67 | +function mapStateToProps(state, ownProps) { |
| 68 | + return { |
| 69 | + p: ownProps.p, |
| 70 | + policyData: state.policyPages.policyData, |
| 71 | + }; |
| 72 | +} |
| 73 | + |
| 74 | +function mapDispatchToProps(dispatch) { |
| 75 | + return { |
| 76 | + getPolicyPages: () => { |
| 77 | + dispatch(actions.contentful.getPolicyPagesInit()); |
| 78 | + dispatch(actions.contentful.getPolicyPagesDone()); |
| 79 | + }, |
| 80 | + }; |
| 81 | +} |
| 82 | + |
| 83 | +export default connect( |
| 84 | + mapStateToProps, |
| 85 | + mapDispatchToProps, |
| 86 | +)(PolicyPagesContainer); |
0 commit comments