import { useEffect, useState } from "react"; import { getCategories, removeCategory } from "../api/admin"; import { MdDelete } from "react-icons/md"; import Pagination from "../components/Pagination"; import { IoAddCircleSharp } from "react-icons/io5"; import CategoryForm from "../components/CategoryForm"; export default function CategoryDashboard() { const [categories, setCategories] = useState([]); const [total, setTotal] = useState(0); const [currentPage, setCurrentPage] = useState(1); let pageLimit = 10; const [visible, setVisible] = useState(false); const onChangePage = (page, limit = 10) => { setCurrentPage(page); fetchCategory(page, limit); }; const fetchCategory = (page = 1, limit = 10) => { getCategories(page, limit).then(({ data, total }) => { setCategories(data); setTotal(total); }); }; const notiChange = () => { fetchCategory(currentPage); }; const handleToggleForm = () => { setVisible((curr) => !curr); }; const handleRemove = (id) => { removeCategory(id) .then(() => { fetchCategory(currentPage); }) .catch((err) => { console.log(err); }); }; //Get user when initialize the component useEffect(fetchCategory, []); return (
| CategoryID | Name | Action |
|---|---|---|
| {category.CategoryID} | {category.Name} |
|
No category exists!
)}