AdminGoodList.js 2.2 KB

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