diff options
| author | HATEC\SPVDEV001 <tri.susilo@altama.co.id> | 2023-05-08 16:44:09 +0700 |
|---|---|---|
| committer | HATEC\SPVDEV001 <tri.susilo@altama.co.id> | 2023-05-08 16:44:09 +0700 |
| commit | 486f85a45fc7e0669576f59824a31be472ed25bb (patch) | |
| tree | 0268afa8efe48746e040611ba41ad2cafda7ad08 /src/lib/product/components/Product | |
| parent | cff198277e14450f8d20d9e18548325e6f277682 (diff) | |
| parent | 30fc50600009ca54f085d594d838803c107e87f2 (diff) | |
Merge branch 'master' into development_tri/implementasi_raja_ongkir
# Conflicts:
# src/lib/checkout/components/Checkout.jsx
Diffstat (limited to 'src/lib/product/components/Product')
| -rw-r--r-- | src/lib/product/components/Product/ProductDesktop.jsx | 209 | ||||
| -rw-r--r-- | src/lib/product/components/Product/ProductMobile.jsx | 25 |
2 files changed, 152 insertions, 82 deletions
diff --git a/src/lib/product/components/Product/ProductDesktop.jsx b/src/lib/product/components/Product/ProductDesktop.jsx index bb2b2db9..8ce6da00 100644 --- a/src/lib/product/components/Product/ProductDesktop.jsx +++ b/src/lib/product/components/Product/ProductDesktop.jsx @@ -11,7 +11,9 @@ import { updateItemCart } from '@/core/utils/cart' import { useRouter } from 'next/router' import { createSlug } from '@/core/utils/slug' import BottomPopup from '@/core/components/elements/Popup/BottomPopup' -import { Toast } from 'flowbite-react' +import ProductCard from '../ProductCard' +import productSimilarApi from '../../api/productSimilarApi' +import whatsappUrl from '@/core/utils/whatsappUrl' const ProductDesktop = ({ product, wishlist, toggleWishlist }) => { const router = useRouter() @@ -59,7 +61,6 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => { selected: true }) setAddCartAlert(true) - // toast.success('Berhasil menambahkan ke keranjang') } const handleBuy = (variantId) => { @@ -85,61 +86,117 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => { `fq=-manufacture_id_i:${product.manufacture?.id || 0}` ].join('&') + const [productSimilarInBrand, setProductSimilarInBrand] = useState(null) + + useEffect(() => { + const loadProductSimilarInBrand = async () => { + const productSimilarQuery = [product?.name, `fq=-product_id_i:${product.id}`].join('&') + const dataProductSimilar = await productSimilarApi({ query: productSimilarQuery }) + setProductSimilarInBrand(dataProductSimilar.products) + } + if (!productSimilarInBrand) loadProductSimilarInBrand() + }, [product, productSimilarInBrand]) + return ( <DesktopView> <div className='container mx-auto pt-10'> <div className='flex'> - <div className='w-[30%]'> - <Image - src={product.image} - alt={product.name} - className='h-96 object-contain object-center w-full border border-gray_r-4' - /> - </div> - <div className='w-[50%] px-4'> - <h1 className='text-title-md leading-10 font-medium'>{product?.name}</h1> - <div className='mt-10'> - <div className='flex p-3'> - <div className='w-1/4 text-gray_r-12/70'>Nomor SKU</div> - <div className='w-3/4'>SKU-{product.id}</div> - </div> - <div className='flex p-3 bg-gray_r-4'> - <div className='w-1/4 text-gray_r-12/70'>Part Number</div> - <div className='w-3/4'>{product.code || '-'}</div> + <div className='w-full flex flex-wrap'> + <div className='w-5/12'> + <Image + src={product.image} + alt={product.name} + className='h-96 object-contain object-center w-full border border-gray_r-4' + /> + </div> + + <div className='w-7/12 px-4'> + <h1 className='text-title-md leading-10 font-medium'>{product?.name}</h1> + <div className='mt-10'> + <div className='flex p-3'> + <div className='w-1/4 text-gray_r-12/70'>Nomor SKU</div> + <div className='w-3/4'>SKU-{product.id}</div> + </div> + <div className='flex p-3 bg-gray_r-4'> + <div className='w-1/4 text-gray_r-12/70'>Part Number</div> + <div className='w-3/4'>{product.code || '-'}</div> + </div> + <div className='flex p-3'> + <div className='w-1/4 text-gray_r-12/70'>Manufacture</div> + <div className='w-3/4'> + {product.manufacture?.name ? ( + <Link + href={createSlug( + '/shop/brands/', + product.manufacture?.name, + product.manufacture?.id + )} + > + {product.manufacture?.name} + </Link> + ) : ( + <div>-</div> + )} + </div> + </div> + <div className='flex p-3 bg-gray_r-4'> + <div className='w-1/4 text-gray_r-12/70'>Berat Barang</div> + <div className='w-3/4'> + {product?.weight > 0 && <span>{product?.weight} KG</span>} + {product?.weight == 0 && ( + <a + href={whatsappUrl('productWeight', { + name: product.name, + url: createSlug('/shop/product/', product.name, product.id, true) + })} + className='text-danger-500 font-medium' + > + Tanya Berat + </a> + )} + </div> + </div> </div> - <div className='flex p-3'> - <div className='w-1/4 text-gray_r-12/70'>Manufacture</div> - <div className='w-3/4'> - {product.manufacture?.name ? ( - <Link - href={createSlug( - '/shop/brands/', - product.manufacture?.name, - product.manufacture?.id - )} + </div> + + <div className='w-full'> + <div className='mt-12'> + <div className='text-h-lg font-semibold'>Informasi Produk</div> + <div className='flex gap-x-4 mt-6 mb-4'> + {informationTabOptions.map((option) => ( + <TabButton + value={option.value} + key={option.value} + active={informationTab == option.value} + onClick={() => setInformationTab(option.value)} > - {product.manufacture?.name} - </Link> - ) : ( - <div>-</div> - )} + {option.label} + </TabButton> + ))} </div> - </div> - <div className='flex p-3 bg-gray_r-4'> - <div className='w-1/4 text-gray_r-12/70'>Berat Barang</div> - <div className='w-3/4'> - {product?.weight > 0 && <span>{product?.weight} KG</span>} - {product?.weight == 0 && ( - <a href='https://wa.me' className='text-danger-500 font-medium'> - Tanya Berat - </a> - )} + <div className='flex'> + <div className='w-3/4 leading-7 product__description'> + <TabContent active={informationTab == 'description'}> + <span + dangerouslySetInnerHTML={{ + __html: + product.description != '' + ? product.description + : 'Belum ada deskripsi produk.' + }} + /> + </TabContent> + + <TabContent active={informationTab == 'information'}> + Belum ada informasi. + </TabContent> + </div> </div> </div> </div> </div> - <div className='w-[20%]'> + <div className='w-[25%]'> {product.variants.length > 1 && product.lowestPrice.priceDiscount > 0 && ( <div className='text-gray_r-12/80'>Harga mulai dari: </div> )} @@ -160,7 +217,13 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => { ) : ( <span className='text-gray_r-12/90 font-normal text-h-sm'> Hubungi kami untuk dapatkan harga terbaik, - <a href='https://wa.me/' className='text-danger-500 underline'> + <a + href={whatsappUrl('product', { + name: product.name, + url: createSlug('/shop/product/', product.name, product.id, true) + })} + className='text-danger-500 underline' + > klik disini </a> </span> @@ -209,6 +272,20 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => { Wishlist </button> </div> + + <div className='border border-gray_r-6 overflow-auto mt-4'> + <div className='font-medium text-center p-4 bg-gray_r-1 border-b border-gray_r-6 sticky top-0 z-10'> + Produk Serupa + </div> + <div className='h-full divide-y divide-gray_r-6 max-h-96'> + {productSimilarInBrand && + productSimilarInBrand?.map((product) => ( + <div className='py-2' key={product.id}> + <ProductCard product={product} variant='horizontal' /> + </div> + ))} + </div> + </div> </div> </div> @@ -244,7 +321,13 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => { {variant.price.priceDiscount > 0 ? ( currencyFormat(variant.price.priceDiscount) ) : ( - <a href='https://wa.me/' className='text-red_r-11'> + <a + href={whatsappUrl('product', { + name: variant.name, + url: createSlug('/shop/product/', product.name, product.id, true) + })} + className='text-red_r-11' + > Call for price </a> )} @@ -283,38 +366,6 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => { </div> )} - <div className='mt-12'> - <div className='text-h-lg font-semibold'>Informasi Produk</div> - <div className='flex gap-x-4 mt-6 mb-4'> - {informationTabOptions.map((option) => ( - <TabButton - value={option.value} - key={option.value} - active={informationTab == option.value} - onClick={() => setInformationTab(option.value)} - > - {option.label} - </TabButton> - ))} - </div> - <div className='flex'> - <div className='w-3/4 leading-7 product__description'> - <TabContent active={informationTab == 'description'}> - <span - dangerouslySetInnerHTML={{ - __html: - product.description != '' - ? product.description - : 'Belum ada deskripsi produk.' - }} - /> - </TabContent> - - <TabContent active={informationTab == 'information'}>Belum ada informasi.</TabContent> - </div> - </div> - </div> - <div className='my-12'> <div className='text-h-lg font-semibold mb-6'>Kamu Mungkin Juga Suka</div> <LazyLoad> diff --git a/src/lib/product/components/Product/ProductMobile.jsx b/src/lib/product/components/Product/ProductMobile.jsx index b75a191b..426fe1b8 100644 --- a/src/lib/product/components/Product/ProductMobile.jsx +++ b/src/lib/product/components/Product/ProductMobile.jsx @@ -13,6 +13,7 @@ import MobileView from '@/core/components/views/MobileView' import { toast } from 'react-hot-toast' import { createSlug } from '@/core/utils/slug' import BottomPopup from '@/core/components/elements/Popup/BottomPopup' +import whatsappUrl from '@/core/utils/whatsappUrl' const ProductMobile = ({ product, wishlist, toggleWishlist }) => { const router = useRouter() @@ -152,7 +153,13 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => { ) : ( <span className='text-gray_r-11 leading-6 font-normal'> Hubungi kami untuk dapatkan harga terbaik, - <a href='https://wa.me/' className='text-danger-500 underline'> + <a + href={whatsappUrl('product', { + name: product.name, + url: createSlug('/shop/product/', product.name, product.id, true) + })} + className='text-danger-500 underline' + > klik disini </a> </span> @@ -236,7 +243,13 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => { </span> )} {activeVariant?.stock == 0 && ( - <a href='https://wa.me' className='text-danger-500 font-medium'> + <a + href={whatsappUrl('product', { + name: product.name, + url: createSlug('/shop/product/', product.name, product.id, true) + })} + className='text-danger-500 font-medium' + > Tanya Stok </a> )} @@ -244,7 +257,13 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => { <SpecificationContent label='Berat Barang'> {activeVariant?.weight > 0 && <span>{activeVariant?.weight} KG</span>} {activeVariant?.weight == 0 && ( - <a href='https://wa.me' className='text-danger-500 font-medium'> + <a + href={whatsappUrl('productWeight', { + name: product.name, + url: createSlug('/shop/product/', product.name, product.id, true) + })} + className='text-danger-500 font-medium' + > Tanya Berat </a> )} |
