From d178a520534af7d1cbcc03134034ad8a2327b461 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Mon, 20 Mar 2023 17:14:16 +0700 Subject: product detail and cart header --- src/lib/product/components/ProductDesktop.jsx | 279 -------------------------- 1 file changed, 279 deletions(-) delete mode 100644 src/lib/product/components/ProductDesktop.jsx (limited to 'src/lib/product/components/ProductDesktop.jsx') diff --git a/src/lib/product/components/ProductDesktop.jsx b/src/lib/product/components/ProductDesktop.jsx deleted file mode 100644 index 55d44212..00000000 --- a/src/lib/product/components/ProductDesktop.jsx +++ /dev/null @@ -1,279 +0,0 @@ -import Image from '@/core/components/elements/Image/Image' -import Link from '@/core/components/elements/Link/Link' -import DesktopView from '@/core/components/views/DesktopView' -import currencyFormat from '@/core/utils/currencyFormat' -import { HeartIcon } from '@heroicons/react/24/outline' -import { Fragment, useEffect, useRef, useState } from 'react' -import LazyLoad from 'react-lazy-load' -import ProductSimilar from './ProductSimilar' -import { toast } from 'react-hot-toast' -import { updateItemCart } from '@/core/utils/cart' - -const ProductDesktop = ({ product, wishlist, toggleWishlist }) => { - const [variantQuantity, setVariantQuantity] = useState(null) - const [informationTab, setInformationTab] = useState(informationTabOptions[0].value) - - useEffect(() => { - const mapVariantQuantity = product.variants.reduce((acc, cur) => { - acc[cur.id] = '1' - return acc - }, {}) - setVariantQuantity(mapVariantQuantity) - }, [product]) - - const changeQuantity = (variantId, quantity) => { - setVariantQuantity((variantQuantity) => ({ ...variantQuantity, [variantId]: quantity })) - } - - const variantSectionRef = useRef(null) - const goToVariantSection = () => { - if (variantSectionRef.current) { - const position = variantSectionRef.current.getBoundingClientRect() - window.scrollTo({ - top: position.top - 120 + window.pageYOffset, - behavior: 'smooth' - }) - } - } - - const validAction = (variantId) => { - let isValid = true - if ( - !variantQuantity[variantId] || - variantQuantity[variantId] < 1 || - isNaN(parseInt(variantQuantity[variantId])) - ) { - toast.error('Jumlah barang minimal 1') - isValid = false - } - return isValid - } - - const handleAddToCart = (variantId) => { - if (!validAction(variantId)) return - updateItemCart({ - productId: variantId, - quantity: variantQuantity[variantId] - }) - toast.success('Berhasil menambahkan ke keranjang') - } - - const productSimilarQuery = [ - product?.name.replace(/[()/"&]/g, ''), - `fq=-product_id:${product.id}`, - `fq=-manufacture_id:${product.manufacture?.id || 0}` - ].join('&') - - return ( - -
-
-
- {product.name} -
-
-

{product?.name}

-
-
-
Nomor SKU
-
SKU-{product.id}
-
-
-
Part Number
-
{product.code || '-'}
-
-
-
Manufacture
-
- {product.manufacture?.name ? ( - {product.manufacture?.name} - ) : ( -
-
- )} -
-
-
-
Berat Barang
-
- {product?.weight > 0 && {product?.weight} KG} - {product?.weight == 0 && ( - - Tanya Berat - - )} -
-
-
-
- -
- {product.variants.length > 1 && product.lowestPrice.priceDiscount > 0 && ( -
Harga mulai dari:
- )} - {product?.lowestPrice.discountPercentage > 0 && ( -
-
- {product?.lowestPrice.discountPercentage}% -
-
- {currencyFormat(product?.lowestPrice.price)} -
-
- )} -

- {product?.lowestPrice.priceDiscount > 0 ? ( - currencyFormat(product?.lowestPrice.priceDiscount) - ) : ( - - Hubungi kami untuk dapatkan harga terbaik,  - - klik disini - - - )} -

- - -
- -
-
-
- -
-
Varian Produk
-
- - - - - - - - - - - {product.variants.map((variant) => ( - - - - - - - ))} - -
Part NumberHargaJumlahAction
{variant.code} - {variant.price.discountPercentage > 0 && ( - <> - - {currencyFormat(variant.price.price)} - {' '} - - )} - {currencyFormat(variant.price.priceDiscount)} - - changeQuantity(variant.id, e.target.value)} - /> - - - -
-
-
- -
-
Informasi Produk
-
-
- {informationTabOptions.map((option) => ( - setInformationTab(option.value)} - > - {option.label} - - ))} -
-
-
- - - - - Belum ada informasi. -
-
-
- -
-
Kamu Mungkin Juga Suka
- - - -
-
- - ) -} - -const informationTabOptions = [ - { value: 'description', label: 'Deskripsi' }, - { value: 'information', label: 'Info Penting' } -] - -const TabButton = ({ children, active, ...props }) => { - const activeClassName = active - ? 'text-red_r-11 underline underline-offset-4' - : 'text-gray_r-12/80' - return ( - - ) -} - -const TabContent = ({ children, active, className = '', ...props }) => ( -
- {children} -
-) - -export default ProductDesktop -- cgit v1.2.3