import React, { useEffect } from 'react'; import { Box, Typography, Button } from '@mui/material'; import Grid from '@mui/material/Grid2'; //REDUX import { useSelector, useDispatch } from 'react-redux'; import { fetchProducts } from '../../redux/slices/productSlice'; const ProductList = ({ size = 99999 }) => { const products = useSelector((state) => state.products.products.data) const dispatch = useDispatch(); useEffect(() => { dispatch(fetchProducts()) }, []) useEffect(() => { if(products) console.log(products) }, [products]) const renderProduct = (id, img_url, title, collection, price, currency, extra_desc) => { return ( { window.location.href = `/products/${id}` }} sx={{ overflow: 'hidden', position: 'relative', cursor: 'pointer' }} > {title} {/* */} {collection} {title} {`${currency} ${price}`} {extra_desc} ) } return ( {products.map((product, index) => { let {id, title, compareAtPriceRange, images, collections} = product let price = compareAtPriceRange.maxVariantPrice.amount let currency = compareAtPriceRange.maxVariantPrice.currencyCode let img_url = images.nodes[0].url let collection_name = collections.nodes[0]?.title // ID const parts = id.split('/'); let prodID = parts[parts.length - 1]; if (index < size) { return renderProduct(prodID, img_url, title, collection_name, price, currency, "" ) } })} ); }; export default ProductList;