Parcourir la source

side cart done

master
azri il y a 1 semaine
Parent
révision
09bc4bcb22
1 fichiers modifiés avec 140 ajouts et 72 suppressions
  1. 140
    72
      src/components/SideCart/SideCart.jsx

+ 140
- 72
src/components/SideCart/SideCart.jsx Voir le fichier

@@ -1,5 +1,5 @@
1 1
 import { useEffect, useState } from "react";
2
-import { Drawer, Box, Typography, IconButton } from "@mui/material";
2
+import { Drawer, Box, Typography, IconButton, Button } from "@mui/material";
3 3
 import Grid from '@mui/material/Grid2';
4 4
 import CloseIcon from "@mui/icons-material/Close";
5 5
 import { updateItemQuantity } from "../../redux/slices/cartSlice";
@@ -20,13 +20,13 @@ const SideCart = ({ open, onClose }) => {
20 20
   }, [cart])
21 21
 
22 22
 
23
-  const handleUpdateCart = ({ quantity,  lineId}) => {
23
+  const handleUpdateCart = ({ quantity, lineId }) => {
24 24
 
25 25
     let cartHistory = localStorage.getItem('amber-cart');
26 26
     cartHistory = cartHistory ? JSON.parse(cartHistory) : {};
27 27
 
28 28
     dispatch(updateItemQuantity({
29
-      cartId:cartHistory.id,
29
+      cartId: cartHistory.id,
30 30
       lineId,
31 31
       quantity,
32 32
     }))
@@ -47,11 +47,12 @@ const SideCart = ({ open, onClose }) => {
47 47
             sm: "90%",
48 48
             md: "30%",
49 49
           },
50
+          height: "97%",
50 51
           padding: 2,
51 52
         },
52 53
       }}
53 54
     >
54
-      <Box>
55
+      <Box sx={{ display: "flex", flexDirection: "column", height: "100%" }}>
55 56
         {/* Header */}
56 57
         <Box
57 58
           sx={{
@@ -67,79 +68,146 @@ const SideCart = ({ open, onClose }) => {
67 68
           </IconButton>
68 69
         </Box>
69 70
 
70
-        {/* Product List */}
71
-        {cartProducts && cartProducts?.length > 0 ? (
72
-          cartProducts.map(({ id, cost, merchandise, quantity }, index) => {
73
-
74
-            let { amount, currencyCode } = cost.totalAmount
75
-            let { image, product, title } = merchandise
71
+        <Box sx={{ flexGrow: 1 }}>
72
+          {/* Product List */}
73
+          {cartProducts && cartProducts?.length > 0 ? (
74
+            cartProducts.map(({ id, cost, merchandise, quantity }, index) => {
75
+
76
+              let { amount, currencyCode } = cost.totalAmount
77
+              let { image, product, title } = merchandise
78
+
79
+              // ID
80
+              const parts = product?.id?.split('/');
81
+              let prodID = parts[parts.length - 1];
82
+
83
+              return (
84
+                <>
85
+                  <Box
86
+                    key={index}
87
+                    sx={{
88
+                      display: "flex",
89
+                      alignItems: "center",
90
+                      padding: 1,
91
+                      borderBottom: "1px solid #eee",
92
+                    }}
93
+                  >
94
+                    <Grid container>
95
+                      {/* Product Image */}
96
+                      <Grid item size={2}>
97
+                        <Box
98
+                          component="img"
99
+                          src={merchandise?.image?.src}
100
+                          alt={product.name}
101
+                          sx={{
102
+                            width: "100%",
103
+                            height: "auto",
104
+                            borderRadius: 2,
105
+                          }}
106
+                        />
107
+                      </Grid>
108
+
109
+                      {/* Product Details */}
110
+                      <Grid item size={10} sx={{ paddingLeft: 1 }}>
111
+                        <Typography variant="body1" sx={{ lineHeight: 1, fontWeight: "bold" }}>
112
+                          {product?.title}
113
+                        </Typography>
114
+                        <Typography variant='body1' sx={{ fontWeight: "bold", mb: 1 }}>{`VARIANT: ${title}`}</Typography>
115
+
116
+                        <Box sx={{ display: "flex", alignItems: "center" }}>
117
+
118
+                          <Typography variant='body1' sx={{ fontWeight: "bold" }}>{`${currencyCode} ${parseFloat(amount).toFixed(2)}`}</Typography>
119
+
120
+                          <Box sx={{ display: "flex", ml: "auto" }}>
121
+                            <IconButton onClick={() => {
122
+
123
+                              handleUpdateCart({ quantity: quantity - 1, lineId: id })
124
+                            }}>
125
+                              <RemoveIcon sx={{ fontSize: 16, margin: "0 15px" }} />
126
+                            </IconButton>
127
+
128
+                            <p style={{ fontSize: 20, fontWeight: "bold" }}>{quantity}</p>
129
+
130
+                            <IconButton onClick={() => {
131
+
132
+                              handleUpdateCart({ quantity: quantity + 1, lineId: id })
133
+                            }}>
134
+                              <AddIcon sx={{ fontSize: 16, margin: "0 15px" }} />
135
+                            </IconButton>
136
+                          </Box>
137
+
138
+                        </Box>
139
+                      </Grid>
140
+                    </Grid>
141
+                  </Box>
142
+                </>
143
+              )
144
+
145
+            })
146
+          ) : (
147
+            <Typography variant="body2" color="text.secondary">
148
+              Your cart is empty.
149
+            </Typography>
150
+          )}
151
+        </Box>
76 152
 
77
-            // ID
78
-            const parts = product?.id?.split('/');
79
-            let prodID = parts[parts.length - 1];
153
+        <Box sx={{ mt: "auto" }}>
154
+          {/* INVOICES */}
155
+          <Grid container spacing={2}>
80 156
 
81
-            return (
157
+            <Grid item size={12}>
158
+              <Box
159
+                display="flex"
160
+                justifyContent="space-between"
161
+                alignItems="center"
162
+              >
163
+                <Typography variant="body1" sx={{ fontWeight: "400" }}>Subtotal</Typography>
164
+                <Typography variant="body1" sx={{ fontWeight: "400" }}>
165
+                  {`
166
+                    ${cart?.cost?.subtotalAmount?.currencyCode} 
167
+                    ${parseFloat(cart?.cost?.subtotalAmount?.amount).toFixed(2)}
168
+                  `}
169
+                </Typography>
170
+              </Box>
82 171
               <Box
83
-                key={index}
84
-                sx={{
85
-                  display: "flex",
86
-                  alignItems: "center",
87
-                  padding: 1,
88
-                  borderBottom: "1px solid #eee",
89
-                }}
172
+                display="flex"
173
+                justifyContent="space-between"
174
+                alignItems="center"
90 175
               >
91
-                <Grid container>
92
-                  {/* Product Image */}
93
-                  <Grid item size={4}>
94
-                    <Box
95
-                      component="img"
96
-                      src={merchandise?.image?.src}
97
-                      alt={product.name}
98
-                      sx={{
99
-                        width: "100%",
100
-                        height: "auto",
101
-                        borderRadius: 2,
102
-                      }}
103
-                    />
104
-                  </Grid>
105
-
106
-                  {/* Product Details */}
107
-                  <Grid item size={8} sx={{ paddingLeft: 1 }}>
108
-                    <Typography variant="body1" sx={{lineHeight:1, fontWeight: "bold"}}>
109
-                      {product?.title}
110
-                    </Typography>
111
-                    <Typography variant='body2' sx={{ fontWeight: "bold" }}>{`${currencyCode} ${parseFloat(amount).toFixed(2)}`}</Typography>
112
-                    <Typography variant='body2' sx={{ fontWeight: "bold" }} >{title}</Typography>
113
-                    <Box sx={{ display: "flex", justifyContent: "center" }}>
114
-
115
-                        <IconButton onClick={() => {
116
-
117
-                          handleUpdateCart({ quantity: quantity - 1, lineId:id })
118
-                        }}>
119
-                          <RemoveIcon sx={{ fontSize: 16, margin: "0 15px" }} />
120
-                        </IconButton>
121
-
122
-                        <p style={{ fontSize: 20, fontWeight: "bold" }}>{quantity}</p>
123
-
124
-                        <IconButton onClick={() => {
125
-
126
-                          handleUpdateCart({ quantity: quantity + 1, lineId:id })
127
-                        }}>
128
-                          <AddIcon sx={{ fontSize: 16, margin: "0 15px" }} />
129
-                        </IconButton>
130
-
131
-                      </Box>
132
-                  </Grid>
133
-                </Grid>
176
+                <Typography variant="body1" sx={{ fontWeight: "400" }}>Taxes</Typography>
177
+                <Typography variant="body1" sx={{ fontWeight: "400" }}>
178
+                  {`
179
+                    ${cart?.cost?.totalTaxAmount?.currencyCode} 
180
+                    ${parseFloat(cart?.cost?.totalTaxAmount?.amount).toFixed(2)}
181
+                  `}
182
+                </Typography>
134 183
               </Box>
135
-            )
136
-
137
-          })
138
-        ) : (
139
-          <Typography variant="body2" color="text.secondary">
140
-            Your cart is empty.
141
-          </Typography>
142
-        )}
184
+              <Box
185
+                display="flex"
186
+                justifyContent="space-between"
187
+                alignItems="center"
188
+              >
189
+                <Typography variant="body1" sx={{ fontWeight: "400" }}>Total</Typography>
190
+                <Typography variant="body1" sx={{ fontWeight: "bold" }}>
191
+                  {`
192
+                    ${cart?.cost?.totalAmount?.currencyCode} 
193
+                    ${parseFloat(cart?.cost?.totalAmount?.amount).toFixed(2)}
194
+                  `}
195
+                </Typography>
196
+              </Box>
197
+            </Grid>
198
+            <Grid item size={12} sx={{textAlign:"center"}}>
199
+              <Button
200
+                variant="contained"
201
+                color="primary"
202
+                onClick={() => {
203
+                  window.location.href = '/cart'
204
+                }}>
205
+                CHECKOUT NOW
206
+              </Button>
207
+            </Grid>
208
+          </Grid>
209
+        </Box>
210
+
143 211
       </Box>
144 212
     </Drawer>
145 213
   );

Chargement…
Annuler
Enregistrer