/
newEvent.jsx
141 lines (135 loc) · 5.31 KB
/
newEvent.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import React from 'react';
import qs from 'qs';
import axios from 'axios';
import { browserHistory } from 'react-router';
import store from '../store';
import NavBar from './navbar.jsx';// eslint-disable-line
export default class NewEvent extends React.Component {
constructor(props) {
super(props);
this.handleChange = this.handleChange.bind(this);
this.submitEvent = this.submitEvent.bind(this);
this.state = {};
}
submitEvent(event) {
event.preventDefault();
const apiQueryString = `api/event?${qs.stringify(this.state)}`;
if (this.state.event_title === undefined || '') {
alert('Event title is required!');
} else {
axios.post(apiQueryString)
.then((result) => {
this.state.id = result.data[0];
store.dispatch({
type: 'ADD_SINGLE_EVENT',
event: this.state,
});
alert('Success creating event!');
browserHistory.push('/');
})
.catch((error) => {
console.log(error);
alert('Error with database! See console for output.');
});
}
}
handleChange(event) {
const key = event.target.id;
const value = event.target.value;
this.setState({
[key]: value,
});
}
render() {
return (
<div>
<NavBar />
<div className="container-fluid">
{ /* <!--Heading Text-->*/ }
<div className="row">
<div className="col-md-offset-4 col-md-4">
<h3 className="text-center">Create New Event</h3>
</div>
</div>
<div className="row">
<div className="col-md-offset-2 col-md-8">
<div className="well">
<form className="form-horizontal" onSubmit={this.submitEvent}>
<fieldset>
{/* <!--Event Title-->*/}
<div className="form-group">
<label
htmlFor="event_title" className="col-lg-2 control-label"
>Event Title (required)</label>
<div className="col-lg-9">
<input
type="text"
onChange={this.handleChange}
className="form-control"
id="event_title"
/>
</div>
</div>
{/* <!--Description-->*/}
<div className="form-group">
<label
htmlFor="description" className="col-lg-2 control-label"
>Description</label>
<div className="col-lg-9">
<textarea
className="form-control" onChange={this.handleChange}rows="3" id="description"
/>
</div>
</div>
{/* <!--Start Date-->*/}
<div className="form-group">
<label
htmlFor="start_date" className="col-lg-2 control-label"
>Start Date</label>
<div className="col-lg-9">
<input type="date" onChange={this.handleChange} className="form-control" id="start_date" placeholder="YYYY/MM/DD" />
</div>
</div>
{/* <!--End Date-->*/}
<div className="form-group">
<label htmlFor="end_date" className="col-lg-2 control-label">End Date</label>
<div className="col-lg-9">
<input type="date" onChange={this.handleChange} className="form-control" id="end_date" placeholder="YYYY/MM/DD" />
</div>
</div>
{/* <!--Category-->*/}
<div className="form-group">
<label htmlFor="category" className="col-lg-2 control-label">Category</label>
<div className="col-lg-9">
<input
type="text" className="form-control" onChange={this.handleChange} id="category"
/>
</div>
</div>
{/* <!--Featured-->*/}
<div className="form-group">
<label htmlFor="featured_flag" className="col-lg-2 control-label">Featured?</label>
<div className="col-lg-9">
<select onChange={this.handleChange} className="form-control" id="featured_flag">
<option value="null" />
<option value="1">True</option>
<option value="0">False</option>
</select>
</div>
</div>
{/* <!--Submit BTN-->*/}
<div className="form-group">
<div className="col-lg-10 col-lg-offset-2">
<button className="btn btn-primary" type="submit">Submit</button>
</div>
</div>
</fieldset>
</form>
</div>
</div>
</div>
</div>
</div>
);
}
}