This repository has been archived by the owner on Apr 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
/
AddDestination.jsx
80 lines (62 loc) · 2.57 KB
/
AddDestination.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import React, { Component } from "react";
export default class AddDestination extends Component {
constructor(props) {
super(props);
this.state = this.getInitialState();
}
static defaultProps = {
onAdd: () => null
}
getInitialState = () => ({
id: '',
description: '',
city: '',
state: '',
zip: ''
});
handleChange = (field, event) => {
const { target: { value } } = event;
this.setState({
[field]: value
});
}
handleAdd = () => {
const { id, description, city, state, zip } = this.state;
this.setState(this.getInitialState(), () => {
this.props.onAdd({ id, description, city, state, zip });
});
alert('Destination Added!');
}
handleCancel = () => {
this.setState(this.getInitialState());
}
render() {
return (
<div className="ui container raised very padded segment">
<div className="ui small form">
<div className="required field required eight wide">
<label htmlFor="description">Description</label>
<input type="text" id="description" value={this.state.description} onChange={this.handleChange.bind(this, 'description')} />
</div>
<div class="fields">
<div className="required field required eight ">
<label htmlFor="city">City</label>
<input type="text" id="city" value={this.state.city} onChange={this.handleChange.bind(this, 'city')} />
</div>
<div className="required field required eight ">
<label htmlFor="state">State</label>
<input type="text" id="state" value={this.state.state} onChange={this.handleChange.bind(this, 'state')} />
</div>
<div className="required field required eight ">
<label htmlFor="zip">Zip</label>
<input type="text" id="zip" value={this.state.zip} onChange={this.handleChange.bind(this, 'zip')} />
</div>
</div>
<button className="ui positive button" onClick={this.handleAdd}>
Save
</button>
</div>
</div>
);
}
}