import Divider from '@/core/components/elements/Divider/Divider' import Image from '@/core/components/elements/Image/Image' import Link from '@/core/components/elements/Link/Link' import currencyFormat from '@/core/utils/currencyFormat' import { useEffect, useState } from 'react' import Select from 'react-select' import ProductSimilar from '../ProductSimilar' import LazyLoad from 'react-lazy-load' import { updateItemCart } from '@/core/utils/cart' import { HeartIcon } from '@heroicons/react/24/outline' import { useRouter } from 'next/router' 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' import { gtagAddToCart } from '@/core/utils/googleTag' import odooApi from '@/core/api/odooApi' import { Skeleton } from '@chakra-ui/react' const ProductMobileVariant = ({ product, wishlist, toggleWishlist }) => { const router = useRouter() const [quantity, setQuantity] = useState('1') const [selectedVariant, setSelectedVariant] = useState(product.id) const [informationTab, setInformationTab] = useState(informationTabOptions[0].value) const [addCartAlert, setAddCartAlert] = useState(false) const [isLoadingSLA, setIsLoadingSLA] = useState(true) const getLowestPrice = () => { const lowest = product.price return lowest } const [activeVariant, setActiveVariant] = useState({ id: null, code: product.code, name: product.name, price: getLowestPrice(), stock: product.stockTotal, weight: product.weight }) useEffect(() => { if (selectedVariant) { setActiveVariant({ id: product.id, code: product.code, name: product.name, price: product.price, stock: product.stock, weight: product.weight }) } }, [selectedVariant, product]) const validAction = () => { let isValid = true if (!selectedVariant) { toast.error('Pilih varian terlebih dahulu') isValid = false } if (!quantity || quantity < 1 || isNaN(parseInt(quantity))) { toast.error('Jumlah barang minimal 1') isValid = false } return isValid } const handleClickCart = () => { if (!validAction()) return gtagAddToCart(activeVariant, quantity) updateItemCart({ productId: variant, quantity, programLineId: null, selected: true, source: null }) setAddCartAlert(true) } const handleClickBuy = () => { if (!validAction()) return updateItemCart({ productId: product.id, quantity, programLineId: null, selected: true, source: 'buy' }) router.push(`/shop/checkout?source=buy`) } const productSimilarQuery = [ product?.name, `fq=-product_id_i:${product.id}`, `fq=-manufacture_id_i:${product.manufacture?.id || 0}` ].join('&') useEffect(() => { const fetchData = async () => { const dataSLA = await odooApi('GET', `/api/v1/product_variant/${product.id}/stock`) product.sla = dataSLA setIsLoadingSLA(false) } fetchData() }, [product]) return ( {product.name}
{product.manufacture?.name ? ( {product.manufacture?.name} ) : (
-
)}

{activeVariant?.name}

{activeVariant?.price?.priceDiscount > 0 ? ( <>
Harga Sebelum PPN :
{' '} {currencyFormat(activeVariant?.price?.priceDiscount)}
Termasuk PPN :
{activeVariant?.price?.discountPercentage > 0 && ( <>
{activeVariant?.price?.discountPercentage}%
{currencyFormat(activeVariant?.price?.price * 1.11)}
)}

{currencyFormat(activeVariant?.price?.priceDiscount * 1.11)}

) : ( Hubungi kami untuk dapatkan harga terbaik,  klik disini )}
Jumlah
setQuantity(e.target.value)} />

Informasi Produk

{informationTabOptions.map((option) => ( setInformationTab(option.value)} > {option.label} ))}
{isLoadingSLA ? ( ) : product?.sla?.slaDate != '-' ? ( ) : ( '-' )} SKU-{product?.id} {activeVariant?.code || '-'} {activeVariant?.stock > 0 && (
Ready Stock
{activeVariant?.stock > 5 ? '> 5' : '< 5'}
)} {activeVariant?.stock == 0 && ( Tanya Stok )}
{activeVariant?.weight > 0 && {activeVariant?.weight} KG} {activeVariant?.weight == 0 && ( Tanya Berat )}

Kamu Mungkin Juga Suka

setAddCartAlert(false)} >
{product.name}
{product.name}
Lihat Keranjang
Kamu Mungkin Juga Suka
) } const informationTabOptions = [ { value: 'specification', label: 'Spesifikasi' } // { value: 'description', label: 'Deskripsi' }, // { value: 'information', label: 'Info Penting' } ] const TabButton = ({ children, active, ...props }) => { const activeClassName = active ? 'text-danger-500 underline underline-offset-4' : 'text-gray_r-11' return ( ) } const TabContent = ({ children, active, className, ...props }) => (
{children}
) const SpecificationContent = ({ children, label }) => (
{label} {children}
) export default ProductMobileVariant