Skip to content

fix(order-form): added order_item parameter #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 90 additions & 72 deletions application/src/components/order-form/orderForm.js
Original file line number Diff line number Diff line change
@@ -1,83 +1,101 @@
import React, { Component } from 'react';
import { Template } from '../../components';
import { connect } from 'react-redux';
import { SERVER_IP } from '../../private';
import './orderForm.css';
import React, { Component } from "react";
import { Template } from "../../components";
import { connect } from "react-redux";
import { SERVER_IP } from "../../private";
import "./orderForm.css";

const ADD_ORDER_URL = `${SERVER_IP}/api/add-order`
const ADD_ORDER_URL = `${SERVER_IP}/api/add-order`;

const mapStateToProps = (state) => ({
auth: state.auth,
})
auth: state.auth,
});

class OrderForm extends Component {
constructor(props) {
super(props);
this.state = {
order_item: "",
quantity: "1"
}
}
constructor(props) {
super(props);
this.state = {
order_item: "",
quantity: "1",
};
}

menuItemChosen(event) {
this.setState({ item: event.target.value });
}
menuItemChosen(event) {
// Fixed bug by adding 'order-item' parameter
this.setState({ order_item: event.target.value });
}

menuQuantityChosen(event) {
this.setState({ quantity: event.target.value });
}
menuQuantityChosen(event) {
this.setState({ quantity: event.target.value });
}

submitOrder(event) {
event.preventDefault();
if (this.state.order_item === "") return;
fetch(ADD_ORDER_URL, {
method: 'POST',
body: JSON.stringify({
order_item: this.state.order_item,
quantity: this.state.quantity,
ordered_by: this.props.auth.email || 'Unknown!',
}),
headers: {
'Content-Type': 'application/json'
}
})
.then(res => res.json())
.then(response => console.log("Success", JSON.stringify(response)))
.catch(error => console.error(error));
}
submitOrder(event) {
event.preventDefault();
if (this.state.order_item === "") return;
fetch(ADD_ORDER_URL, {
method: "POST",
body: JSON.stringify({
order_item: this.state.order_item,
quantity: this.state.quantity,
ordered_by: this.props.auth.email || "Unknown!",
}),
headers: {
"Content-Type": "application/json",
},
})
.then((res) => res.json())
.then((response) => console.log("Success", JSON.stringify(response)))
.catch((error) => console.error(error));
}

render() {
return (
<Template>
<div className="form-wrapper">
<form>
<label className="form-label">I'd like to order...</label><br />
<select
value={this.state.order_item}
onChange={(event) => this.menuItemChosen(event)}
className="menu-select"
>
<option value="" defaultValue disabled hidden>Lunch menu</option>
<option value="Soup of the Day">Soup of the Day</option>
<option value="Linguini With White Wine Sauce">Linguini With White Wine Sauce</option>
<option value="Eggplant and Mushroom Panini">Eggplant and Mushroom Panini</option>
<option value="Chili Con Carne">Chili Con Carne</option>
</select><br />
<label className="qty-label">Qty:</label>
<select value={this.state.quantity} onChange={(event) => this.menuQuantityChosen(event)}>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
<button type="button" className="order-btn" onClick={(event) => this.submitOrder(event)}>Order It!</button>
</form>
</div>
</Template>
);
}
render() {
return (
<Template>
<div className="form-wrapper">
<form>
<label className="form-label">I'd like to order...</label>
<br />
<select
value={this.state.order_item}
onChange={(event) => this.menuItemChosen(event)}
className="menu-select"
>
<option value="" defaultValue disabled hidden>
Lunch menu
</option>
<option value="Soup of the Day">Soup of the Day</option>
<option value="Linguini With White Wine Sauce">
Linguini With White Wine Sauce
</option>
<option value="Eggplant and Mushroom Panini">
Eggplant and Mushroom Panini
</option>
<option value="Chili Con Carne">Chili Con Carne</option>
</select>
<br />
<label className="qty-label">Qty:</label>
<select
value={this.state.quantity}
onChange={(event) => this.menuQuantityChosen(event)}
>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
<button
type="button"
className="order-btn"
onClick={(event) => this.submitOrder(event)}
>
Order It!
</button>
</form>
</div>
</Template>
);
}
}

export default connect(mapStateToProps, null)(OrderForm);
export default connect(mapStateToProps, null)(OrderForm);