mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
dc4b97d15f
- Refactor imports of PropTypes to use the prop-types package - Upgrade dependencies that were setting off deprecation warnings
49 lines
942 B
JavaScript
49 lines
942 B
JavaScript
import React, { Component } from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import { connect } from 'react-redux';
|
|
import { push } from 'react-router-redux';
|
|
|
|
import paths from '../../router/paths';
|
|
import userInterface from '../../interfaces/user';
|
|
|
|
export class AuthenticatedAdminRoutes extends Component {
|
|
static propTypes = {
|
|
children: PropTypes.node,
|
|
dispatch: PropTypes.func,
|
|
user: userInterface,
|
|
};
|
|
|
|
componentWillMount () {
|
|
const { dispatch, user: { admin } } = this.props;
|
|
const { HOME } = paths;
|
|
|
|
if (!admin) {
|
|
dispatch(push(HOME));
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
render () {
|
|
const { children, user } = this.props;
|
|
|
|
if (!user) {
|
|
return false;
|
|
}
|
|
|
|
return (
|
|
<div>
|
|
{children}
|
|
</div>
|
|
);
|
|
}
|
|
}
|
|
|
|
const mapStateToProps = (state) => {
|
|
const { user } = state.auth;
|
|
|
|
return { user };
|
|
};
|
|
|
|
export default connect(mapStateToProps)(AuthenticatedAdminRoutes);
|