diff --git a/components/product/ProductCard/FUTURE_ProductCard.tsx b/components/product/ProductCard/FUTURE_ProductCard.tsx index 7ef41b0be..9ca615d90 100644 --- a/components/product/ProductCard/FUTURE_ProductCard.tsx +++ b/components/product/ProductCard/FUTURE_ProductCard.tsx @@ -13,6 +13,7 @@ interface Props { } const ProductCard: FC = ({ className, product, variant, imgProps }) => { + const firstImage = product.images[0] return ( {variant === 'slim' ? ( @@ -36,14 +37,16 @@ const ProductCard: FC = ({ className, product, variant, imgProps }) => {
- {product.name} + {firstImage.src && ( + {product.name} + )}
)} diff --git a/framework/types.d.ts b/framework/types.d.ts index a05f03a69..de5deb080 100644 --- a/framework/types.d.ts +++ b/framework/types.d.ts @@ -2,13 +2,13 @@ interface Product { id: string | number name: string description: string - images: Images[] + images: Image[] slug: string price: string variantId: string } -interface Images { +interface Image { src: string alt?: string } diff --git a/pages/index.tsx b/pages/index.tsx index 6ebbc8d40..8406b333c 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -12,6 +12,7 @@ import getAllPages from '@framework/api/operations/get-all-pages' // Outputs from providers should already be normalized // TODO (bc) move this to the provider + function normalize(arr: any[]) { // Normalizes products arr response and flattens node edges return arr.map( @@ -19,9 +20,15 @@ function normalize(arr: any[]) { node: { entityId: id, images, variants, productOptions, ...rest }, }) => ({ id, - images: images.edges, - variants: variants.edges, - productOptions: productOptions.edges, + images: images.edges.map( + ({ node: { urlOriginal, altText, ...rest } }: any) => ({ + url: urlOriginal, + alt: altText, + ...rest, + }) + ), + variants: variants.edges.map(({ node }: any) => node), + productOptions: productOptions.edges.map(({ node }: any) => node), ...rest, }) ) @@ -41,7 +48,7 @@ export async function getStaticProps({ const products = normalize(rawProducts) - console.log(products) + // console.log(products) const { categories, brands } = await getSiteInfo({ config, preview }) const { pages } = await getAllPages({ config, preview }) @@ -65,10 +72,10 @@ export default function Home({ return (
- {products.slice(0, 3).map(({ p }, i) => ( + {products.slice(0, 3).map((product, i) => (