import { Skeleton } from '@chakra-ui/react'; import { HeartIcon } from '@heroicons/react/24/outline'; import { useRouter } from 'next/router'; import { useEffect, useState } from 'react'; import { toast } from 'react-hot-toast'; import LazyLoad from 'react-lazy-load'; import odooApi from '@/core/api/odooApi'; 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 BottomPopup from '@/core/components/elements/Popup/BottomPopup'; import MobileView from '@/core/components/views/MobileView'; import { updateItemCart } from '@/core/utils/cart'; import currencyFormat from '@/core/utils/currencyFormat'; import { gtagAddToCart } from '@/core/utils/googleTag'; import { createSlug } from '@/core/utils/slug'; import whatsappUrl from '@/core/utils/whatsappUrl'; import ProductSimilar from '../ProductSimilar'; 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.lowestPrice; return lowest; }; const [activeVariant, setActiveVariant] = useState({ id: null, code: product.code, name: product.name, price: getLowestPrice(), stock: product.stockTotal, weight: product.weight, isFlashSale: product.isFlashSale, }); useEffect(() => { if (selectedVariant) { setActiveVariant({ id: product.id, code: product.code, name: product.name, price: product.price, stock: product.stockTotal, weight: product.weight, isFlashSale: product.isFlashSale, }); } }, [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.isFlashSale && activeVariant?.price?.discountPercentage > 0 ? ( <>
{activeVariant?.price?.discountPercentage}%
{currencyFormat(activeVariant?.price?.price)}
{currencyFormat(activeVariant?.price?.priceDiscount)}
Termasuk PPN:{' '} {currencyFormat( activeVariant?.price.priceDiscount * process.env.NEXT_PUBLIC_PPN )}
) : (

{activeVariant?.price?.price > 0 ? ( <> {currencyFormat(activeVariant?.price?.price)}
Termasuk PPN:{' '} {currencyFormat( activeVariant?.price.price * process.env.NEXT_PUBLIC_PPN )}
) : ( 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;