diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2025-05-27 10:32:45 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2025-05-27 10:32:45 +0700 |
| commit | 62d2edfa5ae62cd8faa2d0322ddfd5dfa6ad2d2e (patch) | |
| tree | d6cceab24bd7f7c4dbfc4c0ff3ef3c932e0d9b14 /src-migrate/modules/product-detail/components | |
| parent | 6499f025995f13fcf32b2b5f79c8ee14585668fc (diff) | |
| parent | fd867a90e22fb2fc2fb16237165796ebe0cabab0 (diff) | |
<hafid> merge repeat order & new-release
Diffstat (limited to 'src-migrate/modules/product-detail/components')
| -rw-r--r-- | src-migrate/modules/product-detail/components/ProductDetail.tsx | 72 |
1 files changed, 60 insertions, 12 deletions
diff --git a/src-migrate/modules/product-detail/components/ProductDetail.tsx b/src-migrate/modules/product-detail/components/ProductDetail.tsx index f23aa9dc..0660b9c0 100644 --- a/src-migrate/modules/product-detail/components/ProductDetail.tsx +++ b/src-migrate/modules/product-detail/components/ProductDetail.tsx @@ -2,7 +2,7 @@ import style from '../styles/product-detail.module.css'; import Link from 'next/link'; import { useRouter } from 'next/router'; -import { useEffect } from 'react'; +import { useEffect, useState } from 'react'; import { Button } from '@chakra-ui/react'; import { MessageCircleIcon, Share2Icon } from 'lucide-react'; @@ -73,6 +73,16 @@ const ProductDetail = ({ product }: Props) => { // setSelectedVariant(product?.variants[0]) }, []); + // Gabungkan semua gambar produk (utama + tambahan) + const allImages = product.image_carousel ? [...product.image_carousel] : []; + + if (product.image) { + allImages.unshift(product.image); // Tambahkan gambar utama di awal array + } + console.log(product); + + const [mainImage, setMainImage] = useState(allImages[0] || ''); + return ( <> <div className='md:flex md:flex-wrap'> @@ -82,7 +92,37 @@ const ProductDetail = ({ product }: Props) => { <div className='md:w-9/12 md:flex md:flex-col md:pr-4 md:pt-6'> <div className='md:flex md:flex-wrap'> <div className='md:w-4/12'> - <ProductImage product={product} /> + <ProductImage product={{ ...product, image: mainImage }} /> + + {/* Carousel horizontal */} + {allImages.length > 0 && ( + <div className='mt-4 overflow-x-auto'> + <div className='flex space-x-3 pb-3'> + {allImages.map((img, index) => ( + <div + key={index} + className={`flex-shrink-0 w-16 h-16 cursor-pointer border-2 rounded-md transition-colors ${ + mainImage === img + ? 'border-red-500 ring-2 ring-red-200' + : 'border-gray-200 hover:border-gray-300' + }`} + onClick={() => setMainImage(img)} + > + <img + src={img} + alt={`Thumbnail ${index + 1}`} + className='w-full h-full object-cover rounded-sm' + loading='lazy' + onError={(e) => { + (e.target as HTMLImageElement).src = + '/path/to/fallback-image.jpg'; + }} + /> + </div> + ))} + </div> + </div> + )} </div> <div className='md:w-8/12 px-4 md:pl-6'> @@ -106,7 +146,12 @@ const ProductDetail = ({ product }: Props) => { )} <div className='h-4 md:h-10' /> - {!!activeVariantId && !isApproval && <ProductPromoSection product={product} productId={activeVariantId} />} + {!!activeVariantId && !isApproval && ( + <ProductPromoSection + product={product} + productId={activeVariantId} + /> + )} {/* <div className={style['section-card']}> <h2 className={style['heading']}> @@ -121,15 +166,18 @@ const ProductDetail = ({ product }: Props) => { <div className={style['section-card']}> <h2 className={style['heading']}>Informasi Produk</h2> <div className='h-4' /> - <div - className={style['description']} - dangerouslySetInnerHTML={{ - __html: - !product.description || product.description == '<p><br></p>' - ? 'Belum ada deskripsi' - : product.description, - }} - /> + <div className='overflow-x-auto'> + <div + className={style['description']} + dangerouslySetInnerHTML={{ + __html: + !product.description || + product.description == '<p><br></p>' + ? 'Belum ada deskripsi' + : product.description, + }} + /> + </div> </div> </div> </div> |
