Commit 40aaf8a3 by Kristian Freeman

QA check widgets

parent eaa8494c
......@@ -5,6 +5,7 @@ import "./normalize.css"
import Inventory from './Inventory'
import Materials from './Materials'
import Manufacturing from './Manufacturing'
import QA from './QA'
const Header = () => <img className="logo" src="/logo.png" />
const Error = (props) => <h4>{props.message}</h4>
......@@ -15,6 +16,7 @@ class App extends Component {
this.state = {
error: null,
failed: 0,
materials: {
dowel: { count: 2 },
screw: { count: 8 },
......@@ -27,20 +29,30 @@ class App extends Component {
this.presentError = this.presentError.bind(this)
}
qaCheck() {
const check = Math.floor(Math.random() * 10)
return check < 7
}
addWidget() {
const newState = {}
const newMaterials = this.state.materials
newMaterials.dowel.count -= 1
newMaterials.screw.count -= 2
newMaterials.wheel.count -= 2
const newWidget = { created: Date.now() }
const newWidgetsInventory = [].concat(this.state.widgets, newWidget)
let newState = { materials: newMaterials }
if (this.qaCheck()) {
const newWidget = { created: Date.now() }
const newWidgetsInventory = [].concat(this.state.widgets, newWidget)
newState.widgets = newWidgetsInventory
} else {
newState.failed = this.state.failed += 1
newState.error = "A widget failed QA!"
}
this.setState(Object.assign({}, this.state, {
materials: newMaterials,
widgets: newWidgetsInventory
}))
this.setState(Object.assign({}, this.state, newState))
}
presentError(message) {
......@@ -48,7 +60,7 @@ class App extends Component {
}
render() {
const { error, materials, widgets } = this.state
const { error, failed, materials, widgets } = this.state
return (
<div>
<Header />
......@@ -59,6 +71,7 @@ class App extends Component {
materials={materials}
presentError={this.presentError}
/>
<QA failed={failed} />
<Inventory widgets={widgets} />
</div>
);
......
import React, { Component } from 'react';
class QA extends Component {
render() {
return (
<div>
<h2>QA</h2>
<h4>{this.props.failed} widgets failed QA</h4>
</div>
);
}
}
export default QA;
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