@@ -8,13 +8,16 @@ class UserForm extends React.Component {
88 state = {
99 id: 0,
1010 username: '',
11- caloriesPerDay: 0
11+ preferences: { max_calories: 0 }
1212 };
1313
1414 componentDidMount() {
1515 if (this.props.user) {
16- const { id, username, caloriesPerDay } = this.props.user;
17- this.setState({ id, username, caloriesPerDay });
16+ this.setState({
17+ id: this.props.user.id,
18+ username: this.props.user.username,
19+ preferences: this.props.user.preferences
20+ });
1821 }
1922 }
2023
@@ -22,10 +25,13 @@ class UserForm extends React.Component {
2225 this.setState({ [e.target.name]: e.target.value });
2326 };
2427
28+ onCaloriesChange = e => {
29+ this.setState({ preferences: { max_calories: e.target.value }});
30+ };
31+
2532 createUser = e => {
2633 e.preventDefault();
2734 axios.post(API_URL + 'users/', this.state, { crossdomain: true }).then(() => {
28- this.props.resetState();
2935 this.props.toggle();
3036 });
3137 };
@@ -33,7 +39,6 @@ class UserForm extends React.Component {
3339 editUser = e => {
3440 e.preventDefault();
3541 axios.put(API_URL + 'users/' + this.state.id, this.state, { crossdomain: true }).then(() => {
36- this.props.resetState();
3742 this.props.toggle();
3843 });
3944 };
@@ -46,7 +51,7 @@ class UserForm extends React.Component {
4651 return (
4752 <Form onSubmit={this.props.user ? this.editUser : this.createUser}>
4853 <FormGroup>
49- <Label for="username">username:</Label>
54+ <Label for="username">Username:</Label>
5055 <Input
5156 type="text"
5257 name="username"
@@ -55,16 +60,25 @@ class UserForm extends React.Component {
5560 />
5661 </FormGroup>
5762 <FormGroup>
58- <Label for="caloriesPerDay">Calories per day:</Label>
63+ <Label for="examplePassword">Password:</Label>
64+ <Input
65+ type="password"
66+ name="password"
67+ onChange={this.onChange}
68+ value={this.defaultIfEmpty(this.state.name)}
69+ />
70+ </FormGroup>
71+ <FormGroup>
72+ <Label for="caloriesPerDay">Maximum Calories per Day:</Label>
5973 <Input
6074 type="text"
6175 name="caloriesPerDay"
62- onChange={this.onChange}
76+ onChange={this.onCaloriesChange}
6377 value={this.defaultIfEmpty(this.state.name)}
6478 />
6579 </FormGroup>
6680
67- <Button>Save</Button>
81+ <Button className="float-right" color="primary">Save</Button>
6882 </Form>
6983 )
7084 }