Last active
April 28, 2019 03:26
-
-
Save beaucarnes/9c64361dc92b3d739b68e75b865a6fb8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { Component } from 'react'; | |
| import DatePicker from 'react-datepicker'; | |
| import "react-datepicker/dist/react-datepicker.css"; | |
| export default class CreateExercise extends Component { | |
| constructor(props) { | |
| super(props); | |
| this.onChangeUsername = this.onChangeUsername.bind(this); | |
| this.onChangeDescription = this.onChangeDescription.bind(this); | |
| this.onChangeDuration = this.onChangeDuration.bind(this); | |
| this.onChangeDate = this.onChangeDate.bind(this); | |
| this.onSubmit = this.onSubmit.bind(this); | |
| this.state = { | |
| username: '', | |
| description: '', | |
| duration: 0, | |
| date: new Date(), | |
| users: [] | |
| } | |
| } | |
| componentDidMount() { | |
| this.setState({ | |
| users: ['test user'], | |
| username: 'test user' | |
| }); | |
| } | |
| onChangeUsername(e) { | |
| this.setState({ | |
| username: e.target.value | |
| }); | |
| } | |
| onChangeDescription(e) { | |
| this.setState({ | |
| description: e.target.value | |
| }); | |
| } | |
| onChangeDuration(e) { | |
| this.setState({ | |
| duration: e.target.value | |
| }); | |
| } | |
| onChangeDate(date) { | |
| this.setState({ | |
| date: date | |
| }); | |
| } | |
| onSubmit(e) { | |
| e.preventDefault(); | |
| const exercise = { | |
| username: this.state.username, | |
| description: this.state.description, | |
| duration: this.state.duration, | |
| date: this.state.date, | |
| }; | |
| console.log(exercise); | |
| window.location = '/'; | |
| } | |
| render() { | |
| return ( | |
| <div> | |
| <h3>Create New Exercise Log</h3> | |
| <form onSubmit={this.onSubmit}> | |
| <div className="form-group"> | |
| <label>Username: </label> | |
| <select ref="userInput" | |
| required | |
| className="form-control" | |
| value={this.state.username} | |
| onChange={this.onChangeUsername}> | |
| { | |
| this.state.users.map(function(user) { | |
| return <option | |
| key={user} | |
| value={user}>{user} | |
| </option>; | |
| }) | |
| } | |
| </select> | |
| </div> | |
| <div className="form-group"> | |
| <label>Description: </label> | |
| <input type="text" | |
| required | |
| className="form-control" | |
| value={this.state.description} | |
| onChange={this.onChangeDescription} | |
| /> | |
| </div> | |
| <div className="form-group"> | |
| <label>Duration (in minutes): </label> | |
| <input | |
| type="text" | |
| className="form-control" | |
| value={this.state.duration} | |
| onChange={this.onChangeDuration} | |
| /> | |
| </div> | |
| <div className="form-group"> | |
| <label>Date: </label> | |
| <div> | |
| <DatePicker | |
| selected={this.state.date} | |
| onChange={this.onChangeDate} | |
| /> | |
| </div> | |
| </div> | |
| <div className="form-group"> | |
| <input type="submit" value="Create Exercise Log" className="btn btn-primary" /> | |
| </div> | |
| </form> | |
| </div> | |
| ) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment