add link to public states on admin dashboard

This commit is contained in:
Markus Schubert 2020-03-30 14:55:52 +02:00
parent 4639eade8d
commit a16bc79756
2 changed files with 25 additions and 9 deletions

View file

@ -38,7 +38,8 @@ class AppHeader extends Component {
super(props); super(props);
this.state = { this.state = {
logoutSuccess: false, logoutSuccess: false,
redirectToStart: false redirectToStart: false,
redirectToAdmin: false
} }
} }
@ -53,11 +54,15 @@ class AppHeader extends Component {
console.log('error logging out: ' + error); console.log('error logging out: ' + error);
}); });
break; break;
case 'start': case 'start':
this.setState({ this.setState({
redirectToStart: true redirectToStart: true
}); });
break; break;
case 'admin':
this.setState({
redirectToAdmin: true
});
default: default:
break; break;
} }
@ -73,6 +78,12 @@ class AppHeader extends Component {
const redirectAfterLogout = this.state.logoutSuccess ? <Redirect to='/login' /> : <div></div> const redirectAfterLogout = this.state.logoutSuccess ? <Redirect to='/login' /> : <div></div>
const redirectToStart = this.state.redirectToStart ? <Redirect to='/start' /> : <div></div> const redirectToStart = this.state.redirectToStart ? <Redirect to='/start' /> : <div></div>
const redirectToAdmin = this.state.redirectToAdmin ? <Redirect to='/admin' /> : <div></div>
let adminSubmenu;
if (this.props.user && this.props.user.role === 'admin') {
adminSubmenu = <Menu.Item key='admin'>admin</Menu.Item>
}
if (this.props.user) { if (this.props.user) {
userInfo = ( userInfo = (
@ -86,6 +97,7 @@ class AppHeader extends Component {
</span> </span>
}> }>
<Menu.Item key="start">start</Menu.Item> <Menu.Item key="start">start</Menu.Item>
{adminSubmenu}
<Menu.Item key="logout">logout</Menu.Item> <Menu.Item key="logout">logout</Menu.Item>
</SubMenu> </SubMenu>
</Menu> </Menu>
@ -96,6 +108,7 @@ class AppHeader extends Component {
<Header style={{ position: 'fixed', zIndex: 1, width: '100%', background: '#3399cc' }}> <Header style={{ position: 'fixed', zIndex: 1, width: '100%', background: '#3399cc' }}>
{redirectAfterLogout} {redirectAfterLogout}
{redirectToStart} {redirectToStart}
{redirectToAdmin}
<div style={styles.logo}> <div style={styles.logo}>
<img style={styles.logoImage} src='images/logo.png' alt='' /> <img style={styles.logoImage} src='images/logo.png' alt='' />
<Link style={styles.logo} to="/">Die Gesellschaft der Gegenwart</Link> <Link style={styles.logo} to="/">Die Gesellschaft der Gegenwart</Link>

View file

@ -2,6 +2,7 @@ import React, { Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { loadPublicStates } from '../../actions/gameActions'; import { loadPublicStates } from '../../actions/gameActions';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { Link } from 'react-router-dom';
class PublicStateList extends Component { class PublicStateList extends Component {
@ -11,11 +12,13 @@ class PublicStateList extends Component {
render() { render() {
console.log('public states: ' + this.props.publicStates);
const pubStateList = this.props.publicStates.map((ps) => { const pubStateList = this.props.publicStates.map((ps) => {
return ( return (
<div key={ps.id}>{ps.name}</div> <div key={ps.id}>
<Link to={"/state/" + ps.name}>
{ps.name}
</Link>
</div>
) )
}); });