|
@ -8,67 +8,55 @@ import { friendlySize } from '../Size'; |
|
|
import BikeModal from '../BikeModal'; |
|
|
import BikeModal from '../BikeModal'; |
|
|
import { fetchBikes, setBike } from '../../actions'; |
|
|
import { fetchBikes, setBike } from '../../actions'; |
|
|
|
|
|
|
|
|
const renderBikes = (bikes) => { |
|
|
|
|
|
console.log(bikes); |
|
|
|
|
|
const bikeRows = bikes.map(bike => ( |
|
|
|
|
|
<TableRow selectable={false} key={bike.id}> |
|
|
|
|
|
<TableRowColumn>{friendlySize(bike.size)}</TableRowColumn> |
|
|
|
|
|
<TableRowColumn>{bike.colour}</TableRowColumn> |
|
|
|
|
|
<TableRowColumn>{bike.make}</TableRowColumn> |
|
|
|
|
|
<TableRowColumn>{bike.serial_number}</TableRowColumn> |
|
|
|
|
|
<TableRowColumn>{bike.state}</TableRowColumn> |
|
|
|
|
|
<TableRowColumn>{bike.claimed_by}</TableRowColumn> |
|
|
|
|
|
<TableRowColumn><FlatButton label="Edit" primary /></TableRowColumn> |
|
|
|
|
|
</TableRow> |
|
|
|
|
|
)); |
|
|
|
|
|
return bikeRows; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class BikeTableComponent extends React.Component { |
|
|
class BikeTableComponent extends React.Component { |
|
|
constructor(props) { |
|
|
constructor(props) { |
|
|
super(props); |
|
|
super(props); |
|
|
|
|
|
|
|
|
this.state = { |
|
|
this.state = { |
|
|
bikes: [], |
|
|
|
|
|
bikeModal: { |
|
|
bikeModal: { |
|
|
open: false, |
|
|
open: false, |
|
|
bike: undefined, |
|
|
bike: undefined, |
|
|
editing: false, |
|
|
|
|
|
}, |
|
|
}, |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
this.handleEditBike = this.handleEditBike.bind(this); |
|
|
this.handleOpen = this.handleOpen.bind(this); |
|
|
|
|
|
this.renderBikes = this.renderBikes.bind(this); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
componentDidMount() { |
|
|
componentDidMount() { |
|
|
this.props.fetchBikes(); |
|
|
this.props.fetchBikes(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
handleEditBike(bike) { |
|
|
handleOpen(id) { |
|
|
this.setState({ |
|
|
this.setState({ |
|
|
...this.state, |
|
|
...this.state, |
|
|
bikeModal: { |
|
|
bikeModal: { |
|
|
|
|
|
...this.state.bikeModal, |
|
|
open: true, |
|
|
open: true, |
|
|
bike, |
|
|
bike: id, |
|
|
editing: true, |
|
|
|
|
|
}, |
|
|
}, |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
handleAddBike() { |
|
|
renderBikes(bikes) { |
|
|
this.setState({ |
|
|
const bikeRows = bikes.map(bike => ( |
|
|
...this.state, |
|
|
<TableRow selectable={false} key={bike.id}> |
|
|
bikeModal: { |
|
|
<TableRowColumn>{friendlySize(bike.size)}</TableRowColumn> |
|
|
open: true, |
|
|
<TableRowColumn>{bike.colour}</TableRowColumn> |
|
|
bike: {}, |
|
|
<TableRowColumn>{bike.make}</TableRowColumn> |
|
|
editing: false, |
|
|
<TableRowColumn>{bike.serial_number}</TableRowColumn> |
|
|
}, |
|
|
<TableRowColumn>{bike.state}</TableRowColumn> |
|
|
}); |
|
|
<TableRowColumn>{bike.claimed_by}</TableRowColumn> |
|
|
|
|
|
<TableRowColumn><FlatButton label="Edit" primary onTouchTap={(e) => this.handleOpen(bike.id)} /></TableRowColumn> |
|
|
|
|
|
</TableRow> |
|
|
|
|
|
)); |
|
|
|
|
|
|
|
|
|
|
|
return bikeRows; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
render() { |
|
|
render() { |
|
|
if (this.props.bikes.fetched) { |
|
|
if (this.props.bikes.fetched) { |
|
|
const bikeRows = renderBikes(Object.values(this.props.bikes.entities)); |
|
|
const bikeRows = this.renderBikes(Object.values(this.props.bikes.entities)); |
|
|
return ( |
|
|
return ( |
|
|
<div className="mdl-grid"> |
|
|
<div className="mdl-grid"> |
|
|
<div className="mdl-cell mdl-cell--12-col"> |
|
|
<div className="mdl-cell mdl-cell--12-col"> |
|
@ -98,6 +86,11 @@ class BikeTableComponent extends React.Component { |
|
|
</TableBody> |
|
|
</TableBody> |
|
|
</Table> |
|
|
</Table> |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
<BikeModal |
|
|
|
|
|
open={this.state.bikeModal.open} |
|
|
|
|
|
bike={this.state.bikeModal.bike} |
|
|
|
|
|
bikes={this.props.bikes.entities} |
|
|
|
|
|
/> |
|
|
</div> |
|
|
</div> |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
@ -114,9 +107,6 @@ const mapDispatchToProps = dispatch => ({ |
|
|
fetchBikes: () => { |
|
|
fetchBikes: () => { |
|
|
dispatch(fetchBikes()); |
|
|
dispatch(fetchBikes()); |
|
|
}, |
|
|
}, |
|
|
setBike: (id) => { |
|
|
|
|
|
dispatch(setBike(id)); |
|
|
|
|
|
}, |
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
const BikeTable = connect(mapStateToProps, mapDispatchToProps)(BikeTableComponent); |
|
|
const BikeTable = connect(mapStateToProps, mapDispatchToProps)(BikeTableComponent); |
|
|