import React, { PropTypes } from 'react';
import { connect } from 'react-redux';
import GroupPage from './GroupPage.js';
import GroupNotFoundPage from './GroupNotFoundPage.js';


const Group = ({ isValid, groupId }) => (isValid ? <GroupPage groupId={groupId} /> : <GroupNotFoundPage groupId={groupId} />);


Group.propTypes = {
  groupId: PropTypes.string,
  isValid: PropTypes.bool.isRequired
};

export default connect(state => ({
  groupId: state.router.params.groupId,
  isValid: !!state.groups.data[state.router.params.groupId]
}))(Group);
