From 1ef538546c0bdd9351baaed90b837f399584b460 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Mon, 13 Mar 2023 16:20:18 +0700 Subject: category, brand, product popular, product category in desktop home page --- src/lib/brand/components/BrandCard.jsx | 6 +- src/lib/home/components/CategoryHome.jsx | 2 +- src/lib/home/components/PopularProduct.jsx | 51 ++++++++++++---- src/lib/home/components/PreferredBrand.jsx | 21 +++++-- src/lib/product/components/ProductCard.jsx | 91 +++++++++++++++++++++++++--- src/lib/product/components/ProductSlider.jsx | 8 ++- 6 files changed, 147 insertions(+), 32 deletions(-) (limited to 'src/lib') diff --git a/src/lib/brand/components/BrandCard.jsx b/src/lib/brand/components/BrandCard.jsx index 1bcdb5ab..984a9fa6 100644 --- a/src/lib/brand/components/BrandCard.jsx +++ b/src/lib/brand/components/BrandCard.jsx @@ -1,18 +1,20 @@ import Image from '@/core/components/elements/Image/Image' import Link from '@/core/components/elements/Link/Link' +import useDevice from '@/core/hooks/useDevice' import { createSlug } from '@/core/utils/slug' const BrandCard = ({ brand }) => { + const { isMobile } = useDevice() return ( {brand.logo && ( {brand.name} )} {!brand.logo && ( diff --git a/src/lib/home/components/CategoryHome.jsx b/src/lib/home/components/CategoryHome.jsx index ac43e2bc..05f0ca28 100644 --- a/src/lib/home/components/CategoryHome.jsx +++ b/src/lib/home/components/CategoryHome.jsx @@ -6,7 +6,7 @@ const CategoryHome = ({ id }) => { const { categoryHome } = useCategoryHome({ id }) return ( -
+
{categoryHome.data ? ( { const { popularProducts } = usePopularProduct() return ( -
-
Produk Populer
- {popularProducts.isLoading && } - {!popularProducts.isLoading && ( - - )} -
+ <> + +
+
Produk Banyak Dilihat
+ {popularProducts.isLoading && } + {!popularProducts.isLoading && ( + + )} +
+
+ + +
+
+ Produk Banyak Dilihat +
+
+ {popularProducts.data && + popularProducts.data.products.map((product) => ( +
+ +
+ ))} +
+
+
+ ) } diff --git a/src/lib/home/components/PreferredBrand.jsx b/src/lib/home/components/PreferredBrand.jsx index 3df3cdb7..7edd0730 100644 --- a/src/lib/home/components/PreferredBrand.jsx +++ b/src/lib/home/components/PreferredBrand.jsx @@ -2,18 +2,31 @@ import { Swiper, SwiperSlide } from 'swiper/react' import usePreferredBrand from '../hooks/usePreferredBrand' import PreferredBrandSkeleton from './Skeleton/PreferredBrandSkeleton' import BrandCard from '@/lib/brand/components/BrandCard' +import useDevice from '@/core/hooks/useDevice' +import Link from '@/core/components/elements/Link/Link' const PreferredBrand = () => { const { preferredBrands } = usePreferredBrand() + const { isMobile, isDesktop } = useDevice() return ( -
-
Brand Pilihan
+
+
+
Brand Pilihan
+ {isDesktop && ( + + Lihat Semua + + )} +
{preferredBrands.isLoading && } {!preferredBrands.isLoading && ( {preferredBrands.data?.manufactures.map((brand) => ( diff --git a/src/lib/product/components/ProductCard.jsx b/src/lib/product/components/ProductCard.jsx index 6b88a3bd..0c11137d 100644 --- a/src/lib/product/components/ProductCard.jsx +++ b/src/lib/product/components/ProductCard.jsx @@ -3,9 +3,9 @@ import Link from '@/core/components/elements/Link/Link' import currencyFormat from '@/core/utils/currencyFormat' import { createSlug } from '@/core/utils/slug' -const ProductCard = ({ product, simpleTitle }) => { - return ( - <> +const ProductCard = ({ product, simpleTitle, variant = 'vertical' }) => { + if (variant == 'vertical') { + return (
{ {product?.name} {product.variantTotal > 1 && (
@@ -22,7 +22,7 @@ const ProductCard = ({ product, simpleTitle }) => {
)} -
+
{product?.manufacture?.name ? ( { product?.manufacture?.name, product?.manufacture.id )} - className='mb-1' + className='mb-1 font-normal' > {product.manufacture.name} @@ -39,7 +39,7 @@ const ProductCard = ({ product, simpleTitle }) => { )} @@ -47,7 +47,7 @@ const ProductCard = ({ product, simpleTitle }) => { {product?.lowestPrice?.discountPercentage > 0 && (
-
+
{currencyFormat(product?.lowestPrice?.price)}
{product?.lowestPrice?.discountPercentage}%
@@ -69,8 +69,79 @@ const ProductCard = ({ product, simpleTitle }) => { )}
- - ) + ) + } + + if (variant == 'horizontal') { + return ( +
+
+ + {product?.name} + {product.variantTotal > 1 && ( +
+ {product.variantTotal} Varian +
+ )} + +
+
+ {product?.manufacture?.name ? ( + + {product.manufacture.name} + + ) : ( +
-
+ )} + + {product?.name} + + + {product?.lowestPrice?.discountPercentage > 0 && ( +
+
{product?.lowestPrice?.discountPercentage}%
+
+ {currencyFormat(product?.lowestPrice?.price)} +
+
+ )} + +
+ {product?.lowestPrice?.priceDiscount > 0 ? ( + currencyFormat(product?.lowestPrice?.priceDiscount) + ) : ( + Call for price + )} +
+ {product?.stockTotal > 0 && ( +
+
Ready Stock
+
{product?.stockTotal > 5 ? '> 5' : '< 5'}
+
+ )} +
+
+ ) + } } export default ProductCard diff --git a/src/lib/product/components/ProductSlider.jsx b/src/lib/product/components/ProductSlider.jsx index 060d4638..ed7db486 100644 --- a/src/lib/product/components/ProductSlider.jsx +++ b/src/lib/product/components/ProductSlider.jsx @@ -5,12 +5,14 @@ import 'swiper/css' import Image from '@/core/components/elements/Image/Image' import Link from '@/core/components/elements/Link/Link' import { useRef } from 'react' +import useDevice from '@/core/hooks/useDevice' const bannerClassName = - 'absolute rounded-r top-0 left-0 h-full max-w-[52%] idt-transition border border-gray_r-6' + 'absolute rounded-r top-0 left-0 h-full w-auto md:w-[20%] idt-transition border border-gray_r-6' const ProductSlider = ({ products, simpleTitle = false, bannerMode = false }) => { const bannerRef = useRef('') + const { isMobile } = useDevice() const changeBannerOpacity = (swiper) => { if (!bannerMode) return @@ -32,8 +34,8 @@ const ProductSlider = ({ products, simpleTitle = false, bannerMode = false }) => )}