| 
				
			 | 
			
			
				
				@@ -1,84 +1,92 @@ 
			 | 
		
		
	
		
			
			| 
				1
			 | 
			
				
			 | 
			
			
				
				-import React from 'react'; 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				1
			 | 
			
			
				
				+import { useEffect } from 'react'; 
			 | 
		
		
	
		
			
			| 
				2
			 | 
			
				2
			 | 
			
			
				
				 import { Box, Typography, Button, useMediaQuery } from '@mui/material'; 
			 | 
		
		
	
		
			
			| 
				3
			 | 
			
				3
			 | 
			
			
				
				 import Grid from '@mui/material/Grid2'; 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				4
			 | 
			
			
				
				+import { useSelector, useDispatch } from 'react-redux'; 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				5
			 | 
			
			
				
				+import { fetchProducts } from '../../redux/slices/productSlice'; 
			 | 
		
		
	
		
			
			| 
				4
			 | 
			
				6
			 | 
			
			
				
				  
			 | 
		
		
	
		
			
			| 
				5
			 | 
			
				7
			 | 
			
			
				
				 const ProductSelected = () => { 
			 | 
		
		
	
		
			
			| 
				6
			 | 
			
				8
			 | 
			
			
				
				  
			 | 
		
		
	
		
			
			| 
				7
			 | 
			
				
			 | 
			
			
				
				-  const images = [ 
			 | 
		
		
	
		
			
			| 
				8
			 | 
			
				
			 | 
			
			
				
				-    { 
			 | 
		
		
	
		
			
			| 
				9
			 | 
			
				
			 | 
			
			
				
				-      url: 'https://via.placeholder.com/300', 
			 | 
		
		
	
		
			
			| 
				10
			 | 
			
				
			 | 
			
			
				
				-      title: 'KEMBOJA IN BEIGE', 
			 | 
		
		
	
		
			
			| 
				11
			 | 
			
				
			 | 
			
			
				
				-      price: 123.90, 
			 | 
		
		
	
		
			
			| 
				12
			 | 
			
				
			 | 
			
			
				
				-      description: "Atma Sari Kurta Raya Collection 2024", 
			 | 
		
		
	
		
			
			| 
				13
			 | 
			
				
			 | 
			
			
				
				-      extra_desc: "or 3 payments of 68.50 MYR with Atome" 
			 | 
		
		
	
		
			
			| 
				14
			 | 
			
				
			 | 
			
			
				
				-    }, 
			 | 
		
		
	
		
			
			| 
				15
			 | 
			
				
			 | 
			
			
				
				-    { 
			 | 
		
		
	
		
			
			| 
				16
			 | 
			
				
			 | 
			
			
				
				-      url: 'https://via.placeholder.com/300', 
			 | 
		
		
	
		
			
			| 
				17
			 | 
			
				
			 | 
			
			
				
				-      title: 'KEMBOJA IN BEIGE', 
			 | 
		
		
	
		
			
			| 
				18
			 | 
			
				
			 | 
			
			
				
				-      price: 123.90, 
			 | 
		
		
	
		
			
			| 
				19
			 | 
			
				
			 | 
			
			
				
				-      description: "Atma Sari Kurta Raya Collection 2024", 
			 | 
		
		
	
		
			
			| 
				20
			 | 
			
				
			 | 
			
			
				
				-      extra_desc: "or 3 payments of 68.50 MYR with Atome" 
			 | 
		
		
	
		
			
			| 
				21
			 | 
			
				
			 | 
			
			
				
				-    }, 
			 | 
		
		
	
		
			
			| 
				22
			 | 
			
				
			 | 
			
			
				
				-    { 
			 | 
		
		
	
		
			
			| 
				23
			 | 
			
				
			 | 
			
			
				
				-      url: 'https://via.placeholder.com/300', 
			 | 
		
		
	
		
			
			| 
				24
			 | 
			
				
			 | 
			
			
				
				-      title: 'KEMBOJA IN BEIGE', 
			 | 
		
		
	
		
			
			| 
				25
			 | 
			
				
			 | 
			
			
				
				-      price: 123.90, 
			 | 
		
		
	
		
			
			| 
				26
			 | 
			
				
			 | 
			
			
				
				-      description: "Atma Sari Kurta Raya Collection 2024", 
			 | 
		
		
	
		
			
			| 
				27
			 | 
			
				
			 | 
			
			
				
				-      extra_desc: "or 3 payments of 68.50 MYR with Atome" 
			 | 
		
		
	
		
			
			| 
				28
			 | 
			
				
			 | 
			
			
				
				-    }, 
			 | 
		
		
	
		
			
			| 
				29
			 | 
			
				
			 | 
			
			
				
				-    { 
			 | 
		
		
	
		
			
			| 
				30
			 | 
			
				
			 | 
			
			
				
				-      url: 'https://via.placeholder.com/300', 
			 | 
		
		
	
		
			
			| 
				31
			 | 
			
				
			 | 
			
			
				
				-      title: 'KEMBOJA IN BEIGE', 
			 | 
		
		
	
		
			
			| 
				32
			 | 
			
				
			 | 
			
			
				
				-      price: 123.90, 
			 | 
		
		
	
		
			
			| 
				33
			 | 
			
				
			 | 
			
			
				
				-      description: "Atma Sari Kurta Raya Collection 2024", 
			 | 
		
		
	
		
			
			| 
				34
			 | 
			
				
			 | 
			
			
				
				-      extra_desc: "or 3 payments of 68.50 MYR with Atome" 
			 | 
		
		
	
		
			
			| 
				35
			 | 
			
				
			 | 
			
			
				
				-    } 
			 | 
		
		
	
		
			
			| 
				36
			 | 
			
				
			 | 
			
			
				
				-  ]; 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				9
			 | 
			
			
				
				+  const products = useSelector((state) => state.products.products.data) 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				10
			 | 
			
			
				
				+  const dispatch = useDispatch(); 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				11
			 | 
			
			
				
				+ 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				12
			 | 
			
			
				
				+  useEffect(() => { 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				13
			 | 
			
			
				
				+ 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				14
			 | 
			
			
				
				+    dispatch(fetchProducts()) 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				15
			 | 
			
			
				
				+ 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				16
			 | 
			
			
				
				+  }, []) 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				17
			 | 
			
			
				
				+ 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				18
			 | 
			
			
				
				+  const renderProduct = (id, img_url, title, collection, price, currency, extra_desc) => { 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				19
			 | 
			
			
				
				+ 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				20
			 | 
			
			
				
				+    return ( 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				21
			 | 
			
			
				
				+      <Grid item size={{ xs: 6, sm: 6, md: 3 }}> 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				22
			 | 
			
			
				
				+        <Box 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				23
			 | 
			
			
				
				+          onClick={() => { window.location.href = `/products/${id}` }} 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				24
			 | 
			
			
				
				+          sx={{ 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				25
			 | 
			
			
				
				+            overflow: 'hidden', 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				26
			 | 
			
			
				
				+            position: 'relative', 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				27
			 | 
			
			
				
				+            cursor: 'pointer' 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				28
			 | 
			
			
				
				+          }} 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				29
			 | 
			
			
				
				+ 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				30
			 | 
			
			
				
				+        > 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				31
			 | 
			
			
				
				+          <img 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				32
			 | 
			
			
				
				+            src={img_url} 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				33
			 | 
			
			
				
				+            alt={title} 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				34
			 | 
			
			
				
				+            style={{ 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				35
			 | 
			
			
				
				+              width: '100%', 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				36
			 | 
			
			
				
				+              aspectRatio: '3 / 4', 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				37
			 | 
			
			
				
				+              objectFit: 'cover', 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				38
			 | 
			
			
				
				+              objectPosition: 'top center' 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				39
			 | 
			
			
				
				+            }} 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				40
			 | 
			
			
				
				+          /> 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				41
			 | 
			
			
				
				+ 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				42
			 | 
			
			
				
				+          {/* <Button sx={{ position: "absolute", top: 20, left: 20, boxShadow: 0 }} variant="contained"> 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				43
			 | 
			
			
				
				+            NEW 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				44
			 | 
			
			
				
				+          </Button> */} 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				45
			 | 
			
			
				
				+ 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				46
			 | 
			
			
				
				+          <Box sx={{ py: 5 }}> 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				47
			 | 
			
			
				
				+            <Typography variant="body2" > 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				48
			 | 
			
			
				
				+              {collection} 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				49
			 | 
			
			
				
				+            </Typography> 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				50
			 | 
			
			
				
				+            <Typography variant="h5" sx={{ fontWeight: "bolder" }}> 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				51
			 | 
			
			
				
				+              {title} 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				52
			 | 
			
			
				
				+            </Typography> 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				53
			 | 
			
			
				
				+            <Typography variant="body" > 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				54
			 | 
			
			
				
				+              {`${currency} ${parseFloat(price).toFixed(2)}`} 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				55
			 | 
			
			
				
				+            </Typography> 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				56
			 | 
			
			
				
				+            <Typography variant="body2" sx={{ mt: 2 }}> 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				57
			 | 
			
			
				
				+              {extra_desc} 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				58
			 | 
			
			
				
				+            </Typography> 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				59
			 | 
			
			
				
				+          </Box> 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				60
			 | 
			
			
				
				+        </Box> 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				61
			 | 
			
			
				
				+      </Grid> 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				62
			 | 
			
			
				
				+    ) 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				63
			 | 
			
			
				
				+ 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				64
			 | 
			
			
				
				+  } 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				65
			 | 
			
			
				
				+ 
			 | 
		
		
	
		
			
			| 
				37
			 | 
			
				66
			 | 
			
			
				
				  
			 | 
		
		
	
		
			
			| 
				38
			 | 
			
				67
			 | 
			
			
				
				   const isMobileScreen = useMediaQuery((theme) => theme.breakpoints.down('sm')) 
			 | 
		
		
	
		
			
			| 
				39
			 | 
			
				68
			 | 
			
			
				
				  
			 | 
		
		
	
		
			
			| 
				40
			 | 
			
				
			 | 
			
			
				
				-  const displayedImages = isMobileScreen ? images.slice(0, 2) : images; 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				69
			 | 
			
			
				
				+  const displayedImages = isMobileScreen ? products.slice(0, 2) : products.slice(0, 4); 
			 | 
		
		
	
		
			
			| 
				41
			 | 
			
				70
			 | 
			
			
				
				  
			 | 
		
		
	
		
			
			| 
				42
			 | 
			
				71
			 | 
			
			
				
				   return ( 
			 | 
		
		
	
		
			
			| 
				43
			 | 
			
				72
			 | 
			
			
				
				     <Box sx={{ mb: 5 }}> 
			 | 
		
		
	
		
			
			| 
				44
			 | 
			
				73
			 | 
			
			
				
				       <Grid container spacing={1} columns={12}> 
			 | 
		
		
	
		
			
			| 
				45
			 | 
			
				
			 | 
			
			
				
				-        {displayedImages.map((image, index) => (<Grid item size={{ xs: 6, md: 3 }} key={index}> 
			 | 
		
		
	
		
			
			| 
				46
			 | 
			
				
			 | 
			
			
				
				-          <Box 
			 | 
		
		
	
		
			
			| 
				47
			 | 
			
				
			 | 
			
			
				
				-            sx={{ 
			 | 
		
		
	
		
			
			| 
				48
			 | 
			
				
			 | 
			
			
				
				-              overflow: 'hidden', 
			 | 
		
		
	
		
			
			| 
				49
			 | 
			
				
			 | 
			
			
				
				-              position: 'relative' 
			 | 
		
		
	
		
			
			| 
				50
			 | 
			
				
			 | 
			
			
				
				-            }} 
			 | 
		
		
	
		
			
			| 
				51
			 | 
			
				
			 | 
			
			
				
				-          > 
			 | 
		
		
	
		
			
			| 
				52
			 | 
			
				
			 | 
			
			
				
				-            <img 
			 | 
		
		
	
		
			
			| 
				53
			 | 
			
				
			 | 
			
			
				
				-              src={image.url} 
			 | 
		
		
	
		
			
			| 
				54
			 | 
			
				
			 | 
			
			
				
				-              alt={image.title} 
			 | 
		
		
	
		
			
			| 
				55
			 | 
			
				
			 | 
			
			
				
				-              style={{ 
			 | 
		
		
	
		
			
			| 
				56
			 | 
			
				
			 | 
			
			
				
				-                width: '100%', 
			 | 
		
		
	
		
			
			| 
				57
			 | 
			
				
			 | 
			
			
				
				-                aspectRatio: '3 / 4', 
			 | 
		
		
	
		
			
			| 
				58
			 | 
			
				
			 | 
			
			
				
				-                objectFit: 'cover', 
			 | 
		
		
	
		
			
			| 
				59
			 | 
			
				
			 | 
			
			
				
				-              }} 
			 | 
		
		
	
		
			
			| 
				60
			 | 
			
				
			 | 
			
			
				
				-            /> 
			 | 
		
		
	
		
			
			| 
				61
			 | 
			
				
			 | 
			
			
				
				- 
			 | 
		
		
	
		
			
			| 
				62
			 | 
			
				
			 | 
			
			
				
				-            {/* <Button sx={{ position: "absolute", top: 20, left: 20, boxShadow: 0 }} variant="contained"> 
			 | 
		
		
	
		
			
			| 
				63
			 | 
			
				
			 | 
			
			
				
				-              NEW 
			 | 
		
		
	
		
			
			| 
				64
			 | 
			
				
			 | 
			
			
				
				-            </Button> */} 
			 | 
		
		
	
		
			
			| 
				65
			 | 
			
				
			 | 
			
			
				
				- 
			 | 
		
		
	
		
			
			| 
				66
			 | 
			
				
			 | 
			
			
				
				-            <Box sx={{ py: 5 }}> 
			 | 
		
		
	
		
			
			| 
				67
			 | 
			
				
			 | 
			
			
				
				-              <Typography variant="body2" > 
			 | 
		
		
	
		
			
			| 
				68
			 | 
			
				
			 | 
			
			
				
				-                {image.description} 
			 | 
		
		
	
		
			
			| 
				69
			 | 
			
				
			 | 
			
			
				
				-              </Typography> 
			 | 
		
		
	
		
			
			| 
				70
			 | 
			
				
			 | 
			
			
				
				-              <Typography variant="h5" sx={{ fontWeight: "bolder" }}> 
			 | 
		
		
	
		
			
			| 
				71
			 | 
			
				
			 | 
			
			
				
				-                {image.title} 
			 | 
		
		
	
		
			
			| 
				72
			 | 
			
				
			 | 
			
			
				
				-              </Typography> 
			 | 
		
		
	
		
			
			| 
				73
			 | 
			
				
			 | 
			
			
				
				-              <Typography variant="body" > 
			 | 
		
		
	
		
			
			| 
				74
			 | 
			
				
			 | 
			
			
				
				-                {`RM ${image.price}`} 
			 | 
		
		
	
		
			
			| 
				75
			 | 
			
				
			 | 
			
			
				
				-              </Typography> 
			 | 
		
		
	
		
			
			| 
				76
			 | 
			
				
			 | 
			
			
				
				-              <Typography variant="body2" sx={{ mt: 2 }}> 
			 | 
		
		
	
		
			
			| 
				77
			 | 
			
				
			 | 
			
			
				
				-                {image.extra_desc} 
			 | 
		
		
	
		
			
			| 
				78
			 | 
			
				
			 | 
			
			
				
				-              </Typography> 
			 | 
		
		
	
		
			
			| 
				79
			 | 
			
				
			 | 
			
			
				
				-            </Box> 
			 | 
		
		
	
		
			
			| 
				80
			 | 
			
				
			 | 
			
			
				
				-          </Box> 
			 | 
		
		
	
		
			
			| 
				81
			 | 
			
				
			 | 
			
			
				
				-        </Grid>))} 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				74
			 | 
			
			
				
				+        {displayedImages.map((product, index) => { 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				75
			 | 
			
			
				
				+ 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				76
			 | 
			
			
				
				+          let { id, title, compareAtPriceRange, images, collections } = product 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				77
			 | 
			
			
				
				+          let price = compareAtPriceRange.maxVariantPrice.amount 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				78
			 | 
			
			
				
				+          let currency = compareAtPriceRange.maxVariantPrice.currencyCode 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				79
			 | 
			
			
				
				+          let img_url = images.nodes[0].url 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				80
			 | 
			
			
				
				+          let collection_name = collections.nodes[0]?.title 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				81
			 | 
			
			
				
				+ 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				82
			 | 
			
			
				
				+          // ID 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				83
			 | 
			
			
				
				+          const parts = id.split('/'); 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				84
			 | 
			
			
				
				+          let prodID = parts[parts.length - 1]; 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				85
			 | 
			
			
				
				+ 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				86
			 | 
			
			
				
				+ 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				87
			 | 
			
			
				
				+          return renderProduct(prodID, img_url, title, collection_name, price, currency, "") 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				88
			 | 
			
			
				
				+ 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				89
			 | 
			
			
				
				+        })} 
			 | 
		
		
	
		
			
			| 
				82
			 | 
			
				90
			 | 
			
			
				
				       </Grid> 
			 | 
		
		
	
		
			
			| 
				83
			 | 
			
				91
			 | 
			
			
				
				     </Box> 
			 | 
		
		
	
		
			
			| 
				84
			 | 
			
				92
			 | 
			
			
				
				   ); 
			 |