Commit 227fb9ee authored by Khai Yuan ​Liew's avatar Khai Yuan ​Liew

[AFP-15] Start work on Delete product functionality

parent 7803e712
......@@ -5,4 +5,11 @@ export const getAllProducts = async data => {
const res = await axios.get(`${Config.inventoryUrl}`);
// console.log(res.data);
return res.data;
}
export const deleteProduct = async (sku) => {
await axios.delete(`${Config.inventoryUrl}/${sku}`)
.then(() => {
return await axios.get(`${Config.inventoryUrl}`);
});
}
\ No newline at end of file
import React, { useState } from "react";
import "./../styles/Product.css";
import { Modal, Button, Alert } from "react-bootstrap";
import { deleteProduct } from "../actions/apiRequests";
export default function Product({ product }) {
const [show, setShow] = useState(false);
......@@ -10,6 +11,16 @@ export default function Product({ product }) {
setShow(false);
handleCloseConfirm();
};
const handleDelete = (sku) => {
deleteProduct(sku)
.then(res => {
const products = res.data;
this.setState({products});
});
}
const handleShow = () => setShow(true);
const handleShowConfirm = () => setShowConfirm(true);
const handleCloseConfirm = () => setShowConfirm(false);
......@@ -66,7 +77,7 @@ export default function Product({ product }) {
Cancel
</Button>
&nbsp;&nbsp;
<Button variant="danger">Yes, delete</Button>
<Button variant="danger" onClick={handleDelete(product.sku)}>Yes, delete</Button>
</Alert>
</Modal.Footer>
</Modal>
......
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