diff --git a/frontend/src/app/dashboard/page.tsx b/frontend/src/app/dashboard/page.tsx index 020bad7..9752d7a 100644 --- a/frontend/src/app/dashboard/page.tsx +++ b/frontend/src/app/dashboard/page.tsx @@ -1,6 +1,6 @@ 'use client'; import Image from 'next/image'; -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import { BsFillXDiamondFill } from 'react-icons/bs'; import { HiMenuAlt3 } from 'react-icons/hi'; import { IoSearchOutline, IoSettingsOutline } from 'react-icons/io5'; @@ -13,6 +13,16 @@ import { toast } from 'react-toastify'; import 'react-toastify/dist/ReactToastify.css'; import DatePicker from 'react-datepicker'; import 'react-datepicker/dist/react-datepicker.css'; +import { getRegisteredProductsByManufacturer } from '@/services/apiService'; + +type ProductDetails = { + product_id: string; + name: string; + image: string; + manufacturer: string; + manufactureDate: string; + expiryDate: string; +}; const AddProductModal = ({ isOpen, @@ -182,6 +192,30 @@ const Dashboard = () => { const [isModalOpen, setModalOpen] = useState(false); const [activePage, setActivePage] = useState(1); const [activeMenu, setActiveMenu] = useState('menu'); + const [products, setProducts] = useState([]); + const [loading, setLoading] = useState(true); + const manufacturerId = '12'; + + useEffect(() => { + const fetchProducts = async () => { + try { + setLoading(true); + const fetchedProducts = + await getRegisteredProductsByManufacturer(manufacturerId); + if (fetchedProducts) { + setProducts(fetchedProducts); + } + } catch (err) { + console.error('Error fetching products:', err); + } finally { + setLoading(false); + } + }; + + if (manufacturerId) { + fetchProducts(); + } + }, [manufacturerId]); const handlePageClick = (page: React.SetStateAction) => { setActivePage(page); @@ -274,77 +308,85 @@ const Dashboard = () => { - - - - + + + + + + - {Array.from({ length: 10 }).map((_, idx) => ( - - - - - - - ))} + {products && products.length > 0 ? ( + <> + {products.map((product, idx) => ( + + + + + + + + + ))} + + ) : ( +
No products found.
+ )}
ChecksDatesRoleDescriptionIDNameImage + Manufacturer + + Manufactured Date + Expiry Date
- - Avatar - - Take recent orders on Jumia - - - August 23, 2023 - - Avatar - Doris K. John - -

. Required to look up items on Jumia

-

. Select required item and place

-
+ {product.product_id} + + {product.name} + + product image + +

{product.manufacturer}

+
+

{product.manufactureDate}

+
+

{product.expiryDate}

+
-
- - {[1, 2, 3, 4, 5].map((page) => ( - - ))} - -
+ {[1, 2, 3, 4, 5].map((page) => ( + + ))} + + + )} ); diff --git a/frontend/src/services/apiService.ts b/frontend/src/services/apiService.ts index a61b39e..2eb53a4 100644 --- a/frontend/src/services/apiService.ts +++ b/frontend/src/services/apiService.ts @@ -55,3 +55,18 @@ export const fetchProductDetails = async (productId: string) => { throw error; } }; + +const BASE_URL = process.env.BACKEND_BASE_URL || 'http://localhost:3000'; + +export const getRegisteredProductsByManufacturer = async ( + manufacturerId: string +) => { + try { + const response = await fetch( + `${BASE_URL}/manufacturer-products/${manufacturerId}` + ); + return await response.json(); + } catch (error) { + console.error('Error fetching product details:', error); + } +};