瀏覽代碼

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 1 天之前
父節點
當前提交
269418ac4c
共有 1 個文件被更改,包括 103 次插入32 次删除
  1. 103
    32
      src/components/ProductDetails/ProductDetails.jsx

+ 103
- 32
src/components/ProductDetails/ProductDetails.jsx 查看文件

45
   const [variants, setVariants] = useState([])
45
   const [variants, setVariants] = useState([])
46
   const [showLoader, setShowLoader] = useState(false)
46
   const [showLoader, setShowLoader] = useState(false)
47
   const [atomeOpen, setAtomeOpen] = useState(false)
47
   const [atomeOpen, setAtomeOpen] = useState(false)
48
+  const [expandedInfoRows, setExpandedInfoRows] = useState({})
48
   const [alert, setAlert] = useState({ open: false, severity: '', message: '' });
49
   const [alert, setAlert] = useState({ open: false, severity: '', message: '' });
49
 
50
 
50
   useEffect(() => {
51
   useEffect(() => {
230
   const installmentPrice = `${(amount / 3).toFixed(2)} ${currencyCode}`
231
   const installmentPrice = `${(amount / 3).toFixed(2)} ${currencyCode}`
231
   // const shortDescriptionHtml = getFirstDescriptionBlock(product?.descriptionHtml)
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
   return (
266
   return (
235
     <Box sx={{ position: "relative" }}>
267
     <Box sx={{ position: "relative" }}>
380
         </Box>
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
             <Button
417
             <Button
386
               variant="text"
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
               disabled={variantSelection?.quantityAvailable <= 0 || quantity === 1}
427
               disabled={variantSelection?.quantityAvailable <= 0 || quantity === 1}
389
               onClick={handleDecrement}
428
               onClick={handleDecrement}
390
             >
429
             >
391
-              <RemoveIcon />
430
+              <RemoveIcon sx={{ fontSize: 18 }} />
392
             </Button>
431
             </Button>
393
 
432
 
394
             <TextField
433
             <TextField
395
               value={quantity}
434
               value={quantity}
396
               inputProps={{ readOnly: true, style: { textAlign: 'center' } }}
435
               inputProps={{ readOnly: true, style: { textAlign: 'center' } }}
397
               sx={{
436
               sx={{
398
-                width: 58,
437
+                width: { xs: 52, sm: 74 },
399
                 "& .MuiOutlinedInput-root": {
438
                 "& .MuiOutlinedInput-root": {
400
-                  height: 48,
439
+                  height: 52,
401
                   borderRadius: 0,
440
                   borderRadius: 0,
402
                   backgroundColor: "#F4F4F4",
441
                   backgroundColor: "#F4F4F4",
403
                   "& fieldset": {
442
                   "& fieldset": {
410
 
449
 
411
             <Button
450
             <Button
412
               variant="text"
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
               disabled={variantSelection?.quantityAvailable <= 0 || quantity === variantSelection?.quantityAvailable}
460
               disabled={variantSelection?.quantityAvailable <= 0 || quantity === variantSelection?.quantityAvailable}
415
               onClick={handleIncrement}
461
               onClick={handleIncrement}
416
             >
462
             >
417
-              <AddIcon />
463
+              <AddIcon sx={{ fontSize: 20 }} />
418
             </Button>
464
             </Button>
419
           </Box>
465
           </Box>
420
 
466
 
421
           <Button
467
           <Button
422
             onClick={() => { handleCart() }}
468
             onClick={() => { handleCart() }}
423
             variant="contained"
469
             variant="contained"
424
-            color="primary"
425
-            fullWidth
426
             disabled={variantSelection?.quantityAvailable <= 0 || showLoader}
470
             disabled={variantSelection?.quantityAvailable <= 0 || showLoader}
427
             sx={{
471
             sx={{
472
+              flex: 1,
473
+              minWidth: 0,
474
+              height: 52,
428
               backgroundColor: (theme) => theme.palette.primary.main,
475
               backgroundColor: (theme) => theme.palette.primary.main,
429
               color: "white",
476
               color: "white",
430
               textTransform: "uppercase",
477
               textTransform: "uppercase",
431
               borderRadius: 0,
478
               borderRadius: 0,
432
-              fontSize: "0.875rem",
479
+              fontSize: "0.9rem",
480
+              fontWeight: 400,
481
+              whiteSpace: "nowrap",
482
+              boxShadow: "none",
433
               "&:hover": {
483
               "&:hover": {
434
                 backgroundColor: (theme) => theme.palette.primary.dark,
484
                 backgroundColor: (theme) => theme.palette.primary.dark,
485
+                boxShadow: "none"
435
               },
486
               },
436
             }}
487
             }}
437
           >
488
           >
458
           PAY NOW
509
           PAY NOW
459
         </Button>}
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
         <Box sx={{ mb: 5 }}>
525
         <Box sx={{ mb: 5 }}>
490
           </Box>
552
           </Box>
491
 
553
 
492
           {/* Product Details */}
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
             <Typography variant="body2" sx={{ textTransform: "uppercase", fontWeight: "400", fontSize: { xs: "0.875rem", md: "1.1rem" } }}>
559
             <Typography variant="body2" sx={{ textTransform: "uppercase", fontWeight: "400", fontSize: { xs: "0.875rem", md: "1.1rem" } }}>
495
               Product Details
560
               Product Details
496
             </Typography>
561
             </Typography>
497
-            <AddIcon sx={{ fontSize: 18 }} />
562
+            {expandedInfoRows.productDetails ? <RemoveIcon sx={{ fontSize: 18 }} /> : <AddIcon sx={{ fontSize: 18 }} />}
498
           </Box>
563
           </Box>
564
+          {emptyInfoPanel("productDetails")}
499
 
565
 
500
           {/* Material */}
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
             <Typography variant="body2" sx={{ textTransform: "uppercase", fontWeight: "400", fontSize: { xs: "0.875rem", md: "1.1rem" } }}>
571
             <Typography variant="body2" sx={{ textTransform: "uppercase", fontWeight: "400", fontSize: { xs: "0.875rem", md: "1.1rem" } }}>
503
               Material
572
               Material
504
             </Typography>
573
             </Typography>
505
-            <AddIcon sx={{ fontSize: 18 }} />
574
+            {expandedInfoRows.material ? <RemoveIcon sx={{ fontSize: 18 }} /> : <AddIcon sx={{ fontSize: 18 }} />}
506
           </Box>
575
           </Box>
576
+          {emptyInfoPanel("material")}
507
 
577
 
508
           {/* Care Instruction */}
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
             <Typography variant="body2" sx={{ textTransform: "uppercase", fontWeight: "400", fontSize: { xs: "0.875rem", md: "1.1rem" } }}>
583
             <Typography variant="body2" sx={{ textTransform: "uppercase", fontWeight: "400", fontSize: { xs: "0.875rem", md: "1.1rem" } }}>
511
               Care Instruction
584
               Care Instruction
512
             </Typography>
585
             </Typography>
513
-            <AddIcon sx={{ fontSize: 18 }} />
586
+            {expandedInfoRows.careInstruction ? <RemoveIcon sx={{ fontSize: 18 }} /> : <AddIcon sx={{ fontSize: 18 }} />}
514
           </Box>
587
           </Box>
588
+          {emptyInfoPanel("careInstruction")}
515
           {/* Shipping Information */}
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
             <Typography variant="body2" sx={{ textTransform: "uppercase", fontWeight: "400", fontSize: { xs: "0.875rem", md: "1.1rem" } }}>
594
             <Typography variant="body2" sx={{ textTransform: "uppercase", fontWeight: "400", fontSize: { xs: "0.875rem", md: "1.1rem" } }}>
518
               Shipping Information
595
               Shipping Information
519
             </Typography>
596
             </Typography>
520
-            <AddIcon sx={{ fontSize: 18 }} />
597
+            {expandedInfoRows.shippingInformation ? <RemoveIcon sx={{ fontSize: 18 }} /> : <AddIcon sx={{ fontSize: 18 }} />}
521
           </Box>
598
           </Box>
599
+          {emptyInfoPanel("shippingInformation")}
522
 
600
 
523
           {/* Return & Exchanges */}
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
             <Typography variant="body2" sx={{ textTransform: "uppercase", fontWeight: "400", fontSize: { xs: "0.875rem", md: "1.1rem" } }}>
606
             <Typography variant="body2" sx={{ textTransform: "uppercase", fontWeight: "400", fontSize: { xs: "0.875rem", md: "1.1rem" } }}>
526
               Return & Exchanges
607
               Return & Exchanges
527
             </Typography>
608
             </Typography>
528
-            <AddIcon sx={{ fontSize: 18 }} />
609
+            {expandedInfoRows.returnExchanges ? <RemoveIcon sx={{ fontSize: 18 }} /> : <AddIcon sx={{ fontSize: 18 }} />}
529
           </Box>
610
           </Box>
611
+          {emptyInfoPanel("returnExchanges")}
530
         </Box>
612
         </Box>
531
       </Box>
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
       {/* Atome Popup */}
615
       {/* Atome Popup */}
545
       <Dialog
616
       <Dialog

Loading…
取消
儲存