-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCart.js
106 lines (99 loc) · 3.19 KB
/
Cart.js
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
import {
Box,
Icon,
Stack,
Text,
Select,
Heading,
Flex,
Button,
Divider,
} from "@chakra-ui/react";
import { BiRupee } from "react-icons/bi";
import { MdCall } from "react-icons/md";
import { MdDelete } from "react-icons/md";
function Cart({ cartItems, addToCart }) {
let totalPrice = cartItems.reduce(
(total, item) => total + Number(item.price) * Number(item.quantity),
0
);
return (
<>
{cartItems.length ? (
<Box
maxW={{ base: "3xl", lg: "7xl" }}
mx="auto"
px={{ base: "4", md: "8", lg: "12" }}
py={{ base: "6", md: "8", lg: "12" }}
>
<Stack align={{ lg: "flex-start" }} spacing={{ base: "3", md: "6" }}>
{cartItems.map((item, index) => (
<Stack direction="row" spacing="1" width="full" key={index}>
<Stack spacing="1" align="center">
<Heading size="sm">{item.itemName}</Heading>
<Stack direction="row" spacing={4} align="center">
<Select
value={`${item.quantity}`}
maxW="64px"
aria-label="Select quantity"
onChange={(ev) => {
addToCart({ ...item, quantity: ev.target.value });
}}
>
{new Array(10).fill(0).map((_, index) => (
<option key={index} value={index}>
{index}
</option>
))}
</Select>
<Flex ml="10">
<Icon as={BiRupee} w={5} h={5} />
<Text fontSize="medium">{item.price}</Text>
</Flex>
<Button
colorScheme="red"
variant="ghost"
_hover={{ bg: "red.500", color: " white" }}
onClick={() => {
addToCart({ ...item, quantity: 0 });
}}
>
<Text fontSize="xl">
<MdDelete />
</Text>
</Button>
</Stack>
</Stack>
</Stack>
))}
<Box pt="6">
<Heading size="md">Order Summary</Heading>
<Stack spacing="6">
<Flex justify="space-between" fontSize="sm"></Flex>
<Flex justify="space-between">
<Text fontSize="lg" fontWeight="semibold">
Total
</Text>
<Text fontSize="xl" fontWeight="extrabold">
<Icon as={BiRupee} /> {totalPrice}
</Text>
</Flex>
</Stack>
<Button
rightIcon={<MdCall />}
colorScheme="blue"
variant="outline"
>
Call us make an order
</Button>
</Box>{" "}
</Stack>
<Divider />
</Box>
) : (
<div>Shopping cart is empty</div>
)}{" "}
</>
);
}
export default Cart;