summaryrefslogtreecommitdiff
path: root/src/lib/product
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-07-23 14:29:08 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-07-23 14:29:08 +0700
commitb1341b76e94da9e64549768646bb54d2836976d0 (patch)
treef6151a95c4ac7e7b91835d0c7c46e2814521a17a /src/lib/product
parentbf5c3b1d48da54e0e44689412ad9de9c10cf9edb (diff)
<iman> update categories management
Diffstat (limited to 'src/lib/product')
-rw-r--r--src/lib/product/components/CategorySection.jsx109
1 files changed, 68 insertions, 41 deletions
diff --git a/src/lib/product/components/CategorySection.jsx b/src/lib/product/components/CategorySection.jsx
index 749a56eb..14a39e7e 100644
--- a/src/lib/product/components/CategorySection.jsx
+++ b/src/lib/product/components/CategorySection.jsx
@@ -1,15 +1,23 @@
-import Image from "next/image"
-import Link from 'next/link'
-import { createSlug } from '@/core/utils/slug'
+import Image from "next/image";
+import Link from 'next/link';
+import { createSlug } from '@/core/utils/slug';
import useDevice from '@/core/hooks/useDevice';
import { Swiper, SwiperSlide } from 'swiper/react';
import 'swiper/css';
-import { useQuery } from 'react-query'
-import { useRouter } from 'next/router'
+import { useQuery } from 'react-query';
+import { useRouter } from 'next/router';
+import {
+ ChevronDownIcon,
+ ChevronUpIcon, // Import ChevronUpIcon for toggling
+ DocumentCheckIcon,
+ HeartIcon,
+} from '@heroicons/react/24/outline';
+import { useState } from 'react'; // Import useState
const CategorySection = ({ categories }) => {
const { isDesktop, isMobile } = useDevice();
- const router = useRouter()
+ const router = useRouter();
+ const [isOpenCategory, setIsOpenCategory] = useState(false); // State to manage category visibility
let teks = router.query.slug;
let hasil = teks?.match(/(\d+)$/)[0];
@@ -17,18 +25,24 @@ const CategorySection = ({ categories }) => {
const breadcrumbs = useQuery(
`category-breadcrumbs/${hasil}`,
async () => await odooApi('GET', `/api/v1/category/${hasil}/category-breadcrumb`)
- )
-
+ );
+
+ const handleToggleCategories = () => {
+ setIsOpenCategory(!isOpenCategory);
+ };
+
+ const displayedCategories = isOpenCategory ? categories : categories.slice(0, 10);
+
return (
<section>
{isDesktop && (
<div className="group/item grid grid-cols-5 gap-y-2 gap-x-2 w-full h-full col-span-2 ">
- {categories.slice(0, 10).map((category) => (
+ {displayedCategories.map((category) => (
<Link href={createSlug('/shop/category/', category?.name, category?.id)} key={category?.id} passHref>
<div className="group transition-colors duration-300 ">
<div className="KartuInti h-12 w-26 max-w-sm lg:max-w-full flex flex-col border-[2px] border-gray-200 group-hover:border-red-400 rounded relative ">
- <div className="flex items-center justify-start h-full px-1 flex-row">
- <Image className="" src={category?.image1920? category?.image1920 : '/images/noimage.jpeg'} width={56} height={48} alt={category?.name} />
+ <div className="flex items-center justify-start h-full px-1 flex-row ">
+ <Image className="h-full" src={category?.image1920 ? category?.image1920 : '/images/noimage.jpeg'} width={56} height={48} alt={category?.name} />
<h2 className="text-gray-700 group-hover:text-[#E20613] line-clamp-2 content-center h-fit w-60 px-1 font-semibold text-sm text-start">{category?.name}</h2>
</div>
</div>
@@ -38,45 +52,58 @@ const CategorySection = ({ categories }) => {
</div>
)}
{isDesktop && categories.length > 10 && (
- <div className="w-full flex justify-end mt-4">
- <Link className=" flex justify-end mt-4 bg-red-500 text-white px-4 py-2 rounded" href={createSlug('/shop/category/', breadcrumbs.data[0]?.name, breadcrumbs.data[0]?.id)}>Lihat Semua
- </Link>
- </div>
+ <div className="w-full flex justify-center mt-4">
+ <button
+ onClick={handleToggleCategories}
+ className="flex justify-end mt-4 text-red-500 font-bold px-4 py-2 rounded"
+ >
+ {isOpenCategory ? 'Sembunyikan' : 'Lihat semua'}
+ {isOpenCategory ? (
+ <ChevronUpIcon className="ml-auto w-5 font-bold" />
+ ) : (
+ <ChevronDownIcon className="ml-auto w-5 font-bold" />
+ )}
+ </button>
+ </div>
)}
- {isMobile &&
+ {isMobile && (
<div className="py-4">
<Swiper slidesPerView={2.3} spaceBetween={10}>
- {categories.slice(0, 10).map((category) => (
- <SwiperSlide key={category?.id}>
- <Link href={createSlug('/shop/category/', category?.name, category?.id)} passHref>
- <div className="group transition-colors duration-300">
- <div className="KartuInti h-18 w-26 max-w-sm lg:max-w-full flex flex-col border-[2px] border-gray-200 group-hover:bg-red-200 group-hover:border-red-400 rounded relative">
- <div className="flex items-center justify-center h-full px-1 flex-row">
- <Image
- src={category?.image1920 ? category?.image1920 : '/images/noimage.jpeg'}
- width={56}
- height={48}
- alt={category?.name}
- />
- <h2 className="text-gray-700 group-hover:text-[#E20613] line-clamp-2 content-center h-fit w-60 px-1 font-semibold text-sm text-start">
- {category?.name}
- </h2>
- </div>
- </div>
- </div>
- </Link>
- </SwiperSlide>
- ))}
+ {displayedCategories.map((category) => (
+ <SwiperSlide key={category?.id}>
+ <Link href={createSlug('/shop/category/', category?.name, category?.id)} passHref>
+ <div className="group transition-colors duration-300">
+ <div className="KartuInti min-h-16 max-h-16 w-26 max-w-sm lg:max-w-full flex flex-col border-[2px] border-gray-200 group-hover:bg-red-200 group-hover:border-red-400 rounded relative">
+ <div className="flex items-center justify-center h-full px-1 flex-row">
+ <Image
+ src={category?.image1920 ? category?.image1920 : '/images/noimage.jpeg'}
+ width={56}
+ height={48}
+ alt={category?.name}
+ />
+ <h2 className="text-gray-700 group-hover:text-[#E20613] line-clamp-2 content-center h-fit w-60 px-1 font-semibold text-sm text-start">
+ {category?.name}
+ </h2>
+ </div>
+ </div>
+ </div>
+ </Link>
+ </SwiperSlide>
+ ))}
</Swiper>
- {categories.length > 10 && (
+ {categories.length > 10 && (
<div className="w-full flex justify-end mt-4">
- <Link className=" flex justify-end mt-4 bg-red-500 text-white text-sm px-4 py-2 rounded" href={createSlug('/shop/category/', breadcrumbs.data[0]?.name, breadcrumbs.data[0]?.id)}>Lihat Semua
- </Link>
+ <button
+ onClick={handleToggleCategories}
+ className="flex justify-end mt-4 bg-red-500 text-white text-sm px-4 py-2 rounded"
+ >
+ {isOpenCategory ? 'Sembunyikan Semua' : 'Lihat Semua'}
+ </button>
</div>
)}
</div>
- }
+ )}
</section>
)
}