Skip to content
Open
Show file tree
Hide file tree
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
28,651 changes: 20,159 additions & 8,492 deletions application/package-lock.json

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions application/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"axios": "^0.19.0",
"bootstrap": "^4.3.1",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-redux": "^7.1.0",
"react-router-dom": "^5.0.1",
"react-scripts": "3.0.1",
"redux": "^4.0.1",
"axios": "^0.21.1",
"bootstrap": "^5.0.0",
"moment": "^2.29.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-redux": "^7.2.4",
"react-router-dom": "^5.2.0",
"react-scripts": "^1.1.5",
"redux": "^4.1.0",
"redux-thunk": "^2.3.0"
},
"scripts": {
Expand Down
10 changes: 5 additions & 5 deletions application/src/components/dashboard/dashboard.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Link } from 'react-router-dom';
import './Dasboard.css';
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Link } from 'react-router-dom';
import './Dasboard.css';

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

class Dashboard extends Component {
Expand Down
12 changes: 6 additions & 6 deletions application/src/components/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Login from './login/login';
import Main from './main/main';
import Nav from './nav/nav';
import OrderForm from './order-form/orderForm';
import Template from './common/template';
import ViewOrders from './view-orders/viewOrders';
import Login from './login/login';
import Main from './main/main';
import Nav from './nav/nav';
import OrderForm from './order-form/orderForm';
import Template from './common/template';
import ViewOrders from './view-orders/viewOrders';

export { Login, OrderForm, Main, Nav, Template, ViewOrders };
100 changes: 59 additions & 41 deletions application/src/components/login/login-form/loginForm.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,64 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { loginUser } from '../../../redux/actions/authActions'
import React from 'react';
import { connect } from 'react-redux';
import { loginUser } from '../../../redux/actions/authActions';

const mapActionsToProps = dispatch => ({
commenceLogin(email, password) {
dispatch(loginUser(email, password))
}
})

class LoginForm extends Component {
state = {
email: "",
password: "",
}

login(e) {
e.preventDefault();
this.props.commenceLogin(this.state.email, this.state.password);
this.props.onLogin();
}

onChange(key, val) {
this.setState({ [key]: val });
}

render() {
return (
<form>
<div className="form-group">
<label htmlFor="inputEmail">Email</label>
<input type="text" className="form-control" placeholder="test@test.com" value={this.state.email} onChange={e => this.onChange('email', e.target.value)}></input>
</div>
<div className="form-group">
<label htmlFor="inputPassword">Password</label>
<input type="password" className="form-control" id="inputPassword" value={this.state.password} onChange={e => this.onChange('password', e.target.value)}></input>
</div>
<div className="d-flex justify-content-center">
<button onClick={e => this.login(e)} type="submit" className="btn btn-primary">Login</button>
</div>
</form>
);
}
commenceLogin(email, password) {
dispatch(loginUser(email, password));
}
});

class LoginForm extends React.Component {

constructor(props) {
super(props);

this.state = {
email: "",
password: "",
}
}


login(e) {
e.preventDefault();

// add user to the database
this.props.commenceLogin(this.state.email, this.state.password);
this.props.onLogin();
}

onChange(key, val) {
this.setState({ [key]: val });
}

render() {
return (
<form>
<div className="form-group">
<label htmlFor="inputEmail">Email</label>
<input type="text"
className="form-control"
placeholder="test@test.com"
value={this.state.email}
onChange={e => this.onChange('email', e.target.value)}></input>
</div>
<div className="form-group">
<label htmlFor="inputPassword">Password</label>
<input type="password"
className="form-control"
id="inputPassword"
value={this.state.password}
onChange={e => this.onChange('password', e.target.value)}></input>
</div>
<div className="d-flex justify-content-center">
<button onClick={e => this.login(e)}
type="submit"
className="btn btn-primary">Login</button>
</div>
</form>
);
}
}

export default connect(null, mapActionsToProps)(LoginForm);
27 changes: 13 additions & 14 deletions application/src/components/login/login.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import React, { Component } from 'react';
import LoginForm from './login-form/loginForm';
import './login.css';
import React, { Component } from 'react';
import LoginForm from './login-form/loginForm';
import './login.css';

class Login extends Component {

render() {
return (
<div className="main-body">
<h1 className="text-center">Login Screen</h1>
<div className="d-flex justify-content-center mt-5">
<LoginForm onLogin={() => {this.props.history.push('/view-orders')}}/>
</div>
</div>
)
}
render() {
return (
<div className="main-body">
<h1 className="text-center">Login Screen</h1>
<div className="d-flex justify-content-center mt-5">
<LoginForm onLogin={() => {this.props.history.push('/view-orders')}} />
</div>
</div>
)
}
}

export default Login;
31 changes: 15 additions & 16 deletions application/src/components/main/main.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Link } from 'react-router-dom';
import './main.css';
import { connect } from 'react-redux';
import { Link } from 'react-router-dom';
import './main.css';

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

class Main extends Component {
render() {
console.log('props', this.props);
return (
<div className="main-body">
<h1>Bruce's Diner Ordering Application</h1>
<h2>Please login to continue</h2>
<Link to={'/login'}>
<button className="btn btn-primary">Go To Login</button>
</Link>
</div>
)
}
render() {
return (
<div className="main-body">
<h1>Bruce's Diner Ordering Application</h1>
<h2>Please login to continue</h2>
<Link to={'/login'}>
<button className="btn btn-primary">Go To Login</button>
</Link>
</div>
)
}
}

export default connect(mapStateToProps, null)(Main);
142 changes: 72 additions & 70 deletions application/src/components/order-form/orderForm.js
Original file line number Diff line number Diff line change
@@ -1,83 +1,85 @@
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) {
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();
console.log(this.state);

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.token || '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);
Loading