From bcf7be5a0c1d9635383605afc0600386b0b356ea Mon Sep 17 00:00:00 2001 From: Miqdad Date: Tue, 26 Aug 2025 11:41:54 +0700 Subject: Push --- .../product-detail/components/Breadcrumb.tsx | 79 +++-- .../product-detail/components/ProductDetail.tsx | 347 +++++++++++---------- 2 files changed, 232 insertions(+), 194 deletions(-) diff --git a/src-migrate/modules/product-detail/components/Breadcrumb.tsx b/src-migrate/modules/product-detail/components/Breadcrumb.tsx index f41859a9..ba53aca4 100644 --- a/src-migrate/modules/product-detail/components/Breadcrumb.tsx +++ b/src-migrate/modules/product-detail/components/Breadcrumb.tsx @@ -1,41 +1,70 @@ -import React, { Fragment } from 'react' -import { useQuery } from 'react-query' -import { getProductCategoryBreadcrumb } from '~/services/product' -import Link from 'next/link' -import { createSlug } from '~/libs/slug' +import React, { Fragment } from 'react'; +import { useQuery } from 'react-query'; +import { getProductCategoryBreadcrumb } from '~/services/product'; +import Link from 'next/link'; +import { createSlug } from '~/libs/slug'; type Props = { - id: number, - name: string -} + id: number; + name: string; +}; + +const MAX_VISIBLE_CATEGORIES = 2; // tampilkan 2 level terakhir const Breadcrumb = ({ id, name }: Props) => { - const query = useQuery({ - queryKey: ['product-category-breadcrumb'], + const { data: breadcrumbs = [] } = useQuery({ + queryKey: ['product-category-breadcrumb', id], // penting: ikutkan id queryFn: () => getProductCategoryBreadcrumb(id), - refetchOnWindowFocus: false - }) + refetchOnWindowFocus: false, + }); - const breadcrumbs = query.data || [] + const total = breadcrumbs.length; + const showEllipsis = total > MAX_VISIBLE_CATEGORIES; + const visible = showEllipsis + ? breadcrumbs.slice(total - MAX_VISIBLE_CATEGORIES) + : breadcrumbs; + const hiddenText = showEllipsis + ? breadcrumbs + .slice(0, total - MAX_VISIBLE_CATEGORIES) + .map((c) => c.name) + .join(' / ') + : ''; return ( -
- Home - / - {breadcrumbs.map((category, index) => ( - +
+ + Home + + / + + {showEllipsis && ( + <> + + … + + / + + )} + + {visible.map((category, index) => ( + {category.name} - / + / ))} - {name} + + {name}
- ) -} + ); +}; -export default Breadcrumb \ No newline at end of file +export default Breadcrumb; diff --git a/src-migrate/modules/product-detail/components/ProductDetail.tsx b/src-migrate/modules/product-detail/components/ProductDetail.tsx index e6b77fb9..8ecdb2fc 100644 --- a/src-migrate/modules/product-detail/components/ProductDetail.tsx +++ b/src-migrate/modules/product-detail/components/ProductDetail.tsx @@ -126,214 +126,223 @@ const ProductDetail = ({ product }: Props) => { }; // ============================================ - return ( - <> -
-
- -
+return ( + <> +
+
+ +
-
-
- {/* ===== Kolom kiri: gambar ===== */} -
- {/* === MOBILE: Slider swipeable, tanpa thumbnail carousel === */} - {isMobile ? ( -
-
- {allImages.length > 0 ? ( - allImages.map((img, i) => ( +
+
+ {/* ===== Kolom kiri: gambar ===== */} +
+ {/* === MOBILE: Slider swipeable, tanpa thumbnail carousel === */} + {isMobile ? ( +
+
+ {allImages.length > 0 ? ( + allImages.map((img, i) => ( + // slide tetap selebar viewport untuk snap mulus +
+ {/* gambar diperkecil */} {`Gambar { (e.target as HTMLImageElement).src = '/path/to/fallback-image.jpg'; }} /> - )) - ) : ( +
+ )) + ) : ( +
Gambar produk - )} -
- - {/* Dots indicator */} - {allImages.length > 1 && ( -
- {allImages.map((_, i) => ( -
)}
- ) : ( - <> - {/* === DESKTOP: Tetap seperti sebelumnya === */} - - - {/* Carousel horizontal (thumbnail) – hanya desktop */} - {allImages.length > 0 && ( -
-
- {allImages.map((img, index) => ( -
setMainImage(img)} - > - {`Thumbnail { - (e.target as HTMLImageElement).src = - '/path/to/fallback-image.jpg'; - }} - /> -
- ))} -
-
- )} - - )} -
- {/* <<=== TUTUP kolom kiri */} - - {/* ===== Kolom kanan: info ===== */} -
-
-

{product.name}

-
- -
-
-
-
- {isMobile && ( -
- + {/* Dots indicator */} + {allImages.length > 1 && ( +
+ {allImages.map((_, i) => ( +
+ )}
+ ) : ( + <> + {/* === DESKTOP: Tetap seperti sebelumnya === */} + + + {/* Carousel horizontal (thumbnail) – hanya desktop */} + {allImages.length > 0 && ( +
+
+ {allImages.map((img, index) => ( +
setMainImage(img)} + > + {`Thumbnail { + (e.target as HTMLImageElement).src = + '/path/to/fallback-image.jpg'; + }} + /> +
+ ))} +
+
+ )} + )} +
+ {/* <<=== TUTUP kolom kiri */} + + {/* ===== Kolom kanan: info ===== */} +
+
+

{product.name}

+
+ +
+
+
-
- {!!activeVariantId && !isApproval && ( - - )} +
+ {isMobile && ( +
+ +
+ )} -
+
+ {!!activeVariantId && !isApproval && ( + + )} -
-

Informasi Produk

-
-
-

' - ? 'Belum ada deskripsi' - : product.description, - }} - /> -
+
+ +
+

Informasi Produk

+
+
+

' + ? 'Belum ada deskripsi' + : product.description, + }} + />
+
- {isDesktop && ( -
- -
+ {isDesktop && ( +
+ +
+ + + | + + + + | + + + +
- | - - - - | +
+
Produk Serupa
- - - -
+
-
-
Produk Serupa
+ +
+ )} -
+
+
Kamu Mungkin Juga Suka
- -
- )} +
-
-
Kamu Mungkin Juga Suka
+ + + +
-
+
+
+ +); - - - -
-
-
- - ); }; -export default ProductDetail; \ No newline at end of file +export default ProductDetail; -- cgit v1.2.3