import React, { Component } from 'react'; class AuthMenu extends Component { constructor (props) { super(props) this.state = { where_in_auth_menu: "requestUsername", username: "", password: "", email: "" } this.handleAccountCreation = this.handleAccountCreation.bind(this) this.handleInputChange = this.handleInputChange.bind(this) this.handlePasswordForLogin = this.handlePasswordForLogin.bind(this) this.handleEmailRequest = this.handleEmailRequest.bind(this) this.authMenu = this.authMenu.bind(this) } handleInputChange(event) { const target = event.target; const value = target.value; const name = target.name; this.setState({ [name]: value }); } handlePasswordForLogin() { this.setState(state => ({ where_in_auth_menu: "requestPasswordForLogin", auth_menu_visible: true, })); } handleEmailRequest() { this.setState(state => ({ where_in_auth_menu: "requestEmail", auth_menu_visible: true, })); } handleAccountCreation() { this.setState(state => ({ where_in_auth_menu: "requestPasswordForCreation", auth_menu_visible: true, })); } authMenu() { if (!this.props.auth_menu_visible) { return null; } switch(this.state.where_in_auth_menu) { case 'requestUsername': return (
) case 'requestPasswordForLogin': return (
onChange={this.handleInputChange}
) case 'requestEmail': return (
onChange={this.handleInputChange}
) case 'requestPasswordForCreation': return (
) default: return null; } } render() { return ( this.authMenu(this.state.auth_menu_visible) ) } } export default (AuthMenu)