DrawerCart.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { useNavigate } from "react-router-dom";
  2. import { IoMdClose } from "react-icons/io";
  3. import { Divider, Typography, Button, Stack, IconButton } from "@mui/material";
  4. import { DrawerCartItem } from "./DrawerCartItem";
  5. import { DrawerRight } from "../DrawerRight";
  6. import { Box } from "@mui/system";
  7. import { connect } from "react-redux";
  8. import { actionCartDelete } from "../../../reducers";
  9. export const DrawerCart = ({ cart = {}, isOpen = false, onClose = null, onDeleteClick } = {}) => {
  10. const navigate = useNavigate();
  11. return (
  12. <DrawerRight open={isOpen} onClose={() => onClose()}>
  13. <Box className="DrawerCart">
  14. <Stack className="list " spacing={2} px={1}>
  15. <Stack spacing={2} direction="row" alignItems="center" justifyContent="space-between" p={1}>
  16. <Typography variant="h5" flexGrow="1">
  17. Кошик
  18. </Typography>
  19. <IconButton onClick={onClose}>
  20. <IoMdClose />
  21. </IconButton>
  22. </Stack>
  23. <Divider />
  24. {Object.entries(cart).map(([_id, order]) => (
  25. <DrawerCartItem order={order} onDeleteClick={(good) => onDeleteClick(good)} key={_id} />
  26. ))}
  27. {!!Object.keys(cart).length && (
  28. <Button
  29. variant="text"
  30. onClick={() => {
  31. onClose();
  32. navigate("/cart");
  33. }}
  34. >
  35. Підтвердити
  36. </Button>
  37. )}
  38. </Stack>
  39. </Box>
  40. </DrawerRight>
  41. );
  42. };
  43. export const CDrawerCart = connect((state) => ({ cart: state.cart || {} }), {
  44. onDeleteClick: (good) => actionCartDelete(good),
  45. })(DrawerCart);