|
1 | 1 | import {
|
2 | 2 | Box,
|
3 | 3 | Button,
|
| 4 | + Flex, |
4 | 5 | FormControl,
|
5 | 6 | FormLabel,
|
| 7 | + Heading, |
6 | 8 | Image,
|
7 |
| - Input, |
| 9 | + Input, |
8 | 10 | Text,
|
9 | 11 | } from "@chakra-ui/react";
|
| 12 | +import { useEffect, useState } from "react"; |
10 | 13 | import { getItem } from "../redux/localStorage";
|
11 | 14 |
|
12 |
| -export default function Cart(cart) { |
| 15 | +export default function Cart() { |
| 16 | + const [cart,setCart] = useState([]); |
13 | 17 | console.log(cart);
|
| 18 | + const handleData = async()=>{ |
| 19 | + const userID = getItem("userid"); |
| 20 | + let res = await fetch(`http://localhost:3000/api/cart/${userID}`); |
| 21 | + let data = await res.json(); |
| 22 | + setCart(data); |
| 23 | + } |
| 24 | + |
| 25 | + useEffect(()=>{ |
| 26 | + handleData(); |
| 27 | + |
| 28 | + },[]) |
14 | 29 |
|
15 | 30 | return (
|
16 | 31 | <>
|
17 |
| - <Box |
18 |
| - display={"flex"} |
19 |
| - padding={3} |
20 |
| - gap={10} |
21 |
| - justifyContent={"space-around"} |
22 |
| - > |
23 |
| - <Box display={"flex"} width={"50%"} alignItems={"center"}> |
24 |
| - <Box width={"80%"}> |
25 |
| - {cart !== |
26 |
| - { |
27 |
| - error: "Please correct enter id in params", |
28 |
| - } |
29 |
| - ? cart.cart?.map((ele) => { |
30 |
| - return ( |
31 |
| - <Box border={"1px solid black"} width={"300px"} padding={2}> |
32 |
| - <Image src={ele.courseID.image} alt="Linux" /> |
33 |
| - <Text>{ele.courseID.course_name}</Text> |
34 |
| - <Button margin={"auto auto"}>Delete</Button> |
35 |
| - </Box> |
36 |
| - ); |
37 |
| - }) |
38 |
| - : ""} |
39 |
| - </Box> |
40 |
| - </Box> |
41 |
| - <Box width={"30%"}> |
42 |
| - <Text fontSize={30}>Total:</Text> |
43 |
| - <FormControl isRequired> |
44 |
| - <FormLabel>Card Number</FormLabel> |
45 |
| - <Input type="number" /> |
46 |
| - <FormLabel>CVV</FormLabel> |
47 |
| - <Input type="number" /> |
48 |
| - <FormLabel>Expire Date</FormLabel> |
49 |
| - <Input size="md" type="date" /> |
50 |
| - </FormControl> |
51 |
| - <Button mt={4} background="#45F3FF" type="submit"> |
52 |
| - Submit |
53 |
| - </Button> |
54 |
| - <Button mt={4} background="#45F3FF" type="submit"> |
55 |
| - Pay with RazorPay |
56 |
| - </Button> |
57 |
| - </Box> |
58 |
| - </Box> |
59 |
| - </> |
60 |
| - ); |
| 32 | + <Box |
| 33 | + borderRadius={"15px"} |
| 34 | + mt={"10px"} |
| 35 | + position="absolute" |
| 36 | + height="600px" |
| 37 | + display={"inline-block"} |
| 38 | + ml={"10px"} |
| 39 | + width={"55%"} |
| 40 | + > |
| 41 | + <Box display={"flex"} w={""} justifyContent="space-between"> |
| 42 | + <Heading |
| 43 | + ml="100px" |
| 44 | + mt="10px" |
| 45 | + fontFamily={"Ubuntu, sans-serif"} |
| 46 | + fontSize="26px" |
| 47 | + color={"blackAlpha.500"} |
| 48 | + > |
| 49 | + {cart.cart |
| 50 | + ? `Your Cart (${cart.cart.length})` |
| 51 | + : `Your Cart (${0}))`} |
| 52 | + </Heading> |
| 53 | + <Text |
| 54 | + mt="15px" |
| 55 | + mr="118px" |
| 56 | + fontFamily={"Ubuntu, sans-serif"} |
| 57 | + color={"blackAlpha.700"} |
| 58 | + fontSize="20px" |
| 59 | + > |
| 60 | + Price |
| 61 | + </Text> |
| 62 | + </Box> |
| 63 | + <Flex |
| 64 | + flexDirection={"column"} |
| 65 | + height={"500px"} |
| 66 | + mt={{ base: "-15px", lg: "auto" }} |
| 67 | + overflow="scroll" |
| 68 | + > |
| 69 | + |
| 70 | + {cart.cart ? cart.cart.map((el, i) => ( |
| 71 | + <> |
| 72 | + <Flex justifyContent={"space-between"}> |
| 73 | + <Box |
| 74 | + display={"flex"} |
| 75 | + flexDirection="column" |
| 76 | + key={i} |
| 77 | + justify="right" |
| 78 | + alignItems="right" |
| 79 | + height="auto" |
| 80 | + w={{ base: "auto", lg: "auto" }} |
| 81 | + mt={{ base: "20px", lg: "20px" }} |
| 82 | + ml={{ base: "-480px", lg: "40px" }} |
| 83 | + gap="2" |
| 84 | + > |
| 85 | + <Flex gap={5}> |
| 86 | + <Image |
| 87 | + className="imageFromPayment" |
| 88 | + h="180px" |
| 89 | + maxW={"180px"} |
| 90 | + src={el.courseID.image} |
| 91 | + /> |
| 92 | + </Flex> |
| 93 | + <Box> |
| 94 | + <Text |
| 95 | + h="auto" |
| 96 | + fontFamily={"Ubuntu, sans-serif"} |
| 97 | + color="teal" |
| 98 | + w="350px" |
| 99 | + fontSize={"18px"} |
| 100 | + > |
| 101 | + {el.courseID.course_name} |
| 102 | + </Text> |
| 103 | + </Box> |
| 104 | + </Box> |
| 105 | + <Text |
| 106 | + mt={{ lg: "130px" }} |
| 107 | + fontSize="24px" |
| 108 | + fontFamily={"Ubuntu, sans-serif;"} |
| 109 | + mr={{ lg: "100px" }} |
| 110 | + color="teal" |
| 111 | + > |
| 112 | + ₹ {el.courseID.selling_price} |
| 113 | + </Text> |
| 114 | + </Flex> |
| 115 | + {/* </Box> */} |
| 116 | + </> |
| 117 | + )):""} |
| 118 | + </Flex> |
| 119 | + </Box> |
| 120 | + </>) |
61 | 121 | }
|
62 | 122 |
|
63 |
| -export async function getServerSideProps(context) { |
64 |
| - const userID = getItem("userid"); |
65 |
| - let res = await fetch(`http://localhost:3000/api/cart/${userID}`); |
66 |
| - let data = await res.json(); |
67 |
| - let courses = data; |
68 |
| - return { |
69 |
| - props: courses, |
70 |
| - }; |
71 |
| -} |
| 123 | +// export async function getServerSideProps(context) { |
| 124 | +// const userID = getItem("userid"); |
| 125 | +// let res = await fetch(`http://localhost:3000/api/cart/${userID}`); |
| 126 | +// let data = await res.json(); |
| 127 | +// let courses = {data,userID}; |
| 128 | + |
| 129 | +// return { |
| 130 | +// props: courses, |
| 131 | +// }; |
| 132 | +// } |
0 commit comments