-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// ProductPage.js | ||
import React, { useState, useEffect } from "react"; | ||
import { useParams } from "react-router-dom"; | ||
import { addAuthHeader } from "../Components/helpers"; | ||
|
||
function ProductPage() { | ||
const { id } = useParams(); | ||
const [product, setProduct] = useState(null); | ||
|
||
useEffect(() => { | ||
fetchProduct(id) | ||
.then((res) => { | ||
if (res) { | ||
setProduct(res); | ||
} else { | ||
setProduct(null); | ||
} | ||
}) | ||
.catch((error) => { | ||
console.log(error); | ||
}); | ||
}, [id]); | ||
|
||
function fetchProduct(id) { | ||
console.log(`Fetching product with id: ${id}`); | ||
return fetch(`http://localhost:8000/products/${id}`, { | ||
headers: addAuthHeader() | ||
}) | ||
.then((res) => { | ||
console.log("Response status:", res.status); | ||
if (res.status === 200) { | ||
return res.json(); | ||
} else { | ||
throw new Error("Failed to fetch product"); | ||
} | ||
}) | ||
.catch((error) => { | ||
console.error("Error fetching product:", error); | ||
}); | ||
} | ||
|
||
if (!product) { | ||
return ( | ||
<div className="container"> | ||
<li> | ||
<img className="ProductPageLogo" src="../assets/yes.png" alt="Loading" /> | ||
</li> | ||
Loading... | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div> | ||
<li> | ||
<img className="ProductPageLogo" src="../assets/yes.png" alt="Loading" /> | ||
</li> | ||
<div className="subtitle-container"> | ||
<h2 className="subtitle">Your Product: {product.product}</h2> | ||
</div> | ||
<h1 className="edit-product-title">Edit Product</h1> | ||
<form> | ||
<div className="input-container"> | ||
<label>Product Name:</label> | ||
<input type="text" value={product.product} readOnly /> | ||
</div> | ||
<div className="input-container"> | ||
<label>Quantity:</label> | ||
<input type="number" value={product.quantity} readOnly /> | ||
</div> | ||
<div className="input-container"> | ||
<label>Price:</label> | ||
<input type="number" value={product.price} readOnly /> | ||
</div> | ||
</form> | ||
</div> | ||
); | ||
} | ||
|
||
export default ProductPage; |
eb316aa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is a pull request for a new Product Page for each specific product. There is a logo on the front and a table listing each product's price, name, and quantity.