Commit bf59eb91 authored by Ben Anderson's avatar Ben Anderson

Merge branch 'AFP-15' into dev

parents b3fda0f1 ec28b423
import React from "react"; import React from "react";
import ProductRow from "./ProductRow.jsx"; import ProductRow from "./ProductRow.jsx";
import { Table } from "react-bootstrap"; import { Table } from "react-bootstrap";
// import "./../styles/ProductTable.css"; import { deleteProduct } from "../actions/apiRequests";
export default class SearchResults extends React.Component { import { withRouter } from "react-router";
class SearchResults extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
results: this.props.history.location.state.results results: this.props.history.location.state.results
} }
this.handleDelete = this.handleDelete.bind(this);
}
handleDelete(sku){
deleteProduct(sku)
.then(() => {
const newResults = this.state.results.filter(product => product.sku !== sku);
this.setState({results: newResults});
this.props.history.push("/searchResults", this.state);
});
} }
render() { render() {
...@@ -31,7 +43,7 @@ export default class SearchResults extends React.Component { ...@@ -31,7 +43,7 @@ export default class SearchResults extends React.Component {
<tbody> <tbody>
{this.state.results.map((product) => { {this.state.results.map((product) => {
return ( return (
<ProductRow key={product.sku} product={product} /> <ProductRow key={product.sku} product={product} handleDelete={() => this.handleDelete(product.sku)} />
); );
})} })}
</tbody> </tbody>
...@@ -44,3 +56,5 @@ export default class SearchResults extends React.Component { ...@@ -44,3 +56,5 @@ export default class SearchResults extends React.Component {
} }
} }
export default withRouter(SearchResults);
\ No newline at end of file
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