ensl_gathers/app/javascripts/components/admin.js

120 lines
2.7 KiB
JavaScript
Raw Normal View History

import React from "react";
import { object } from "prop-types"
import { MenubarMixin } from "javascripts/components/menubar";
2016-02-18 11:06:35 +00:00
class UserLogin extends React.Component {
static propTypes = {
socket: object.isRequired
}
2016-02-18 11:06:35 +00:00
state = {
userId: null
}
2016-02-18 11:06:35 +00:00
handleChange = (e) => {
const newId = e.target.value || null;
this.setState({ userId: newId });
}
2016-02-18 11:06:35 +00:00
authorizeId = (id) => {
this.props.socket.emit("users:authorize", {
id: id
});
}
2016-02-18 11:06:35 +00:00
handleSubmit = (e) => {
e.preventDefault();
this.authorizeId(this.state.userId);
}
2016-02-18 11:06:35 +00:00
render = () => {
return (
<form>
<div className="input-group signin">
<input
id="btn-input"
type="text"
className="form-control"
vaue={this.state.userId}
onChange={this.handleChange}
placeholder="Change user (input ID)" />
<span className="input-group-btn">
<input
type="submit"
className="btn btn-primary"
onClick={this.handleSubmit}
value="Assume ID" />
</span>
</div>
</form>
);
}
}
2016-02-18 11:06:35 +00:00
class ResetGatherButton extends React.Component {
static propTypes = {
socket: object.isRequired,
gather: object.isRequired
}
2016-02-18 11:06:35 +00:00
handleGatherReset = () => {
this.props.socket.emit("gather:reset", {
type: this.props.gather.type
});
}
2016-03-19 23:37:28 +00:00
render = () => {
return (
<button
className="btn btn-danger max-width"
onClick={this.handleGatherReset}>
Reset {this.props.gather.name}</button>
);
}
}
2016-03-19 23:37:28 +00:00
class AdminPanel extends MenubarMixin(React.Component) {
2016-03-19 23:37:28 +00:00
static propTypes = {
socket: object.isRequired,
gatherPool: object.isRequired
}
2016-02-18 11:06:35 +00:00
constructor(props) {
super(props)
this.state = super.getInitialState();
}
render = () => {
const gatherPool = this.props.gatherPool;
const resetButtons = [];
for (let attr in gatherPool) {
let gather = gatherPool[attr];
resetButtons.push(
<ResetGatherButton socket={this.props.socket}
gather={gather} key={gather.type} />
);
}
return (
<li className={this.componentClass()}>
<a href="#" onClick={this.toggleShow}>
<i className="fa fa-rebel"></i>
</a>
<ul className="dropdown-menu">
<li className="header">Admin</li>
<ul className="news-menu">
<h5>Swap Into a Different Account (Only works for admins)</h5>
<UserLogin socket={this.props.socket} />
<h5>Gather Options</h5>
<div>
{resetButtons}
</div>
</ul>
</ul>
</li>
);
}
}
export { AdminPanel, ResetGatherButton }