index.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { Stack, Typography, Divider, LinearProgress } from "@mui/material";
  2. import { Box } from "@mui/system";
  3. import { connect } from "react-redux";
  4. import { useSearchParams } from "react-router-dom";
  5. import { GoodList } from "../common/GoodList";
  6. import { SubCategories } from "./SubCategories";
  7. import { SortOptions } from "../common/SortOptions";
  8. const GoodsPage = ({ category = {}, goods = [], promiseStatus = null }) => {
  9. const { name = "", subcategories = [] } = category || {};
  10. const [searchParams, setSearchParams] = useSearchParams();
  11. return (
  12. <Box className="GoodsPage">
  13. <Box>
  14. <Typography variant="h5" textAlign="center">
  15. {name}
  16. </Typography>
  17. </Box>
  18. {name && <Divider className="Divider" />}
  19. <Stack>
  20. <Box className="sortOptionsWrapper">
  21. <SortOptions
  22. defaultOption={searchParams.get("orderBy", "createdAt")}
  23. onClick={(option) => {
  24. searchParams.set("orderBy", option.value);
  25. setSearchParams(searchParams);
  26. }}
  27. />
  28. </Box>
  29. {!!subcategories.length ? (
  30. <Box>
  31. <Typography variant="h6" color="#79747E" textAlign="left">
  32. Категорії
  33. </Typography>
  34. <SubCategories categories={subcategories} />
  35. </Box>
  36. ) : null}
  37. {!!goods.length ? (
  38. <Box>
  39. <Typography paddingBottom={1} variant="h6" color="#79747E" textAlign="left">
  40. Товари
  41. </Typography>
  42. <GoodList goods={goods} />
  43. </Box>
  44. ) : null}
  45. {promiseStatus === "PENDING" && <LinearProgress />}
  46. </Stack>
  47. </Box>
  48. );
  49. };
  50. const CGoodsPage = connect((state) => ({
  51. category: state?.promise?.catById?.payload || {},
  52. goods: state?.feed?.payload || [],
  53. promiseStatus: state.promise?.feedCategoryGoods?.status || state.promise?.feedGoodsFind?.status || null,
  54. }))(GoodsPage);
  55. export { GoodsPage, CGoodsPage };