AdminOrderList.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { AdminOrderListHeader } from './AdminOrderListHeader';
  2. import { connect } from 'react-redux';
  3. import { SearchBar, SearchResults } from '../../common/SearchBar';
  4. import { actionOrdersFind } from '../../../actions/actionOrdersFind';
  5. import { actionPromiseClear } from '../../../reducers';
  6. import { Box, Table, TableBody, TableHead } from '@mui/material';
  7. import { AdminOrderItem } from './AdminOrderItem';
  8. import { createSearchParams, useLocation, useNavigate } from 'react-router-dom';
  9. const CSearchBar = connect(null, {
  10. onSearch: (text) => actionOrdersFind({ promiseName: 'adminOrdersFind', text, limit: 5 }),
  11. onSearchButtonClick: () => actionPromiseClear('adminOrdersFind'),
  12. })(SearchBar);
  13. const CSearchResults = connect((state) => ({ items: state.promise.adminOrdersFind?.payload || [] }))(SearchResults);
  14. const AdminOrderList = ({ orders, orderBy = '_id' }) => {
  15. const navigate = useNavigate();
  16. const location = useLocation();
  17. return (
  18. <Box className="AdminOrderList">
  19. <Box className="searchBarWrapper">
  20. <CSearchBar
  21. render={CSearchResults}
  22. searchLink="/admin/orders/search/"
  23. renderParams={{ itemLink: '/admin/order/' }}
  24. />
  25. </Box>
  26. <Table>
  27. <TableHead>
  28. <AdminOrderListHeader
  29. sort={orderBy}
  30. onSortChange={(orderBy) => {
  31. navigate({
  32. pathname: location.pathname,
  33. search: createSearchParams({
  34. orderBy,
  35. }).toString(),
  36. });
  37. }}
  38. />
  39. </TableHead>
  40. <TableBody>
  41. {(orders || []).map((order) => (
  42. <AdminOrderItem order={order} key={order._id} />
  43. ))}
  44. </TableBody>
  45. </Table>
  46. </Box>
  47. );
  48. };
  49. const CAdminOrderList = connect((state) => ({ orders: state.feed?.payload || [] }))(AdminOrderList);
  50. export { AdminOrderList, CAdminOrderList };