Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | 12x 12x 2x 2x 1x 1x 2x 12x 1x 1x 1x 12x 12x 14x 1x 12x 12x | import { Box, Stack } from "@mui/material";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import GiveSidePanel from "@shared/SidePanel/GiveSidePanel";
import { SidePanelContainerWrapper } from "@shared/SidePanel/SidePanelAtoms";
import useNiceModal from "@common/Modal/ModalFactory/hooks/useNiceModal";
import NiceModal from "@ebay/nice-modal-react";
import { styled } from "@theme/v2/Provider";
import GiveText from "@shared/Text/GiveText";
import GiveIconButton from "@shared/IconButton/GiveIconButton";
import { XIcon } from "@phosphor-icons/react";
import { ICartItem } from "../provider/CartContext";
import CartItem from "../components/cart/CartItem";
import { CheckoutNavButton } from "../components/products/CheckoutNavButton";
import { useEffect } from "react";
import { CURRENCY } from "@constants/constants";
interface Props {
cartItems: ICartItem[];
addToCart: (
item: ICartItem,
addedQuantity?: number,
quantityChangeType?: string,
) => void;
removeFromCart: (ProductItemTypeId: string) => void;
totalAmount: number;
saveOnClose?: (open: boolean, onClose: () => void) => void;
}
const CART_PANEL_WIDTH = 400;
const CartPreviewModal = NiceModal.create(
({ saveOnClose, ...props }: Props) => {
const { open, onClose } = useNiceModal();
useEffect(() => {
Eif (saveOnClose) {
saveOnClose(open, onClose);
}
}, []);
return (
<GiveSidePanel open={open} onClose={onClose} width={CART_PANEL_WIDTH}>
<CartPreviewModalBody {...props} onClose={onClose} />
</GiveSidePanel>
);
},
);
export const CartPreviewModalBody = ({
addToCart,
removeFromCart,
cartItems,
totalAmount,
onClose,
}: Props & { onClose: () => void }) => {
const { isMobileView } = useCustomThemeV2();
return (
<>
<StyledHeader>
<GiveText variant="bodyS">Your Cart</GiveText>
<GiveIconButton Icon={XIcon} variant="ghost" onClick={onClose} />
</StyledHeader>
<SidePanelContainerWrapper position="relative">
<StyledStack>
<Box
padding="0 10px"
sx={{ overflowY: "auto", paddingBottom: "80px" }}
>
{cartItems.length == 0 && <GiveText> Your cart is empty</GiveText>}
{cartItems?.map((item) => (
<CartItem
key={item.id}
item={item}
removeFromCart={removeFromCart}
addToCart={addToCart}
/>
))}
</Box>
<StyledFooter isMobile={isMobileView}>
<StyledSummary>
<Stack gap="6px">
<GiveText variant="bodyM">Subtotal</GiveText>
</Stack>
<GiveText variant="bodyM">
{totalAmount} {CURRENCY}
</GiveText>
</StyledSummary>
<CheckoutNavButton fullWidth />
</StyledFooter>
</StyledStack>
</SidePanelContainerWrapper>
</>
);
};
export default CartPreviewModal;
const StyledHeader = styled(Stack)({
padding: "12px 16px",
height: "56px",
gap: "20px",
borderBottom: "1px solid #E5E5E3",
flexDirection: "row",
alignItems: "center",
justifyContent: "space-between",
});
const StyledFooter = styled(Stack, {
shouldForwardProp: (prop) => prop !== "isMobile",
})<{ isMobile: boolean }>(({ isMobile }) => ({
padding: "12px 20px 20px 20px",
gap: "20px",
borderTop: "1px solid #E5E5E3",
...(isMobile && {
position: "fixed",
background: "inherit",
width: "100%",
bottom: 0,
backdropFilter: "blur(15px)",
}),
}));
const StyledSummary = styled(Stack)({
flexDirection: "row",
alignItems: "flex-start",
flex: 1,
gap: "16px",
justifyContent: "space-between",
});
const StyledStack = styled(Stack)({
height: "calc(100% - 56px)",
justifyContent: "space-between",
});
|