import { useEffect, useState } from "react"; import { getProducts, removeProduct } from "../api/admin"; import { MdDelete } from "react-icons/md"; import Pagination from "../components/Pagination"; export default function ProductDashboard() { const [products, setProducts] = useState([]); const [total, setTotal] = useState(0); const [currentPage, setCurrentPage] = useState(1); let pageLimit = 10; const onChangePage = (page, limit = 10) => { setCurrentPage(page); fetchProducts(page, limit); }; const fetchProducts = (page = 1, limit = 10) => { getProducts(page, limit).then(({ products, total }) => { setTotal(total); setProducts(products); }); }; const handleRemoveProduct = (id) => { removeProduct(id) .then((res) => { fetchProducts(currentPage); }) .catch((err) => { console.log(err); }); }; //Get user when initialize the component useEffect(fetchProducts, []); return (
| ProductID | Name | Price | Category | Seller | Action |
|---|---|---|---|---|---|
| {product.ProductID} | {product.ProductName} | {product.Price} | {product.Category ? product.Category : "N/A"} | {product.SellerName ? product.SellerName : "N/A"} |
|
No product exists!
)}