|
| 1 | +/** |
| 2 | + * @file LoginForm.js |
| 3 | + * Exports a component that allows users to log into EditVR. |
| 4 | + */ |
| 5 | + |
| 6 | +import React, { Component } from 'react'; |
| 7 | +import PropTypes from 'prop-types'; |
| 8 | +import { TextField, Button, withStyles } from '@material-ui/core'; |
| 9 | + |
| 10 | +import LoginFormStyles from './LoginForm.style'; |
| 11 | + |
| 12 | +class LoginForm extends Component { |
| 13 | + static propTypes = { |
| 14 | + classes: PropTypes.shape({ |
| 15 | + textField: PropTypes.string.isRequired, |
| 16 | + button: PropTypes.string.isRequired |
| 17 | + }).isRequired |
| 18 | + }; |
| 19 | + |
| 20 | + state = { |
| 21 | + username: null, |
| 22 | + password: null, |
| 23 | + apiLoading: false, |
| 24 | + apiMessage: null |
| 25 | + }; |
| 26 | + |
| 27 | + /** |
| 28 | + * Handles field update action. |
| 29 | + * |
| 30 | + * @param {object} event - Field update event. |
| 31 | + */ |
| 32 | + handleFieldUpdate = event => { |
| 33 | + const state = {}; |
| 34 | + state[event.target.id] = event.target.value; |
| 35 | + this.setState(state); |
| 36 | + }; |
| 37 | + |
| 38 | + /** |
| 39 | + * Handles a login form submit action. |
| 40 | + * |
| 41 | + * @param {object} event - Submit event object. |
| 42 | + */ |
| 43 | + handleSubmit = event => {}; |
| 44 | + |
| 45 | + /** |
| 46 | + * {@inheretdoc} |
| 47 | + */ |
| 48 | + render() { |
| 49 | + const { classes } = this.props; |
| 50 | + const { apiLoading, apiMessage } = this.state; |
| 51 | + |
| 52 | + return ( |
| 53 | + <form onSubmit={this.handleSubmit}> |
| 54 | + <TextField |
| 55 | + id="username" |
| 56 | + label="Username" |
| 57 | + type="text" |
| 58 | + required |
| 59 | + onChange={this.handleFieldUpdate} |
| 60 | + className={classes.textField} |
| 61 | + /> |
| 62 | + <TextField |
| 63 | + id="password" |
| 64 | + label="Password" |
| 65 | + type="password" |
| 66 | + required |
| 67 | + onChange={this.handleFieldUpdate} |
| 68 | + className={classes.textField} |
| 69 | + /> |
| 70 | + <Button |
| 71 | + variant="raised" |
| 72 | + color="primary" |
| 73 | + type="submit" |
| 74 | + className={classes.button} |
| 75 | + > |
| 76 | + Log In |
| 77 | + </Button> |
| 78 | + </form> |
| 79 | + ); |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | +export default withStyles(LoginFormStyles)(LoginForm); |
0 commit comments