From ab4819716063f4d7eb4578cbcb0d66077145bdab Mon Sep 17 00:00:00 2001 From: FIN-IT_AndriFP Date: Mon, 12 Jan 2026 13:33:39 +0700 Subject: (andri) fix index table spek & fix view detail information di mobile --- .../product-detail/components/Information.tsx | 88 +++++++++-------- .../product-detail/components/ProductDetail.tsx | 106 +++++++++++++-------- 2 files changed, 114 insertions(+), 80 deletions(-) diff --git a/src-migrate/modules/product-detail/components/Information.tsx b/src-migrate/modules/product-detail/components/Information.tsx index c565682f..e07537fb 100644 --- a/src-migrate/modules/product-detail/components/Information.tsx +++ b/src-migrate/modules/product-detail/components/Information.tsx @@ -9,10 +9,10 @@ import style from '../styles/information.module.css'; import dynamic from 'next/dynamic'; import Link from 'next/link'; import { useEffect, useRef, useState } from 'react'; -import axios from 'axios'; // <--- 1. TAMBAHAN IMPORT AXIOS +import axios from 'axios'; import currencyFormat from '@/core/utils/currencyFormat'; -import { InputGroup, InputRightElement, SimpleGrid, Flex, Text, Box } from '@chakra-ui/react'; +import { InputGroup, InputRightElement, SimpleGrid, Flex, Text, Box, Center } from '@chakra-ui/react'; import { ChevronDownIcon } from '@heroicons/react/24/outline'; import Image from 'next/image'; import { formatToShortText } from '~/libs/formatNumber'; @@ -54,23 +54,16 @@ const Information = ({ product }: Props) => { setLoadingWarranty(true); try { - // Ambil semua SKU untuk dikirim ke API const skus = product.variants.map((v) => v.id).join(','); const mainSku = product.variants[0].id; - console.log("Fetching warranties for SKUs:", skus); - console.log("Main SKU:", mainSku); - // Panggil API magento-product const res = await axios.get('/api/magento-product', { params: { skus, main_sku: mainSku } }); - // Simpan hasil ke state lokal if (res.data && res.data.warranties) { setWarranties(res.data.warranties); } - console.log("Warranties API Response:", res); - console.log("Warranties fetched:", res.data.warranties); } catch (error) { console.error("Gagal ambil garansi:", error); } finally { @@ -80,8 +73,6 @@ const Information = ({ product }: Props) => { fetchWarrantyDirectly(); }, [product]); - // ====================================================== - useEffect(() => { if (selectedVariant) { @@ -103,27 +94,26 @@ const Information = ({ product }: Props) => { } }, [slaVariant, isLoading, setSla]); -const handleOnChange = (vals: any) => { -    setDisableFilter(true); -    let code = vals.replace(/\s-\s.*$/, '').trim(); -    let variant = product?.variants.find((item) => item.code === code); -    + const handleOnChange = (vals: any) => { + 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] : '') -    ); + setSelectedVariant(variant); + setInputValue( + variant?.code + + (variant?.attributes[0] ? ' - ' + variant?.attributes[0] : '') + ); setVariantOptions(product?.variants); -    } -  }; + } + }; const handleOnKeyUp = (e: any) => { setDisableFilter(false); setInputValue(e.target.value); }; - // STYLE CUSTOM UNTUK BARIS (Item Code, dll) const rowStyle = { backgroundColor: '#ffffff', fontSize: '13px', @@ -275,37 +265,49 @@ const handleOnChange = (vals: any) => { - {/* === DETAIL INFORMASI PRODUK (Updated Layout) === */} + {/* === DETAIL INFORMASI PRODUK (Horizontal Minimalis) === */}

Detail Informasi Produk

- + {/* Mobile: 3 Kolom, Spacing Kecil. Desktop: 3 Kolom, Spacing Besar */} + + {/* 1. Distributor Resmi */} - + Distributor Resmi - Distributor Resmi - Jaminan Produk Asli + Distributor Resmi + Jaminan Produk Asli {/* 2. Estimasi Penyiapan */} - + Estimasi Penyiapan - Estimasi Penyiapan + Estimasi Penyiapan {isLoading ? ( - +
) : ( - + {sla?.sla_date || '3 - 7 Hari'} )} @@ -313,20 +315,24 @@ const handleOnChange = (vals: any) => {
{/* 3. Garansi Produk */} - + Garansi Produk - Garansi Produk + Garansi Produk - {/* Menggunakan Loading State & Data dari 'warranties' */} {loadingWarranty ? ( - +
) : ( - + {selectedVariant && warranties[selectedVariant.id] ? warranties[selectedVariant.id] : '-'} diff --git a/src-migrate/modules/product-detail/components/ProductDetail.tsx b/src-migrate/modules/product-detail/components/ProductDetail.tsx index 7ca2f9a7..04bf5533 100644 --- a/src-migrate/modules/product-detail/components/ProductDetail.tsx +++ b/src-migrate/modules/product-detail/components/ProductDetail.tsx @@ -60,6 +60,45 @@ const RWebShare = dynamic( () => import('react-web-share').then((m) => m.RWebShare), { ssr: false } ); +// 1. STYLE DESKTOP (Tebal, Jelas, dengan Border/Padding) +const cssScrollbarDesktop = { + '&::-webkit-scrollbar': { + width: '10px', + height: '10px', + }, + '&::-webkit-scrollbar-track': { + background: '#f1f1f1', + borderRadius: '4px', + }, + '&::-webkit-scrollbar-thumb': { + backgroundColor: '#9ca3af', // Gray-400 + borderRadius: '6px', + border: '2px solid #f1f1f1', // Efek padding + }, + '&::-webkit-scrollbar-thumb:hover': { + backgroundColor: '#6b7280', + }, +}; + +// 2. STYLE MOBILE (Tipis, Minimalis, Tanpa Border) +const cssScrollbarMobile = { + '&::-webkit-scrollbar': { + width: '8px', // Sangat tipis vertikal + height: '8px', // Sangat tipis horizontal + }, + '&::-webkit-scrollbar-track': { + background: '#f1f1f1', + borderRadius: '4px', + }, + '&::-webkit-scrollbar-thumb': { + backgroundColor: '#9ca3af', // Gray-400 + borderRadius: '6px', + border: '2px solid #f1f1f1', // Efek padding + }, + '&::-webkit-scrollbar-thumb:hover': { + backgroundColor: '#6b7280', + }, +}; const SELF_HOST = process.env.NEXT_PUBLIC_SELF_HOST; @@ -494,7 +533,7 @@ const ProductDetail = ({ product }: Props) => { Deskripsi Spesifikasi - Detail Lainnya + {/* Detail Lainnya */} @@ -514,29 +553,13 @@ const ProductDetail = ({ product }: Props) => { overflowX="auto" overflowY="auto" maxHeight="500px" - css={{ - '&::-webkit-scrollbar': { - width: '12px', - height: '12px', - }, - '&::-webkit-scrollbar-track': { - background: '#f1f1f1', - }, - '&::-webkit-scrollbar-thumb': { - backgroundColor: '#a0aec0', - borderRadius: '8px', - border: '4px solid transparent', - backgroundClip: 'content-box', - }, - '&::-webkit-scrollbar-thumb:hover': { - backgroundColor: '#718096', - }, - }} + css={isMobile ? cssScrollbarMobile : cssScrollbarDesktop} > {loadingSpecs ? (
) : specsMatrix.length > 0 ? ( (() => { + // --- 1. PROSES DATA --- const topHeaders: any[] = []; const subHeaders: any[] = []; const flatSpecs: any[] = []; @@ -564,17 +587,19 @@ const ProductDetail = ({ product }: Props) => { } }); + // --- 2. RENDER TABLE (Z-INDEX DITURUNKAN) --- return ( - - - {/* Baris 1: Header Utama */} +
+ {/* Turun dari 20 ke 3 */} + {/* Row 1: Header Utama */} {topHeaders.map((th, idx) => ( ))} - - {/* Baris 2: Sub Header */} + + {/* Row 2: Sub Header */} - {subHeaders.map((sub, idx) => { + {subHeaders.map((sub, idx) => { const isFirstHeaderGroup = topHeaders[0]?.type === 'group'; const shouldSticky = idx === 0 && isFirstHeaderGroup; return ( @@ -622,35 +651,34 @@ const ProductDetail = ({ product }: Props) => { })} - + {sortedVariants.map((v, vIdx) => ( {flatSpecs.map((spec, sIdx) => { const rawValue = spec.values[v.id] || '-'; - const isFirstCol = sIdx === 0; + const isFirstCol = sIdx === 0; return ( @@ -669,7 +697,7 @@ const ProductDetail = ({ product }: Props) => { {/* DETAIL LAINNYA */} -

Informasi tambahan belum tersedia.

+ {/*

Informasi tambahan belum tersedia.

*/} -- cgit v1.2.3
4, dan 20 -> 3 boxShadow={idx === 0 ? "2px 0 5px -2px rgba(0,0,0,0.2)" : "none"} bg="red.600" @@ -582,29 +607,31 @@ const ProductDetail = ({ product }: Props) => { rowSpan={th.rowSpan} color="white" textAlign="center" - fontSize="sm" + fontSize={isMobile ? "xs" : "sm"} textTransform="none" fontWeight="800" letterSpacing="wide" verticalAlign="middle" borderBottom="none" + px={isMobile ? 2 : 4} > {th.label}
4 boxShadow={shouldSticky ? "2px 0 5px -2px rgba(0,0,0,0.2)" : "none"} color="white" @@ -614,7 +641,9 @@ const ProductDetail = ({ product }: Props) => { verticalAlign="middle" whiteSpace="nowrap" bg="red.600" + borderBottom="none" pt={1} pb={1} + px={isMobile ? 2 : 4} > {sub.label}
2 bg={vIdx % 2 === 0 ? 'white' : 'gray.50'} boxShadow={isFirstCol ? "2px 0 5px -2px rgba(0,0,0,0.1)" : "none"} - // ================================= borderColor="gray.200" textAlign="center" - fontSize="sm" + fontSize={isMobile ? "xs" : "sm"} verticalAlign="middle" - px={2} + px={isMobile ? 1 : 2} py={3} - minW="100px" - maxW="150px" + minW={isMobile ? "100px" : "120px"} + maxW="200px" whiteSpace="normal" overflowWrap="break-word" - fontWeight={isFirstCol ? "bold" : "normal"} + fontWeight={isFirstCol ? "bold" : "normal"} > {renderSpecValue(rawValue)}