Procházet zdrojové kódy

feat module 6, 7 : [UI] make same space left and right 'add to cart' section, move success alert message under pay now button, add '+' icon section expand/collapse movement

master
nadia před 1 dnem
rodič
revize
269418ac4c
1 změnil soubory, kde provedl 103 přidání a 32 odebrání
  1. 103
    32
      src/components/ProductDetails/ProductDetails.jsx

+ 103
- 32
src/components/ProductDetails/ProductDetails.jsx Zobrazit soubor

@@ -45,6 +45,7 @@ const ProductDetails = () => {
45 45
   const [variants, setVariants] = useState([])
46 46
   const [showLoader, setShowLoader] = useState(false)
47 47
   const [atomeOpen, setAtomeOpen] = useState(false)
48
+  const [expandedInfoRows, setExpandedInfoRows] = useState({})
48 49
   const [alert, setAlert] = useState({ open: false, severity: '', message: '' });
49 50
 
50 51
   useEffect(() => {
@@ -230,6 +231,37 @@ const ProductDetails = () => {
230 231
   const installmentPrice = `${(amount / 3).toFixed(2)} ${currencyCode}`
231 232
   // const shortDescriptionHtml = getFirstDescriptionBlock(product?.descriptionHtml)
232 233
 
234
+  const toggleInfoRow = (row) => {
235
+    setExpandedInfoRows((prevRows) => ({
236
+      ...prevRows,
237
+      [row]: !prevRows[row]
238
+    }))
239
+  }
240
+
241
+  const infoRowSx = (isExpanded) => ({
242
+    display: "flex",
243
+    alignItems: "flex-start",
244
+    justifyContent: "space-between",
245
+    pt: 2,
246
+    pb: isExpanded ? 5 : 2,
247
+    borderBottom: "1px solid #DDD",
248
+    cursor: "pointer",
249
+    transition: "padding-bottom 0.25s ease-in-out"
250
+  })
251
+
252
+  const emptyInfoPanel = (row) => (
253
+    // Old empty expanded panel kept for reference:
254
+    // expandedInfoRows[row] && (
255
+    //   <Box
256
+    //     sx={{
257
+    //       minHeight: 28,
258
+    //       borderBottom: "1px solid #DDD"
259
+    //     }}
260
+    //   />
261
+    // )
262
+    null
263
+  )
264
+
233 265
 
234 266
   return (
235 267
     <Box sx={{ position: "relative" }}>
@@ -380,24 +412,31 @@ const ProductDetails = () => {
380 412
         </Box>
381 413
 
382 414
 
383
-        <Box sx={{ display: "flex", alignItems: "stretch", gap: 2 }}>
384
-          <Box display="flex" alignItems="stretch" sx={{ backgroundColor: "#F4F4F4", height: 48 }}>
415
+        <Box sx={{ display: "flex", alignItems: "stretch", gap: 1, mb: 4, width: "100%" }}>
416
+          <Box display="flex" alignItems="stretch" sx={{ backgroundColor: "#F4F4F4", height: 52, width: { xs: 124, sm: 186 } }}>
385 417
             <Button
386 418
               variant="text"
387
-              sx={{ minWidth: 80, color: "#000", backgroundColor: "#F4F4F4" }}
419
+              sx={{
420
+                minWidth: 36,
421
+                width: { xs: 36, sm: 56 },
422
+                p: 0,
423
+                color: "#000",
424
+                backgroundColor: "#F4F4F4",
425
+                borderRadius: 0
426
+              }}
388 427
               disabled={variantSelection?.quantityAvailable <= 0 || quantity === 1}
389 428
               onClick={handleDecrement}
390 429
             >
391
-              <RemoveIcon />
430
+              <RemoveIcon sx={{ fontSize: 18 }} />
392 431
             </Button>
393 432
 
394 433
             <TextField
395 434
               value={quantity}
396 435
               inputProps={{ readOnly: true, style: { textAlign: 'center' } }}
397 436
               sx={{
398
-                width: 58,
437
+                width: { xs: 52, sm: 74 },
399 438
                 "& .MuiOutlinedInput-root": {
400
-                  height: 48,
439
+                  height: 52,
401 440
                   borderRadius: 0,
402 441
                   backgroundColor: "#F4F4F4",
403 442
                   "& fieldset": {
@@ -410,28 +449,40 @@ const ProductDetails = () => {
410 449
 
411 450
             <Button
412 451
               variant="text"
413
-              sx={{ minWidth: 80, color: "#000", backgroundColor: "#F4F4F4" }}
452
+              sx={{
453
+                minWidth: 36,
454
+                width: { xs: 36, sm: 56 },
455
+                p: 0,
456
+                color: "#000",
457
+                backgroundColor: "#F4F4F4",
458
+                borderRadius: 0
459
+              }}
414 460
               disabled={variantSelection?.quantityAvailable <= 0 || quantity === variantSelection?.quantityAvailable}
415 461
               onClick={handleIncrement}
416 462
             >
417
-              <AddIcon />
463
+              <AddIcon sx={{ fontSize: 20 }} />
418 464
             </Button>
419 465
           </Box>
420 466
 
421 467
           <Button
422 468
             onClick={() => { handleCart() }}
423 469
             variant="contained"
424
-            color="primary"
425
-            fullWidth
426 470
             disabled={variantSelection?.quantityAvailable <= 0 || showLoader}
427 471
             sx={{
472
+              flex: 1,
473
+              minWidth: 0,
474
+              height: 52,
428 475
               backgroundColor: (theme) => theme.palette.primary.main,
429 476
               color: "white",
430 477
               textTransform: "uppercase",
431 478
               borderRadius: 0,
432
-              fontSize: "0.875rem",
479
+              fontSize: "0.9rem",
480
+              fontWeight: 400,
481
+              whiteSpace: "nowrap",
482
+              boxShadow: "none",
433 483
               "&:hover": {
434 484
                 backgroundColor: (theme) => theme.palette.primary.dark,
485
+                boxShadow: "none"
435 486
               },
436 487
             }}
437 488
           >
@@ -458,6 +509,17 @@ const ProductDetails = () => {
458 509
           PAY NOW
459 510
         </Button>}
460 511
 
512
+        {alert.open && (
513
+          <Alert
514
+            severity={alert.severity}
515
+            onClose={() => setAlert({ ...alert, open: false })}
516
+            sx={{ marginTop: 2 }}
517
+          >
518
+            <AlertTitle>{alert.severity === 'success' ? 'Success' : 'Error'}</AlertTitle>
519
+            {alert.message}
520
+          </Alert>
521
+        )}
522
+
461 523
         {/*
462 524
         {/*
463 525
         <Box sx={{ mb: 5 }}>
@@ -490,56 +552,65 @@ const ProductDetails = () => {
490 552
           </Box>
491 553
 
492 554
           {/* Product Details */}
493
-          <Box sx={{ display: "flex", alignItems: "center", justifyContent: "space-between", py: 2, borderBottom: "1px solid #DDD" }}>
555
+          <Box
556
+            onClick={() => toggleInfoRow("productDetails")}
557
+            sx={infoRowSx(expandedInfoRows.productDetails)}
558
+          >
494 559
             <Typography variant="body2" sx={{ textTransform: "uppercase", fontWeight: "400", fontSize: { xs: "0.875rem", md: "1.1rem" } }}>
495 560
               Product Details
496 561
             </Typography>
497
-            <AddIcon sx={{ fontSize: 18 }} />
562
+            {expandedInfoRows.productDetails ? <RemoveIcon sx={{ fontSize: 18 }} /> : <AddIcon sx={{ fontSize: 18 }} />}
498 563
           </Box>
564
+          {emptyInfoPanel("productDetails")}
499 565
 
500 566
           {/* Material */}
501
-          <Box sx={{ display: "flex", alignItems: "center", justifyContent: "space-between", py: 2, borderBottom: "1px solid #DDD" }}>
567
+          <Box
568
+            onClick={() => toggleInfoRow("material")}
569
+            sx={infoRowSx(expandedInfoRows.material)}
570
+          >
502 571
             <Typography variant="body2" sx={{ textTransform: "uppercase", fontWeight: "400", fontSize: { xs: "0.875rem", md: "1.1rem" } }}>
503 572
               Material
504 573
             </Typography>
505
-            <AddIcon sx={{ fontSize: 18 }} />
574
+            {expandedInfoRows.material ? <RemoveIcon sx={{ fontSize: 18 }} /> : <AddIcon sx={{ fontSize: 18 }} />}
506 575
           </Box>
576
+          {emptyInfoPanel("material")}
507 577
 
508 578
           {/* Care Instruction */}
509
-          <Box sx={{ display: "flex", alignItems: "center", justifyContent: "space-between", py: 2, borderBottom: "1px solid #DDD" }}>
579
+          <Box
580
+            onClick={() => toggleInfoRow("careInstruction")}
581
+            sx={infoRowSx(expandedInfoRows.careInstruction)}
582
+          >
510 583
             <Typography variant="body2" sx={{ textTransform: "uppercase", fontWeight: "400", fontSize: { xs: "0.875rem", md: "1.1rem" } }}>
511 584
               Care Instruction
512 585
             </Typography>
513
-            <AddIcon sx={{ fontSize: 18 }} />
586
+            {expandedInfoRows.careInstruction ? <RemoveIcon sx={{ fontSize: 18 }} /> : <AddIcon sx={{ fontSize: 18 }} />}
514 587
           </Box>
588
+          {emptyInfoPanel("careInstruction")}
515 589
           {/* Shipping Information */}
516
-          <Box sx={{ display: "flex", alignItems: "center", justifyContent: "space-between", py: 2, borderBottom: "1px solid #DDD" }}>
590
+          <Box
591
+            onClick={() => toggleInfoRow("shippingInformation")}
592
+            sx={infoRowSx(expandedInfoRows.shippingInformation)}
593
+          >
517 594
             <Typography variant="body2" sx={{ textTransform: "uppercase", fontWeight: "400", fontSize: { xs: "0.875rem", md: "1.1rem" } }}>
518 595
               Shipping Information
519 596
             </Typography>
520
-            <AddIcon sx={{ fontSize: 18 }} />
597
+            {expandedInfoRows.shippingInformation ? <RemoveIcon sx={{ fontSize: 18 }} /> : <AddIcon sx={{ fontSize: 18 }} />}
521 598
           </Box>
599
+          {emptyInfoPanel("shippingInformation")}
522 600
 
523 601
           {/* Return & Exchanges */}
524
-          <Box sx={{ display: "flex", alignItems: "center", justifyContent: "space-between", py: 2, borderBottom: "1px solid #DDD" }}>
602
+          <Box
603
+            onClick={() => toggleInfoRow("returnExchanges")}
604
+            sx={infoRowSx(expandedInfoRows.returnExchanges)}
605
+          >
525 606
             <Typography variant="body2" sx={{ textTransform: "uppercase", fontWeight: "400", fontSize: { xs: "0.875rem", md: "1.1rem" } }}>
526 607
               Return & Exchanges
527 608
             </Typography>
528
-            <AddIcon sx={{ fontSize: 18 }} />
609
+            {expandedInfoRows.returnExchanges ? <RemoveIcon sx={{ fontSize: 18 }} /> : <AddIcon sx={{ fontSize: 18 }} />}
529 610
           </Box>
611
+          {emptyInfoPanel("returnExchanges")}
530 612
         </Box>
531 613
       </Box>
532
-      
533
-      {alert.open && (
534
-        <Alert
535
-          severity={alert.severity}
536
-          onClose={() => setAlert({ ...alert, open: false })}
537
-          sx={{ marginTop: 2 }}
538
-        >
539
-          <AlertTitle>{alert.severity === 'success' ? 'Success' : 'Error'}</AlertTitle>
540
-          {alert.message}
541
-        </Alert>
542
-      )}
543 614
 
544 615
       {/* Atome Popup */}
545 616
       <Dialog

Načítá se…
Zrušit
Uložit