Fixed pagination styling

This commit is contained in:
Daniel Cojocea committed 2024-08-08 19:27:28 -04:00
1 parent 7e30be9085
commit 6d5cc931d0
2 files changed
+40 -22

No files matched your search

@@ -80,7 +80,7 @@ export const updatePageSpeed = createAsyncThunk(
// notifications: monitor.notifications, // notifications: monitor.notifications,
}; };
const res = await axiosInstance.put( const res = await axiosInstance.put(
`/monitors/edit/${monitor._id}`, `/monitors/${monitor._id}`,
updatedFields, updatedFields,
{ {
headers: { headers: {
@@ -8,12 +8,17 @@ import {
TableBody, TableBody,
TableFooter, TableFooter,
TablePagination, TablePagination,
PaginationItem,
Pagination,
Paper,
} from "@mui/material"; } from "@mui/material";
import { useState, useEffect } from "react"; import { useState, useEffect } from "react";
import { useSelector } from "react-redux"; import { useSelector } from "react-redux";
import axiosInstance from "../../../../Utils/axiosConfig"; import axiosInstance from "../../../../Utils/axiosConfig";
import { StatusLabel } from "../../../../Components/Label"; import { StatusLabel } from "../../../../Components/Label";
import ArrowBackRoundedIcon from "@mui/icons-material/ArrowBackRounded";
import ArrowForwardRoundedIcon from "@mui/icons-material/ArrowForwardRounded";
const PaginationTable = ({ monitorId, filter }) => { const PaginationTable = ({ monitorId, filter }) => {
const { authToken } = useSelector((state) => state.auth); const { authToken } = useSelector((state) => state.auth);
@@ -53,20 +58,43 @@ const PaginationTable = ({ monitorId, filter }) => {
const handlePageChange = (_, newPage) => { const handlePageChange = (_, newPage) => {
setPaginationController({ setPaginationController({
...paginationController, ...paginationController,
page: newPage, page: newPage - 1,
}); });
}; };
const handleChangeRowsPerPage = (event) => { let paginationComponent = <></>;
setPaginationController({ if (checksCount > paginationController.rowsPerPage) {
...paginationController, paginationComponent = (
rowsPerPage: parseInt(event.target.value, 10), <Pagination
page: 0, count={Math.ceil(checksCount / paginationController.rowsPerPage)}
}); page={paginationController.page + 1}
}; onChange={handlePageChange}
shape="rounded"
renderItem={(item) => (
<PaginationItem
slots={{
previous: ArrowBackRoundedIcon,
next: ArrowForwardRoundedIcon,
}}
{...item}
sx={{
"&:focus": {
outline: "none",
},
"& .MuiTouchRipple-root": {
pointerEvents: "none",
display: "none",
},
}}
/>
)}
/>
);
}
return ( return (
<TableContainer> <>
<TableContainer component={Paper}>
<Table> <Table>
<TableHead> <TableHead>
<TableRow> <TableRow>
@@ -96,20 +124,10 @@ const PaginationTable = ({ monitorId, filter }) => {
); );
})} })}
</TableBody> </TableBody>
<TableFooter>
<TableRow>
<TablePagination
rowsPerPageOptions={[5, 10, 25]}
onPageChange={handlePageChange}
page={paginationController.page}
count={checksCount}
rowsPerPage={paginationController.rowsPerPage}
onRowsPerPageChange={handleChangeRowsPerPage}
/>
</TableRow>
</TableFooter>
</Table> </Table>
</TableContainer> </TableContainer>
{paginationComponent}
</>
); );
}; };