-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBookingForm.js
More file actions
199 lines (191 loc) · 5.35 KB
/
BookingForm.js
File metadata and controls
199 lines (191 loc) · 5.35 KB
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import { withRouter } from "react-router-dom";
import { useState } from "react";
import BookingCal from "./BookingCal";
import axios from "axios";
import { apiURL } from "../util/apiURL";
import { useHistory, useParams } from "react-router";
import { useAuth } from "../Providers/AuthProvider";
const API = apiURL();
const BookingForm = ({ chef }) => {
const { id } = useParams();
const chef_id = id;
const { currentUser } = useAuth();
const [request, setRequest] = useState({
event_type: "",
pricing_option: "",
party_size: "",
address: "",
address2: "",
city: "",
state: "",
zip_code: "",
start_event: "",
end_event: "",
});
let history = useHistory();
const handleChange = (type) => {
return (e) => setRequest({ ...request, [type]: e.target.value });
};
const addNewRequest = async (newRequest) => {
try {
const chefRequest = {
chef_id: chef_id,
user_id: currentUser.uid,
...newRequest,
};
let res = await axios.post(
`${API}/users/${currentUser?.uid}/bookings`,
chefRequest
);
return res;
} catch (err) {
return "error";
}
};
const handleSubmit = async (e) => {
e.preventDefault();
let res = await addNewRequest(request);
if (res.data.payload.success === true) {
history.push(`/users/${currentUser.uid}/bookings`);
} else {
console.log(res);
}
};
return (
<section className="booking">
<div className="booking-container">
<p className="booking-heading"> Book Chef</p>
<div className="selects">
<div>
<p>Select Event Type:</p>
<select
onChange={handleChange("event_type")}
className="form-select form-select-sm"
aria-label="Default select example"
>
<option type="text" value={"Birthday Party"}>
Birthday Party
</option>
<option type="text" value={"Corporate Event"}>
Corporate Event
</option>
<option type="text" value={"Dinner Party"}>
Dinner Party
</option>
<option type="text" value={"Meal Prep"}>
Meal Prep
</option>
<option type="text" value={"Brunch"}>
Brunch
</option>
<option type="text" value={"Other"}>
Other
</option>
</select>
</div>
<div className="booking-box">
<p>Party Size</p>
<div className="party_size">
<input
value={request.party_size}
type="number"
name="party_size"
onChange={handleChange("party_size")}
/>
</div>
</div>
</div>
<div>
<p>Service Type:</p>
<select
onChange={handleChange("pricing_option")}
className="form-select form-select-sm"
aria-label="Default select example"
>
<option type="text" value={"Comfort"}>
Comfort - $15
</option>
<option type="text" value={"Casual"}>
Casual - $30
</option>
<option type="text" value={"Fine"}>
Fine - $70
</option>
</select>
</div>
<p className="booking-heading1">Event Location</p>
<div className="booking-box">
<p>Address</p>
<div>
<input
value={request.address}
type="text"
name="address"
onChange={handleChange("address")}
required
/>
</div>
</div>
<div className="booking-box">
<p>Address2</p>
<div>
<input
value={request.address2}
type="text"
name="address2"
onChange={handleChange("address2")}
/>
</div>
</div>
<div className="booking-box">
<p>City</p>
<div>
<input
className=""
value={request.city}
type="text"
name="city"
onChange={handleChange("city")}
required
/>
</div>
</div>
<div className="city-state">
<div className="booking-box">
<p>State</p>
<div>
<input
value={request.state}
type="text"
name="state"
onChange={handleChange("state")}
required
/>
</div>
</div>
<div className="booking-box">
<p>Zip Code</p>
<div>
<input
value={request.zip_code}
type="text"
name="zip_code"
onChange={handleChange("zip_code")}
required
/>
</div>
</div>
</div>
<div>
<p className="booking-heading1">Event Start & End Time</p>
<BookingCal setRequest={setRequest} request={request} />
<button onClick={handleSubmit} className="loginBtn3" type="submit">
{" "}
Book{" "}
</button>
</div>
</div>
</section>
);
};
export default withRouter(BookingForm);