Commit cf62998c authored by Kristian Freeman's avatar Kristian Freeman

Ship orders

parent 6b3ca2fc
......@@ -9,6 +9,7 @@ import Manufacturing from './Manufacturing'
import Orders from './Orders'
import QA from './QA'
import Packaging from './Packaging'
import Shipping from './Shipping'
const Header = () => <img className="logo" src="/logo.png" />
const Error = (props) => <h4>{props.message}</h4>
......@@ -27,6 +28,7 @@ class App extends Component {
wheel: { count: 3 }
},
packaged: 0,
shipped: 0,
widgets: []
}
......@@ -35,6 +37,7 @@ class App extends Component {
this.orderMaterials = this.orderMaterials.bind(this)
this.packageOrder = this.packageOrder.bind(this)
this.presentError = this.presentError.bind(this)
this.shipOrder = this.shipOrder.bind(this)
}
addWidget() {
......@@ -49,6 +52,7 @@ class App extends Component {
const newWidget = { created: Date.now() }
const newWidgetsInventory = [].concat(this.state.widgets, newWidget)
newState.error = null
newState.widgets = newWidgetsInventory
} else {
newState.failed = this.state.failed += 1
......@@ -74,6 +78,7 @@ class App extends Component {
const { materials } = this.state
const { dowel, screw, wheel } = materials
this.setState(Object.assign({}, this.state, {
error: null,
materials: {
dowel: { count: dowel.count + 10 },
screw: { count: screw.count + 10 },
......@@ -87,10 +92,15 @@ class App extends Component {
const newOrders = [].concat(orders)
const order = newOrders.pop()
if (order.widgets <= widgets.length) {
const newWidgets = widgets
for (var i=0; i < order.widgets; i++) {
newWidgets.shift()
}
this.setState({
error: null,
orders: newOrders,
packaged: packaged + 1,
widgets: widgets - order.widgets
widgets: newWidgets
})
} else {
this.presentError("Not enough widgets to fill order!")
......@@ -106,8 +116,17 @@ class App extends Component {
return check < 7
}
shipOrder() {
const { packaged, shipped } = this.state
this.setState({
error: null,
packaged: packaged - 1,
shipped: shipped + 1
})
}
render() {
const { error, failed, materials, orders, packaged, widgets } = this.state
const { error, failed, materials, orders, packaged, shipped, widgets } = this.state
return (
<div>
<Header />
......@@ -122,6 +141,7 @@ class App extends Component {
<QA failed={failed} />
<Inventory widgets={widgets} />
<Packaging orders={orders} packaged={packaged} packageOrder={this.packageOrder} />
<Shipping packaged={packaged} shipped={shipped} shipOrder={this.shipOrder} />
<Management orderMaterials={this.orderMaterials} />
</div>
);
......
import React, { Component } from 'react';
class Shipping extends Component {
render() {
const { packaged, shipped, shipOrder } = this.props
return (
<div>
<h2>Shipping</h2>
<h4>{shipped} orders shipped</h4>
{packaged ? <button onClick={shipOrder}>Ship order</button> : <h4>No orders to ship</h4>}
</div>
);
}
}
export default Shipping;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment