mirror of
https://github.com/wassname/talk.git
synced 2026-07-14 11:18:50 +08:00
39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
import React, {Component} from 'react';
|
|
import {connect} from 'react-redux';
|
|
import {Layout} from '../components/ui/Layout';
|
|
import {checkLogin, logout} from '../actions/auth';
|
|
import {FullLoading} from '../components/FullLoading';
|
|
import {PermissionRequired} from '../components/PermissionRequired';
|
|
|
|
class LayoutContainer extends Component {
|
|
componentWillMount () {
|
|
const {checkLogin} = this.props;
|
|
checkLogin().then(() => {
|
|
if (!this.props.auth.isAdmin) {
|
|
location.href = '/admin/login';
|
|
}
|
|
});
|
|
}
|
|
render () {
|
|
const {isAdmin, loggedIn, loadingUser} = this.props.auth;
|
|
if (loadingUser) { return <FullLoading />; }
|
|
if (!isAdmin) { return <PermissionRequired />; }
|
|
if (isAdmin && loggedIn) { return <Layout {...this.props} />; }
|
|
return <FullLoading />;
|
|
}
|
|
}
|
|
|
|
const mapStateToProps = state => ({
|
|
auth: state.auth.toJS()
|
|
});
|
|
|
|
const mapDispatchToProps = dispatch => ({
|
|
checkLogin: () => dispatch(checkLogin()),
|
|
handleLogout: () => dispatch(logout())
|
|
});
|
|
|
|
export default connect(
|
|
mapStateToProps,
|
|
mapDispatchToProps
|
|
)(LayoutContainer);
|