+
navigate(`/products/${id}`)} key={id}>
-
![]()
+
-
+
{title}
-
Price:
-
Rating:
-
Category:
+
Price: {price}
+
Rating: {rate}
+
Category: {category}
diff --git a/src/components/ui-elements/Navbar.tsx b/src/components/ui-elements/Navbar.tsx
index 5dd37fb..25e3d21 100644
--- a/src/components/ui-elements/Navbar.tsx
+++ b/src/components/ui-elements/Navbar.tsx
@@ -21,7 +21,7 @@ const Navbar: React.FC = () => {
);
}
-
return (
<>
@@ -56,8 +95,15 @@ const Home: React.FC = () => {
-
- {/* TODO - map products */}
+
+ {products.map((product: Product) => (
+
+ ))}
+
diff --git a/src/pages/NotFound.tsx b/src/pages/NotFound.tsx
new file mode 100644
index 0000000..14dce1c
--- /dev/null
+++ b/src/pages/NotFound.tsx
@@ -0,0 +1,16 @@
+import Navbar from "../components/ui-elements/Navbar";
+
+function NotFound() {
+ return (
+ <>
+
+
+
404 - Page Not Found
+
Sorry, the page you are looking for does not exist.
+
+ >
+ );
+}
+
+export default NotFound;
+
diff --git a/src/pages/ProductPage.tsx b/src/pages/ProductPage.tsx
new file mode 100644
index 0000000..1bc2ba0
--- /dev/null
+++ b/src/pages/ProductPage.tsx
@@ -0,0 +1,93 @@
+import React, {useEffect, useState} from 'react';
+import axios from 'axios';
+import '../assets/css/common.css';
+import '../assets/css/main.css';
+import '../assets/css/product-page.css';
+import Navbar from '../components/ui-elements/Navbar';
+import Loading from '../components/ui-elements/Loading';
+import { useParams } from 'react-router-dom';
+import { Product } from '../types';
+
+
+const ProductPage: React.FC = () => {
+ const { id } = useParams<{ id: string }>();
+ const [product, setProduct] = useState(null);
+ const [loading, setLoading] = useState(true);
+ const [error, setError] = useState(null);
+
+ useEffect(() => {
+ const fetchProduct = async () => {
+ try {
+ const response = await axios.get(`https://fakestoreapi.com/products/${id}`);
+ console.log(response.data);
+ setProduct(response.data);
+ setLoading(false);
+ }
+ catch(error:any) {
+ setError(error.message)
+ setLoading(false);
+ }
+ }
+ fetchProduct();
+ }, [id]);
+ if (loading) {
+ return ;
+ }
+ if (error || !product) {
+ return (
+
+ );
+ }
+ return (
+ <>
+
+
+
+
+
+
+
+

+
+
+
+
+
{product.title}
+
+
+ Category: {product.category}
+
+
+
+ ${product.price}
+ {product.rating && (
+
+ ⭐ {product.rating.rate} ({product.rating.count} reviews)
+
+ )}
+
+
+
+ {product.description}
+
+
+
+
+
+
+
+
+
+
+
+ >
+ );
+};
+
+export default ProductPage;
\ No newline at end of file
diff --git a/src/types.ts b/src/types.ts
index 1e3d610..effde33 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -1,11 +1,22 @@
-export interface Rating {
-//TODO
-}
+// export interface Rating {
+// count: number;
+// rate: number;
+// }
export interface Product {
-//TODO
+ title: string;
+ category: string;
+ description: string;
+ id: string;
+ image: string;
+ price: number;
+ rating:{
+ rate: number;
+ count: number;
+ }
}
export interface Category {
-//TODO
+ id: string;
+ name: string;
}