DeleteProduct JSX
DeleteProduct JSX
import "./DeleteProduct.css";
await fetch(`http://localhost:4000/deleteproduct/${selectedProduct}`, {
method: "DELETE",
headers: {
Accept: "application/json",
},
})
.then((resp) => resp.json())
.then((data) =>
data.success ? alert("Product Deleted") : alert("Failed to delete product")
);
return (
<div className="deleteproduct">
<div className="deleteproduct-itemfield">
<p>Select Product to Delete</p>
<select
value={selectedProduct}
onChange={(e) => setSelectedProduct(e.target.value)}
className="delete-product-selector"
>
<option value="">Select a product</option>
{products.map((product) => (
<option key={product._id} value={product._id}>
{product.name}
</option>
))}
</select>
</div>
<button className="deleteproduct-btn" onClick={deleteProduct}>
DELETE
</button>
</div>
);
};