Pagination.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { TablePagination } from '@mui/material';
  2. import { useState } from 'react';
  3. import { connect } from 'react-redux';
  4. import { actionFindOrders, actionOrdersCount } from '../reducers';
  5. import { actionSetOrdersPaging } from '../reducers/frontEndReducer';
  6. const Pagination = ({ allEntitiesCount, changePage, changePageFE, changeRowsPerPage, changeRowsPerPageFE }) => {
  7. allEntitiesCount = allEntitiesCount ?? 0;
  8. const [page, setPage] = useState(0);
  9. const [rowsPerPage, setRowsPerPage] = useState(5);
  10. const handleChangePage = (event, newPage) => {
  11. setPage(newPage);
  12. changePage(newPage, rowsPerPage);
  13. changePageFE(newPage, rowsPerPage);
  14. };
  15. const handleChangeRowsPerPage = (event) => {
  16. let newpageSize = parseInt(event.target.value, 10);
  17. setRowsPerPage(newpageSize);
  18. setPage(0);
  19. changeRowsPerPage(newpageSize);
  20. changeRowsPerPageFE(newpageSize);
  21. };
  22. return (
  23. <TablePagination
  24. rowsPerPageOptions={[5, 10, 25]}
  25. component="div"
  26. count={allEntitiesCount}
  27. rowsPerPage={rowsPerPage}
  28. page={page}
  29. onPageChange={handleChangePage}
  30. onRowsPerPageChange={handleChangeRowsPerPage}
  31. />
  32. )
  33. }
  34. export const COrdersPagination = connect(
  35. state => (
  36. {
  37. allEntitiesCount: state.orders.ordersCount?.payload,
  38. }),
  39. {
  40. changePageFE: (fromPage, pageSize) => actionSetOrdersPaging({ fromPage, pageSize }),
  41. changePage: (fromPage, pageSize) => actionFindOrders(fromPage, pageSize),
  42. changeRowsPerPageFE: pageSize => actionSetOrdersPaging({ fromPage: 0, pageSize }),
  43. changeRowsPerPage: pageSize => actionFindOrders(0, pageSize),
  44. retrieveOrdersCount: actionOrdersCount,
  45. })(Pagination);