Commit 6b3ca2fc by Kristian Freeman

Package orders

parent 0c674133
......@@ -4,9 +4,11 @@ import "./normalize.css"
import Inventory from './Inventory'
import Materials from './Materials'
import Management from './Management'
import Manufacturing from './Manufacturing'
import Orders from './Orders'
import QA from './QA'
import Packaging from './Packaging'
const Header = () => <img className="logo" src="/logo.png" />
const Error = (props) => <h4>{props.message}</h4>
......@@ -24,31 +26,17 @@ class App extends Component {
screw: { count: 8 },
wheel: { count: 3 }
},
packaged: 0,
widgets: []
}
this.addWidget = this.addWidget.bind(this)
this.generateOrder = this.generateOrder.bind(this)
this.orderMaterials = this.orderMaterials.bind(this)
this.packageOrder = this.packageOrder.bind(this)
this.presentError = this.presentError.bind(this)
}
qaCheck() {
const check = Math.floor(Math.random() * 10)
return check < 7
}
generateOrder() {
const newOrder = {
created: Date.now(),
widgets: Math.floor(Math.random() * 10) + 1
}
const newOrders = [].concat(this.state.orders, newOrder)
const newState = Object.assign({}, this.state, {
orders: newOrders
})
this.setState(newState)
}
addWidget() {
const newMaterials = this.state.materials
newMaterials.dowel.count -= 1
......@@ -70,12 +58,56 @@ class App extends Component {
this.setState(Object.assign({}, this.state, newState))
}
generateOrder() {
const newOrder = {
created: Date.now(),
widgets: Math.floor(Math.random() * 10) + 1
}
const newOrders = [].concat(this.state.orders, newOrder)
const newState = Object.assign({}, this.state, {
orders: newOrders
})
this.setState(newState)
}
orderMaterials() {
const { materials } = this.state
const { dowel, screw, wheel } = materials
this.setState(Object.assign({}, this.state, {
materials: {
dowel: { count: dowel.count + 10 },
screw: { count: screw.count + 10 },
wheel: { count: wheel.count + 10 }
}
}))
}
packageOrder() {
const { orders, packaged, widgets } = this.state
const newOrders = [].concat(orders)
const order = newOrders.pop()
if (order.widgets <= widgets.length) {
this.setState({
orders: newOrders,
packaged: packaged + 1,
widgets: widgets - order.widgets
})
} else {
this.presentError("Not enough widgets to fill order!")
}
}
presentError(message) {
this.setState(Object.assign({}, this.state, { error: message }))
}
qaCheck() {
const check = Math.floor(Math.random() * 10)
return check < 7
}
render() {
const { error, failed, materials, orders, widgets } = this.state
const { error, failed, materials, orders, packaged, widgets } = this.state
return (
<div>
<Header />
......@@ -89,6 +121,8 @@ class App extends Component {
/>
<QA failed={failed} />
<Inventory widgets={widgets} />
<Packaging orders={orders} packaged={packaged} packageOrder={this.packageOrder} />
<Management orderMaterials={this.orderMaterials} />
</div>
);
}
......
import React, { Component } from 'react';
class Management extends Component {
render() {
return (
<div>
<h2>Management</h2>
<button onClick={this.props.orderMaterials}>Order raw materials</button>
</div>
);
}
}
export default Management;
import React, { Component } from 'react';
class Packaging extends Component {
render() {
const { orders, packageOrder, packaged } = this.props
return (
<div>
<h2>Packaging</h2>
<h4>{packaged} orders packaged</h4>
{orders.length ? <button onClick={packageOrder}>Package order</button> : <h4>No orders to package</h4>}
</div>
);
}
}
export default Packaging;
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