summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-03-13 16:20:18 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-03-13 16:20:18 +0700
commit1ef538546c0bdd9351baaed90b837f399584b460 (patch)
tree9e0c6c1ab34adecdfcdccf70e2159f219ed217b8 /src/lib
parentd26133d39e7d9cd510fdc72d239303f4ba918bdd (diff)
category, brand, product popular, product category in desktop home page
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/brand/components/BrandCard.jsx6
-rw-r--r--src/lib/home/components/CategoryHome.jsx2
-rw-r--r--src/lib/home/components/PopularProduct.jsx51
-rw-r--r--src/lib/home/components/PreferredBrand.jsx21
-rw-r--r--src/lib/product/components/ProductCard.jsx91
-rw-r--r--src/lib/product/components/ProductSlider.jsx8
6 files changed, 147 insertions, 32 deletions
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 (
<Link
href={createSlug('/shop/brands/', brand.name, brand.id)}
- className='py-1 px-2 rounded border border-gray_r-6 h-12 flex justify-center items-center'
+ className={`py-1 px-2 rounded border border-gray_r-6 flex justify-center items-center ${isMobile ? 'h-16' : 'h-24'}`}
>
{brand.logo && (
<Image
src={brand.logo}
alt={brand.name}
- className='h-full object-contain object-center'
+ className='h-full w-full object-contain object-center'
/>
)}
{!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 (
- <div className='p-4 relative bg-yellow_r-2'>
+ <div className='p-4 sm:py-8 relative bg-yellow_r-2 border border-yellow_r-5'>
{categoryHome.data ? (
<ProductSlider
products={{
diff --git a/src/lib/home/components/PopularProduct.jsx b/src/lib/home/components/PopularProduct.jsx
index d23275f7..78dc5d49 100644
--- a/src/lib/home/components/PopularProduct.jsx
+++ b/src/lib/home/components/PopularProduct.jsx
@@ -1,23 +1,50 @@
-import { Swiper, SwiperSlide } from 'swiper/react'
import usePopularProduct from '../hooks/usePopularProduct'
-import ProductCard from '@/lib/product/components/ProductCard'
import PopularProductSkeleton from './Skeleton/PopularProductSkeleton'
import ProductSlider from '@/lib/product/components/ProductSlider'
+import DesktopView from '@/core/components/views/DesktopView'
+import MobileView from '@/core/components/views/MobileView'
+import ProductCard from '@/lib/product/components/ProductCard'
const PopularProduct = () => {
const { popularProducts } = usePopularProduct()
return (
- <div className='px-4'>
- <div className='font-medium mb-4'>Produk Populer</div>
- {popularProducts.isLoading && <PopularProductSkeleton />}
- {!popularProducts.isLoading && (
- <ProductSlider
- products={popularProducts.data}
- simpleTitle
- />
- )}
- </div>
+ <>
+ <MobileView>
+ <div className='px-4'>
+ <div className='font-medium mb-4'>Produk Banyak Dilihat</div>
+ {popularProducts.isLoading && <PopularProductSkeleton />}
+ {!popularProducts.isLoading && (
+ <ProductSlider
+ products={popularProducts.data}
+ simpleTitle
+ />
+ )}
+ </div>
+ </MobileView>
+
+ <DesktopView>
+ <div className='border border-gray_r-6 h-full overflow-auto'>
+ <div className='font-medium text-center p-4 bg-gray_r-1 border-b border-gray_r-6 sticky top-0 z-10'>
+ Produk Banyak Dilihat
+ </div>
+ <div className='h-full divide-y divide-gray_r-6'>
+ {popularProducts.data &&
+ popularProducts.data.products.map((product) => (
+ <div
+ className='py-2'
+ key={product.id}
+ >
+ <ProductCard
+ product={product}
+ variant='horizontal'
+ />
+ </div>
+ ))}
+ </div>
+ </div>
+ </DesktopView>
+ </>
)
}
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 (
- <div className='px-4'>
- <div className='font-medium mb-4'>Brand Pilihan</div>
+ <div className='px-4 sm:px-0'>
+ <div className='flex justify-between items-center mb-4'>
+ <div className='font-medium sm:text-h-lg'>Brand Pilihan</div>
+ {isDesktop && (
+ <Link
+ href='/'
+ className='btn-yellow !text-gray_r-12'
+ >
+ Lihat Semua
+ </Link>
+ )}
+ </div>
{preferredBrands.isLoading && <PreferredBrandSkeleton />}
{!preferredBrands.isLoading && (
<Swiper
- slidesPerView={3.5}
- spaceBetween={12}
+ slidesPerView={isMobile ? 3.5 : 7.5}
+ spaceBetween={isMobile ? 12 : 24}
freeMode
>
{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 (
<div className='rounded shadow-sm border border-gray_r-4 h-full bg-white'>
<Link
href={createSlug('/shop/product/', product?.name, product?.id)}
@@ -14,7 +14,7 @@ const ProductCard = ({ product, simpleTitle }) => {
<Image
src={product?.image}
alt={product?.name}
- className='w-full object-contain object-center h-36'
+ className='w-full object-contain object-center h-36 sm:h-48'
/>
{product.variantTotal > 1 && (
<div className='absolute badge-gray bottom-1.5 left-1.5'>
@@ -22,7 +22,7 @@ const ProductCard = ({ product, simpleTitle }) => {
</div>
)}
</Link>
- <div className='p-2 pb-3 text-caption-2 leading-5'>
+ <div className='p-2 sm:p-3 pb-3 text-caption-2 sm:text-body-2 leading-5'>
{product?.manufacture?.name ? (
<Link
href={createSlug(
@@ -30,7 +30,7 @@ const ProductCard = ({ product, simpleTitle }) => {
product?.manufacture?.name,
product?.manufacture.id
)}
- className='mb-1'
+ className='mb-1 font-normal'
>
{product.manufacture.name}
</Link>
@@ -39,7 +39,7 @@ const ProductCard = ({ product, simpleTitle }) => {
)}
<Link
href={createSlug('/shop/product/', product?.name, product?.id)}
- className={`font-medium mb-2 !text-gray_r-12 ${
+ className={`font-normal mb-2 !text-gray_r-12 ${
simpleTitle ? 'line-clamp-2' : 'line-clamp-3'
}`}
>
@@ -47,7 +47,7 @@ const ProductCard = ({ product, simpleTitle }) => {
</Link>
{product?.lowestPrice?.discountPercentage > 0 && (
<div className='flex gap-x-1 mb-1 items-center'>
- <div className='text-gray_r-11 line-through text-[11px]'>
+ <div className='text-gray_r-11 line-through text-[11px] sm:text-caption-2'>
{currencyFormat(product?.lowestPrice?.price)}
</div>
<div className='badge-solid-red'>{product?.lowestPrice?.discountPercentage}%</div>
@@ -69,8 +69,79 @@ const ProductCard = ({ product, simpleTitle }) => {
)}
</div>
</div>
- </>
- )
+ )
+ }
+
+ if (variant == 'horizontal') {
+ return (
+ <div className='flex bg-white'>
+ <div className='w-4/12'>
+ <Link
+ href={createSlug('/shop/product/', product?.name, product?.id)}
+ className='relative'
+ >
+ <Image
+ src={product?.image}
+ alt={product?.name}
+ className='w-full object-contain object-center h-36'
+ />
+ {product.variantTotal > 1 && (
+ <div className='absolute badge-gray bottom-1.5 left-1.5'>
+ {product.variantTotal} Varian
+ </div>
+ )}
+ </Link>
+ </div>
+ <div className='w-8/12 p-2'>
+ {product?.manufacture?.name ? (
+ <Link
+ href={createSlug(
+ '/shop/brands/',
+ product?.manufacture?.name,
+ product?.manufacture.id
+ )}
+ className='mb-1 font-normal'
+ >
+ {product.manufacture.name}
+ </Link>
+ ) : (
+ <div>-</div>
+ )}
+ <Link
+ href={createSlug('/shop/product/', product?.name, product?.id)}
+ className={`font-normal mb-2 !text-gray_r-12 ${
+ simpleTitle ? 'line-clamp-2' : 'line-clamp-3'
+ }`}
+ >
+ {product?.name}
+ </Link>
+
+ {product?.lowestPrice?.discountPercentage > 0 && (
+ <div className='flex gap-x-1 mb-1 items-center'>
+ <div className='badge-solid-red'>{product?.lowestPrice?.discountPercentage}%</div>
+ <div className='text-gray_r-11 line-through text-caption-2'>
+ {currencyFormat(product?.lowestPrice?.price)}
+ </div>
+ </div>
+ )}
+
+ <div className='text-red_r-11 font-semibold mb-2'>
+ {product?.lowestPrice?.priceDiscount > 0 ? (
+ currencyFormat(product?.lowestPrice?.priceDiscount)
+ ) : (
+ <a href='https://wa.me/'>Call for price</a>
+ )}
+ </div>
+ {product?.stockTotal > 0 && (
+ <div className='flex gap-x-1'>
+ <div className='badge-solid-red'>Ready Stock</div>
+ <div className='badge-gray'>{product?.stockTotal > 5 ? '> 5' : '< 5'}</div>
+ </div>
+ )}
+ </div>
+ </div>
+ )
+ }
}
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 }) =>
)}
<Swiper
freeMode={{ enabled: true, sticky: false }}
- slidesPerView={2.2}
- spaceBetween={8}
+ slidesPerView={isMobile ? 2.2 : 5.6}
+ spaceBetween={isMobile ? 8 : 16}
onSliderMove={changeBannerOpacity}
onSlideChangeTransitionEnd={changeBannerOpacity}
onSlideChangeTransitionStart={changeBannerOpacity}