From dc14a5fd2c97d50b19b043a44d61786d98fda48b Mon Sep 17 00:00:00 2001 From: Mqdd Date: Sat, 31 Jan 2026 23:48:37 +0700 Subject: remove console log --- .../product-detail/components/Information.tsx | 393 +++++++++++++-------- 1 file changed, 248 insertions(+), 145 deletions(-) (limited to 'src-migrate/modules/product-detail/components/Information.tsx') diff --git a/src-migrate/modules/product-detail/components/Information.tsx b/src-migrate/modules/product-detail/components/Information.tsx index ce848267..757cd473 100644 --- a/src-migrate/modules/product-detail/components/Information.tsx +++ b/src-migrate/modules/product-detail/components/Information.tsx @@ -12,7 +12,16 @@ import { useEffect, useRef, useState } from 'react'; import axios from 'axios'; import currencyFormat from '@/core/utils/currencyFormat'; -import { InputGroup, InputRightElement, SimpleGrid, Flex, Text, Box, Center, Icon } from '@chakra-ui/react'; +import { + InputGroup, + InputRightElement, + SimpleGrid, + Flex, + Text, + Box, + Center, + Icon, +} from '@chakra-ui/react'; import { ChevronDownIcon } from '@heroicons/react/24/outline'; import ImageNext from 'next/image'; import { formatToShortText } from '~/libs/formatNumber'; @@ -28,7 +37,7 @@ import MobileView from '@/core/components/views/MobileView'; // Pastikan path im import ProductComparisonModal from './ProductComparisonModal'; const Skeleton = dynamic(() => - import('@chakra-ui/react').then((mod) => mod.Skeleton) + import('@chakra-ui/react').then((mod) => mod.Skeleton), ); type Props = { @@ -36,7 +45,8 @@ type Props = { }; const Information = ({ product }: Props) => { - const { selectedVariant, setSelectedVariant, setSla, sla } = useProductDetail(); + const { selectedVariant, setSelectedVariant, setSla, sla } = + useProductDetail(); const [inputValue, setInputValue] = useState(''); const [disableFilter, setDisableFilter] = useState(false); @@ -45,7 +55,7 @@ const Information = ({ product }: Props) => { // source of truth // const variantOptions = product.variants; const [variantOptions, setVariantOptions] = useState( - product?.variants + product?.variants, ); const variantId = selectedVariant?.id; @@ -59,25 +69,25 @@ const Information = ({ product }: Props) => { useEffect(() => { const fetchWarrantyDirectly = async () => { - if (!product?.variants || product.variants.length === 0) return; - - setLoadingWarranty(true); - try { - const skus = product.variants.map((v) => v.id).join(','); - const mainSku = product.variants[0].id; - - const res = await axios.get('/api/magento-product', { - params: { skus, main_sku: mainSku } - }); - - if (res.data && res.data.warranties) { - setWarranties(res.data.warranties); - } - } catch (error) { - console.error("Gagal ambil garansi:", error); - } finally { - setLoadingWarranty(false); - } + if (!product?.variants || product.variants.length === 0) return; + + setLoadingWarranty(true); + try { + const skus = product.variants.map((v) => v.id).join(','); + const mainSku = product.variants[0].id; + + const res = await axios.get('/api/magento-product', { + params: { skus, main_sku: mainSku }, + }); + + if (res.data && res.data.warranties) { + setWarranties(res.data.warranties); + } + } catch (error) { + // console.error("Gagal ambil garansi:", error); + } finally { + setLoadingWarranty(false); + } }; fetchWarrantyDirectly(); @@ -90,7 +100,7 @@ const Information = ({ product }: Props) => { selectedVariant.code + (selectedVariant.attributes?.[0] ? ` - ${selectedVariant.attributes[0]}` - : '') + : ''), ); }, [selectedVariant]); @@ -114,14 +124,14 @@ const Information = ({ product }: Props) => { setDisableFilter(true); let code = vals.replace(/\s-\s.*$/, '').trim(); let variant = product?.variants.find((item) => item.code === code); - + if (variant) { setSelectedVariant(variant); setInputValue( variant?.code + - (variant?.attributes[0] ? ' - ' + variant?.attributes[0] : '') + (variant?.attributes[0] ? ' - ' + variant?.attributes[0] : ''), ); - setVariantOptions(product?.variants); + setVariantOptions(product?.variants); } }; @@ -135,7 +145,7 @@ const Information = ({ product }: Props) => { fontSize: '13px', borderBottom: '1px dashed #e2e8f0', padding: '8px 0', - marginBottom: '0px' + marginBottom: '0px', }; return ( @@ -173,96 +183,126 @@ const Information = ({ product }: Props) => { {variantOptions .sort((a: any, b: any) => { - return a.code.localeCompare(b.code, undefined, { numeric: true, sensitivity: 'base' }); + return a.code.localeCompare(b.code, undefined, { + numeric: true, + sensitivity: 'base', + }); }) .map((option, cid) => ( - -
-
- {option.code} - {option.attributes?.[0] ? ` - ${option.attributes[0]}` : ''} -
-
- {option?.price?.discount_percentage > 0 && ( - <> -
- {Math.floor(option.price.discount_percentage)}% -
-
- {currencyFormat(option.price.price)} -
- - )} -
- {currencyFormat(option.price.price_discount)} + +
+
+ {option.code} + {option.attributes?.[0] + ? ` - ${option.attributes[0]}` + : ''} +
+
+ {option?.price?.discount_percentage > 0 && ( + <> +
+ {Math.floor(option.price.discount_percentage)}% +
+
+ {currencyFormat(option.price.price)} +
+ + )} +
+ {currencyFormat(option.price.price_discount)} +
-
- - ))} + + ))} {/* === TOMBOL BANDINGKAN PRODUK (HANYA MOBILE) === */} -
setIsCompareOpen(true)} - > -
-
- -
-
- Bandingkan Produk - Coba bandingkan dengan produk lainnya -
-
-
- Baru - -
+
setIsCompareOpen(true)} + > +
+
+ +
+
+ + Bandingkan Produk + + + Coba bandingkan dengan produk lainnya + +
+
+
+ + Baru + +
+
{/* Render Modal (Logic open/close ada di dalam component) */} {isCompareOpen && ( - setIsCompareOpen(false)} - mainProduct={product} - selectedVariant={selectedVariant} - /> + setIsCompareOpen(false)} + mainProduct={product} + selectedVariant={selectedVariant} + /> )}
{/* ITEM CODE */}
-
Item Code
+
+ Item Code +
{selectedVariant?.code}
{/* MANUFACTURE */}
-
Manufacture
+
+ Manufacture +
{!!product.manufacture.name ? ( {product?.manufacture.logo ? ( @@ -287,81 +327,144 @@ const Information = ({ product }: Props) => { {/* BERAT BARANG */}
-
Berat Barang
+
+ Berat Barang +
{selectedVariant?.weight > 0 ? `${selectedVariant.weight} Kg` : '-'}
{/* TERJUAL */} -
-
Terjual
+
+
+ Terjual +
{product.qty_sold > 0 ? formatToShortText(product.qty_sold) : '-'}
{/* === DETAIL INFORMASI PRODUK === */} -
-

+
+

Detail Informasi Produk

- + - - Distributor Resmi - - Distributor Resmi - Jaminan Produk Asli - - - - - Estimasi Penyiapan - - Estimasi Penyiapan - {isLoading ? ( -
- ) : ( - - {sla?.sla_date || '-'} - - )} -
-
- - - Garansi Produk - - Garansi Produk - {loadingWarranty ? ( -
- ) : ( - - {selectedVariant && warranties[selectedVariant.id] ? warranties[selectedVariant.id] : '-'} - - )} -
-
+ + Distributor Resmi + + + Distributor Resmi + + + Jaminan Produk Asli + + + + + + Estimasi Penyiapan + + + Estimasi Penyiapan + + {isLoading ? ( +
+ +
+ ) : ( + + {sla?.sla_date || '-'} + + )} +
+
+ + + Garansi Produk + + + Garansi Produk + + {loadingWarranty ? ( +
+ +
+ ) : ( + + {selectedVariant && warranties[selectedVariant.id] + ? warranties[selectedVariant.id] + : '-'} + + )} +
+

); }; -export default Information; \ No newline at end of file +export default Information; -- cgit v1.2.3