diff --git a/client/src/Services/bodyServices.js b/client/src/Services/bodyServices.js index 950d103..c18b823 100644 --- a/client/src/Services/bodyServices.js +++ b/client/src/Services/bodyServices.js @@ -1,8 +1,8 @@ import thaliaAPI from "../API/thaliaAPI"; -export const getTopics = async () => { +export const getTopics = async (page) => { try { - const response = await thaliaAPI.get("/admin/my-body", { withCredentials: true }); + const response = await thaliaAPI.get(`/admin/my-body?page=${page}`, { withCredentials: true }); return response.data; } catch (error) { return error; diff --git a/client/src/Services/rightServices.js b/client/src/Services/rightServices.js index 4056d45..7005fb5 100644 --- a/client/src/Services/rightServices.js +++ b/client/src/Services/rightServices.js @@ -1,37 +1,48 @@ import thaliaAPI from "../API/thaliaAPI"; export const createRight = async (rightDetails) => { - try { - const response = await thaliaAPI.post("/admin/rights", rightDetails, { withCredentials: true }); - return response.data; - } catch (error) { - return error; - } -} + try { + const response = await thaliaAPI.post("/admin/rights", rightDetails, { + withCredentials: true, + }); + return response.data; + } catch (error) { + return error; + } +}; export const editRight = async (rightDetails, rightId) => { - try { - const response = await thaliaAPI.put(`/admin/rights/${rightId}`, rightDetails, { withCredentials: true }); - return response.data; - } catch (error) { - return error; - } -} -export const getRight = async () => { - try { - const response = await thaliaAPI.get('/admin/rights', {}, { withCredentials: true }); - return response.data; - } catch (error) { - return error; - } -} + try { + const response = await thaliaAPI.put( + `/admin/rights/${rightId}`, + rightDetails, + { withCredentials: true } + ); + return response.data; + } catch (error) { + return error; + } +}; +export const getRight = async (page) => { + try { + const response = await thaliaAPI.get( + `/admin/rights?page=${page}`, + {}, + { withCredentials: true } + ); + return response.data; + } catch (error) { + return error; + } +}; export const getDelete = async (rightId) => { - try { - const response = await thaliaAPI.delete(`/admin/rights/${rightId}`, {}, { withCredentials: true }); - return response.data; - } catch (error) { - return error; - } -} - - - + try { + const response = await thaliaAPI.delete( + `/admin/rights/${rightId}`, + {}, + { withCredentials: true } + ); + return response.data; + } catch (error) { + return error; + } +}; diff --git a/client/src/pages/AdminPages/MyBody/MyBody.jsx b/client/src/pages/AdminPages/MyBody/MyBody.jsx index 4c0ad6b..7287075 100644 --- a/client/src/pages/AdminPages/MyBody/MyBody.jsx +++ b/client/src/pages/AdminPages/MyBody/MyBody.jsx @@ -5,10 +5,14 @@ import { getTopics } from "../../../Services/bodyServices"; import { deleteBody } from "../../../Services/bodyServices"; import timeFormat from "../../../utils/timeFormat"; import { toast } from "react-toastify"; +import { Pagination } from "flowbite-react"; +import Swal from "sweetalert2"; function MyBody() { const [openModal, setOpenModal] = useState(false); const [bodyDeatails, setBodyDetails] = useState([]); + const [currentPage, setCurrentPage] = useState(1); + const [count, setCount] = useState(0); const [editBody, setEditBody] = useState(); const [editModal, setEditModal] = useState(false); @@ -16,6 +20,7 @@ function MyBody() { const handleModal = () => { setOpenModal(true); }; + const onPageChange = (page) => setCurrentPage(page); const handleEditModal = (bodyId) => { setEditModal(true); const bodyToEdit = bodyDeatails.find((body) => { @@ -25,9 +30,10 @@ function MyBody() { }; useEffect(() => { const getData = async () => { - const response = await getTopics(); + const response = await getTopics(currentPage); if (response.success === true) { setBodyDetails(response.contents); + setCount(response.count) } }; getData(); @@ -38,6 +44,7 @@ function MyBody() { setEditModal, editModal, setEditBody, + currentPage ]); const handleDelete = async (bodyId) => { const response = await deleteBody(bodyId); @@ -115,7 +122,18 @@ function MyBody() { @@ -127,6 +145,15 @@ function MyBody() { })} +
+ {count > 10 && ( + + )} +
diff --git a/client/src/pages/AdminPages/Rights/Rights.jsx b/client/src/pages/AdminPages/Rights/Rights.jsx index 3228639..97fc53e 100644 --- a/client/src/pages/AdminPages/Rights/Rights.jsx +++ b/client/src/pages/AdminPages/Rights/Rights.jsx @@ -5,6 +5,8 @@ import { getRight } from "../../../Services/rightServices"; import { getDelete } from "../../../Services/rightServices"; import timeFormat from "../../../utils/timeFormat"; import { toast } from "react-toastify"; +import { Pagination } from "flowbite-react"; +import Swal from "sweetalert2"; function Rights() { const [openModal, setOpenModal] = useState(false); @@ -12,6 +14,10 @@ function Rights() { const [editRight, setEditRight] = useState(); const [editModal, setEditModal] = useState(false); + const [currentPage, setCurrentPage] = useState(1); + const [count, setCount] = useState(0); + + const onPageChange = (page) => setCurrentPage(page); const handleModal = () => { setOpenModal(true); @@ -25,8 +31,11 @@ function Rights() { }; useEffect(() => { const getRights = async () => { - const response = await getRight(); - setRightDetails(response.rights); + const response = await getRight(currentPage); + if (response.success) { + setRightDetails(response.rights); + setCount(response.count); + } }; getRights(); }, [ @@ -36,6 +45,7 @@ function Rights() { editModal, setRightDetails, setEditRight, + currentPage, ]); const handleDelete = async (rightId) => { const response = await getDelete(rightId); @@ -72,60 +82,79 @@ function Rights() { {/* Table Component */}
- <> - - - - - - - - - - {rightDetails.map((right, index) => { - return ( - <> - - - - - - - - - - ); - })} -
- No - - Name - - Date - - Edit or Delete -
- {index + 1} - {right?.name} - {timeFormat(right?.createdAt)} - - - -
- + + + + + + + + + + {rightDetails.map((right, index) => { + return ( + <> + + + + + + + + + + ); + })} +
+ No + + Name + + Date + + Edit or Delete +
+ {index + 1} + {right?.name} + {timeFormat(right?.createdAt)} + + + +
+ +
+ {count > 0 && ( + + )} +