Commit 0c674133 by Kristian Freeman

Generate orders

parent 40aaf8a3
......@@ -5,6 +5,7 @@ import "./normalize.css"
import Inventory from './Inventory'
import Materials from './Materials'
import Manufacturing from './Manufacturing'
import Orders from './Orders'
import QA from './QA'
const Header = () => <img className="logo" src="/logo.png" />
......@@ -17,6 +18,7 @@ class App extends Component {
this.state = {
error: null,
failed: 0,
orders: [],
materials: {
dowel: { count: 2 },
screw: { count: 8 },
......@@ -26,6 +28,7 @@ class App extends Component {
}
this.addWidget = this.addWidget.bind(this)
this.generateOrder = this.generateOrder.bind(this)
this.presentError = this.presentError.bind(this)
}
......@@ -34,6 +37,18 @@ class App extends Component {
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
......@@ -60,11 +75,12 @@ class App extends Component {
}
render() {
const { error, failed, materials, widgets } = this.state
const { error, failed, materials, orders, widgets } = this.state
return (
<div>
<Header />
{error ? <Error message={error} /> : null}
<Orders generateOrder={this.generateOrder} orders={orders} />
<Materials materials={materials} />
<Manufacturing
addWidget={this.addWidget}
......
import React, { Component } from 'react';
class Orders extends Component {
render() {
const { generateOrder, orders } = this.props
return (
<div>
<h2>Orders</h2>
<h3>{orders.length} orders</h3>
<ul>
{orders.map(order => <li key={order.created}>Order for {order.widgets} widgets</li>)}
</ul>
<button onClick={generateOrder}>Generate order</button>
</div>
)
}
}
export default Orders;
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