2016-09-21 03:07:32 +00:00
|
|
|
import React, { Component, PropTypes } from 'react';
|
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
import { push } from 'react-router-redux';
|
2016-10-19 20:22:18 +00:00
|
|
|
|
2016-09-21 03:07:32 +00:00
|
|
|
import paths from '../../router/paths';
|
2016-10-21 23:13:41 +00:00
|
|
|
import userInterface from '../../interfaces/user';
|
2016-09-21 03:07:32 +00:00
|
|
|
|
|
|
|
|
export class AuthenticatedAdminRoutes extends Component {
|
|
|
|
|
static propTypes = {
|
|
|
|
|
children: PropTypes.node,
|
|
|
|
|
dispatch: PropTypes.func,
|
2016-10-21 23:13:41 +00:00
|
|
|
user: userInterface,
|
2016-09-21 03:07:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
componentWillMount () {
|
|
|
|
|
const { dispatch, user: { admin } } = this.props;
|
|
|
|
|
const { HOME } = paths;
|
|
|
|
|
|
2016-10-19 20:22:18 +00:00
|
|
|
if (!admin) {
|
|
|
|
|
dispatch(push(HOME));
|
|
|
|
|
}
|
2016-09-21 03:07:32 +00:00
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render () {
|
|
|
|
|
const { children, user } = this.props;
|
|
|
|
|
|
2016-10-19 20:22:18 +00:00
|
|
|
if (!user) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2016-09-21 03:07:32 +00:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
{children}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state) => {
|
|
|
|
|
const { user } = state.auth;
|
|
|
|
|
|
|
|
|
|
return { user };
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps)(AuthenticatedAdminRoutes);
|