diff --git a/frontend/src/AgroShopAI/pages/CategoryPage.jsx b/frontend/src/AgroShopAI/pages/CategoryPage.jsx
index 98203d04..c806cd52 100644
--- a/frontend/src/AgroShopAI/pages/CategoryPage.jsx
+++ b/frontend/src/AgroShopAI/pages/CategoryPage.jsx
@@ -4,18 +4,27 @@ import Filter from "../components/Filter";
import { useParams } from 'react-router-dom';
import Preloader from "../../components/PreLoader";
import { useAuth } from "../../context/AuthContext";
+import NotFound from "../../NotFound";
+import { categories } from "../utils/home-data";
const CategoryPage = () => {
const { isLoggedIn, userData } = useAuth();
+ const [wrongURL, setWrongURL] =useState(false);
const [items, setItems] = useState([]); // State to store fetched items
const [filteredItems, setFilteredItems] = useState([]); // State for filtered items
const [loading, setLoading] = useState(true); // State for loading status
const [wishlist, setWishlist] = useState([]);
const [wishlistLoading, setWishlistLoading] = useState(true);
- const { id } = useParams();
+
+ // Using name instead of Id for test purpose.
+ const {name} = useParams();
+ let id;
let url = '';
if (id) {
+ // Add Data to collection and use that Id here
url = `${import.meta.env.VITE_BACKEND_BASE_URL}api/products/category/${id}`;
} else {
+ /* Fetching every product for development phase
+ Remove it after setting up db locally */
url = `${import.meta.env.VITE_BACKEND_BASE_URL}api/products/`;
}
@@ -25,7 +34,7 @@ const CategoryPage = () => {
setLoading(true); // Set loading to true before fetching
const response = await fetch(url); // Replace with your API URL
const data = await response.json();
-
+ console.log(data)
// Flatten data to include each variant as a separate item
const flattenedData = data.flatMap(item =>
item.variants.map(variant => ({
@@ -39,6 +48,7 @@ const CategoryPage = () => {
setFilteredItems(flattenedData); // Set initial filtered items
} catch (error) {
console.error("Failed to fetch items:", error);
+ setWrongURL(true);
} finally {
setLoading(false); // Set loading to false after fetching
}
@@ -62,7 +72,9 @@ const CategoryPage = () => {
fetchData(); // Fetch data when the component mounts
fetchWishlist();
}, [id]);
-
+ if(wrongURL){
+ return
+ }
// Display loader while fetching data
if (loading || wishlistLoading) {
return
category.alias === name)?.banner || null}
+
alt=""
/>
diff --git a/frontend/src/AgroShopAI/utils/home-data.js b/frontend/src/AgroShopAI/utils/home-data.js
index 2aa65352..d05151e5 100644
--- a/frontend/src/AgroShopAI/utils/home-data.js
+++ b/frontend/src/AgroShopAI/utils/home-data.js
@@ -2,55 +2,76 @@ export const categories = [
{
title: "Herbicides",
image: "https://github.com/IkkiOcean/AgroTech_Assets/blob/main/shop-asset/category-img/herbicide.jpg?raw=true",
- id: "" // Empty string for id
+ banner: "https://raw.githubusercontent.com/IkkiOcean/AgroTech_Assets/refs/heads/main/shop-asset/category_page/herbicide.png",
+ id: "",
+ alias: "herbicides"
},
{
title: "Growth Promoters",
image: "https://github.com/IkkiOcean/AgroTech_Assets/blob/main/shop-asset/category-img/growth_promoters.jpg?raw=true",
- id: "67154de8c99a7d1729a431ba" // ID for Growth Promoters
+ banner: "https://raw.githubusercontent.com/IkkiOcean/AgroTech_Assets/refs/heads/main/shop-asset/category_page/growth_promoters.png",
+ id: "67154de8c99a7d1729a431ba",
+ alias: "growth"
},
{
title: "Fungicides",
image: "https://github.com/IkkiOcean/AgroTech_Assets/blob/main/shop-asset/category-img/fungicides.jpg?raw=true",
- id: "" // Empty string for id
+ banner : "https://raw.githubusercontent.com/IkkiOcean/AgroTech_Assets/refs/heads/main/shop-asset/category_page/fungicide.png",
+ id: "",
+ alias: "fungicides"
},
{
title: "Vegetable & Fruit Seeds",
image: "https://github.com/IkkiOcean/AgroTech_Assets/blob/main/shop-asset/category-img/seeds.jpg?raw=true",
- id: "67154da7c99a7d1729a431b8" // ID for Vegetable & Fruit Seeds
+ banner: "https://raw.githubusercontent.com/IkkiOcean/AgroTech_Assets/refs/heads/main/shop-asset/category_page/Seeds.png",
+ id: "67154da7c99a7d1729a431b8",
+ alias: "seeds"
},
{
title: "Farm Machinery",
image: "https://github.com/IkkiOcean/AgroTech_Assets/blob/main/shop-asset/category-img/machine.jpg?raw=true",
- id: "" // Empty string for id
+ banner: "https://raw.githubusercontent.com/IkkiOcean/AgroTech_Assets/refs/heads/main/shop-asset/category_page/farm_machinery.png",
+ id: "",
+ alias: "machinery"
},
{
title: "Nutrients",
image: "https://github.com/IkkiOcean/AgroTech_Assets/blob/main/shop-asset/category-img/nutrient.jpg?raw=true",
- id: "" // Empty string for id
+ banner: "https://raw.githubusercontent.com/IkkiOcean/AgroTech_Assets/refs/heads/main/shop-asset/category_page/nutrient.png",
+ id: "",
+ alias: "nutrients"
},
{
title: "Insecticide",
image: "https://github.com/IkkiOcean/AgroTech_Assets/blob/main/shop-asset/category-img/insecticide.jpg?raw=true",
- id: "" // Empty string for id
+ banner : "https://raw.githubusercontent.com/IkkiOcean/AgroTech_Assets/refs/heads/main/shop-asset/category_page/insecticide.png",
+ id: "",
+ alias: "insecticide"
},
{
title: "Organic Farming",
image: "https://github.com/IkkiOcean/AgroTech_Assets/blob/main/shop-asset/category-img/organic.jpg?raw=true",
- id: "" // Empty string for id
+ banner: "https://raw.githubusercontent.com/IkkiOcean/AgroTech_Assets/refs/heads/main/shop-asset/category_page/organic.png",
+ id: "",
+ alias: "organic"
},
{
title: "Animal Husbandry",
image: "https://github.com/IkkiOcean/AgroTech_Assets/blob/main/shop-asset/category-img/animal.jpg?raw=true",
- id: "" // Empty string for id
+ banner: "https://raw.githubusercontent.com/IkkiOcean/AgroTech_Assets/refs/heads/main/shop-asset/category_page/animal_husbandary.png",
+ id: "",
+ alias: "animal"
},
{
title: "New Products",
image: "https://github.com/IkkiOcean/AgroTech_Assets/blob/main/shop-asset/category-img/new.jpg?raw=true",
- id: "" // Empty string for id
+ banner: "https://raw.githubusercontent.com/IkkiOcean/AgroTech_Assets/refs/heads/main/shop-asset/category_page/new_product.png",
+ id: "",
+ alias: "new"
}
];
+
export const topSellingItems = [
{
title: "Roundup Weed Killer",
diff --git a/frontend/src/MainContent.jsx b/frontend/src/MainContent.jsx
index d48e4c00..ef36a4d7 100644
--- a/frontend/src/MainContent.jsx
+++ b/frontend/src/MainContent.jsx
@@ -137,7 +137,7 @@ const MainContent = () => {
{/* AgroShopAI Routes */}
} />
} />
- } />
+ } />
}/>
} />
} />