summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortri.susilo <tri.susilo@altama.co.id>2024-05-08 14:47:11 +0700
committertri.susilo <tri.susilo@altama.co.id>2024-05-08 14:47:11 +0700
commit6b173eaf8a95432316822b1d41b084875adfbd83 (patch)
treea979594bb1986c230f24566d2c79d8b6669ef3a9 /src
parentd169ea22f8823f1bd9a94614ae2529677e0688ab (diff)
[agnes] - Feature category management
Diffstat (limited to 'src')
-rw-r--r--src/lib/category/components/Category.jsx79
-rw-r--r--src/lib/home/components/CategoryPilihan.jsx32
-rw-r--r--src/lib/product/components/CategorySection.jsx22
-rw-r--r--src/lib/product/components/ProductSearch.jsx20
-rw-r--r--src/pages/index.jsx22
-rw-r--r--src/pages/shop/category/[slug].jsx9
-rw-r--r--src/styles/globals.css5
7 files changed, 166 insertions, 23 deletions
diff --git a/src/lib/category/components/Category.jsx b/src/lib/category/components/Category.jsx
index e6ea5acf..c147a3b3 100644
--- a/src/lib/category/components/Category.jsx
+++ b/src/lib/category/components/Category.jsx
@@ -2,10 +2,14 @@ import odooApi from '@/core/api/odooApi'
import Link from '@/core/components/elements/Link/Link'
import DesktopView from '@/core/components/views/DesktopView'
import { createSlug } from '@/core/utils/slug'
+import { ChevronRightIcon } from '@heroicons/react/24/outline'
+import Image from 'next/image'
import { useEffect, useState } from 'react'
const Category = () => {
const [categories, setCategories] = useState([])
+ const [openCategories, setOpenCategory] = useState([]);
+
useEffect(() => {
const loadCategories = async () => {
@@ -31,7 +35,7 @@ const Category = () => {
<DesktopView>
<div className='category-mega-box'>
{categories?.map((category) => (
- <div key={category.id}>
+ <div key={category.id} className='flex'>
<Link
href={createSlug('/shop/category/', category.name, category.id)}
className='category-mega-box__parent'
@@ -39,33 +43,74 @@ const Category = () => {
{category.name}
</Link>
<div className='category-mega-box__child-wrapper'>
- <div className='grid grid-cols-3 gap-x-4 gap-y-6 max-h-full overflow-auto'>
+ <div className='grid grid-cols-3 gap-x-4 gap-y-6 max-h-full !w-[590px] overflow-auto'>
{category.childs.map((child1Category) => (
- <div key={child1Category.id}>
+ <div key={child1Category.id} className='w-full'>
<Link
href={createSlug('/shop/category/', child1Category.name, child1Category.id)}
- className='category-mega-box__child-one mb-4'
+ className='category-mega-box__child-one mb-4 w-full h-8 flex justify-center line-clamp-2'
>
{child1Category.name}
</Link>
- <div className='flex flex-col gap-y-3'>
- {child1Category.childs.map((child2Category) => (
- <Link
- href={createSlug(
- '/shop/category/',
- child2Category.name,
- child2Category.id
- )}
- className='category-mega-box__child-two'
- key={child2Category.id}
- >
- {child2Category.name}
- </Link>
+ <div className='flex flex-col gap-y-3 w-full'>
+ {child1Category.childs.map((child2Category, index) => (
+ (index < 4) && (
+ <Link
+ href={createSlug('/shop/category/', child2Category.name, child2Category.id)}
+ className='category-mega-box__child-two truncate'
+ key={child2Category.id}
+ >
+ {child2Category.name}
+ </Link>
+ )
))}
+ {child1Category.childs.length > 5 && (
+ <div className='flex hover:bg-gray_r-8/35 rounded-10'>
+ <Link
+ href={createSlug('/shop/category/', child1Category.name, child1Category.id)}
+ className='category-mega-box__child-one flex items-center gap-4 font-bold hover:ml-4'
+ >
+ <p className='mt-2 mb-0 text-danger-500 font-semibold'>Lihat Semua</p>
+ <ChevronRightIcon className='w-4 text-danger-500 font-bold' />
+ </Link>
+ </div>
+ )}
</div>
</div>
))}
</div>
+ <div className='category-mega-box__child-wrapper !w-[260px] !flex !flex-col !gap-4'>
+ <div className='flex flex-col'>
+ <div className='grid grid-cols-2 max-h-full w-full gap-2'>
+ {category.childs.map((brand, index) => (
+ (index < 8 ) && (
+ <div key={brand.id} className='w-full flex items-center justify-center pb-2'>
+ <Link
+ href={createSlug('/shop/category/', brand.name, brand.id)}
+ className='category-mega-box__child-one w-fit h-full flex items-center justify-center '
+ >
+ <Image src='https://erp.indoteknik.com/api/image/x_manufactures/x_logo_manufacture/661' alt='' width={104} height={44} objectFit='cover' />
+ </Link>
+ </div>
+ )
+ ))}
+ </div>
+ {category.childs.length > 8 && (
+ <div className='flex hover:bg-gray_r-8/35 rounded-10'>
+ <Link
+ href={createSlug('/shop/category/', category.name, category.id)}
+ className='category-mega-box__child-one flex items-center gap-4 font-bold hover:ml-4'
+ >
+ <p className='mt-2 mb-0 text-danger-500 font-semibold'>Lihat Semua Brand</p>
+ <ChevronRightIcon className='w-4 text-danger-500 font-bold' />
+ </Link>
+ </div>
+ )}
+ </div>
+ <div className='flex w-60 h-20 object-cover'>
+ <Image src='https://erp.indoteknik.com/api/image/x_banner.banner/x_banner_image/397' alt='' width={275} height={4} />
+ </div>
+ </div>
</div>
</div>
))}
diff --git a/src/lib/home/components/CategoryPilihan.jsx b/src/lib/home/components/CategoryPilihan.jsx
new file mode 100644
index 00000000..c506ef29
--- /dev/null
+++ b/src/lib/home/components/CategoryPilihan.jsx
@@ -0,0 +1,32 @@
+import Image from 'next/image'
+import useCategoryHome from '../hooks/useCategoryHome'
+
+const CategoryPilihan = ({ id, categories }) => {
+ const { categoryHome } = useCategoryHome({ id })
+
+ return (
+ <section>
+ <div className='flex flex-row items-center gap-4'>
+ <h1>Kategori Pilihan</h1>
+ <p className='text-gray_r-10'>total produk</p>
+ </div>
+ <div className="group/item grid grid-cols-6 gap-2 w-full h-full col-span-2 border">
+ {categories.map((category) => (
+ <div className="max-w-sm w-full gap-4 lg:max-w-full flex flex-col bg-white px-4 py-2 border-2 border-gray_r-8 rounded-lg">
+ <div className="group/edit flex items-center justify-center group-hover/item:visible">
+ <Image src='group-hover/ https://erp.indoteknik.com/api/image/product.template/image_256/544371?ratio=square' width={80} height={80} alt={category?.name} />
+ <a class="group/edit invisible hover:bg-slate-200 group-hover/item:visible ..." href="tel:{person.phone}">
+ <span class="group-hover/edit:text-gray-700 ...">Call</span>
+ </a>
+ </div>
+ <div className="flex flex-col justify-center leading-normal items-center">
+ <h2 className="text-gray-900 font-bold text-sm items-center text-center">{category?.name}</h2>
+ </div>
+ </div>
+ ))}
+ </div>
+ </section>
+ )
+}
+
+export default CategoryPilihan
diff --git a/src/lib/product/components/CategorySection.jsx b/src/lib/product/components/CategorySection.jsx
new file mode 100644
index 00000000..7c347fe8
--- /dev/null
+++ b/src/lib/product/components/CategorySection.jsx
@@ -0,0 +1,22 @@
+import Image from "next/image"
+
+const CategorySection = ({ categories }) => {
+ return (
+ <section className="items-center bg-danger-100">
+ <div className="grid grid-cols-4 gap-2 w-full h-full col-span-2">
+ {categories.map((category) => (
+ <div class="max-w-sm w-fit gap-4 lg:max-w-full lg:flex bg-white px-4 py-2 border-2 border-gray_r-8 rounded-lg">
+ <div className="flex items-center justify-center">
+ <Image src='https://erp.indoteknik.com/api/image/product.template/image_256/544371?ratio=square' width={80} height={80} alt={category?.name} />
+ </div>
+ <div class="flex flex-col justify-center leading-normal">
+ <h2 class="text-gray-900 font-bold text-sm">{category?.name}</h2>
+ </div>
+ </div>
+ ))}
+ </div>
+ </section>
+ )
+}
+
+export default CategorySection \ No newline at end of file
diff --git a/src/lib/product/components/ProductSearch.jsx b/src/lib/product/components/ProductSearch.jsx
index 08b64c13..253c3703 100644
--- a/src/lib/product/components/ProductSearch.jsx
+++ b/src/lib/product/components/ProductSearch.jsx
@@ -26,6 +26,8 @@ import ProductSearchSkeleton from './Skeleton/ProductSearchSkeleton';
import SideBanner from '~/modules/side-banner';
import FooterBanner from '~/modules/footer-banner';
+import CategorySection from './CategorySection';
+import { getIdFromSlug } from '@/core/utils/slug'
const ProductSearch = ({
query,
@@ -68,6 +70,10 @@ const ProductSearch = ({
const productStart = productSearch.data?.responseHeader.params.start;
const productRows = limit;
const productFound = productSearch.data?.response.numFound;
+ const [dataCategories, setDataCategories] = useState([])
+
+ const categoryId = getIdFromSlug(prefixUrl)
+
useEffect(() => {
if (productFound == 0 && query.q && !spellings) {
@@ -116,6 +122,18 @@ const ProductSearch = ({
}
}, [q]);
+ useEffect(() => {
+ const loadCategories = async () => {
+ const getCategories = await odooApi('GET', '/api/v1/category/child?partner_id='+{categoryId})
+ if(getCategories){
+ setDataCategories(getCategories)
+ }
+ }
+ loadCategories()
+ }, [])
+
+ console.log('Data Category : ', dataCategories)
+
const brands = [];
for (
let i = 0;
@@ -409,7 +427,9 @@ const ProductSearch = ({
<SideBanner />
</div>
+
<div className='w-9/12 pl-6'>
+ <CategorySection categories={dataCategories}/>
{bannerPromotionHeader && bannerPromotionHeader?.image && (
<div className='mb-3'>
<Image
diff --git a/src/pages/index.jsx b/src/pages/index.jsx
index c097530c..9675c355 100644
--- a/src/pages/index.jsx
+++ b/src/pages/index.jsx
@@ -1,5 +1,5 @@
import dynamic from 'next/dynamic';
-import { useRef } from 'react';
+import { useEffect, useRef, useState } from 'react';
import { HeroBannerSkeleton } from '@/components/skeleton/BannerSkeleton';
import { PopularProductSkeleton } from '@/components/skeleton/PopularProductSkeleton';
@@ -11,6 +11,9 @@ import { FlashSaleSkeleton } from '@/lib/flashSale/skeleton/FlashSaleSkeleton';
import PreferredBrandSkeleton from '@/lib/home/components/Skeleton/PreferredBrandSkeleton';
import PromotinProgram from '@/lib/promotinProgram/components/HomePage';
import PagePopupIformation from '~/modules/popup-information';
+import CategoryPilihan from '../lib/home/components/CategoryPilihan';
+import odooApi from '@/core/api/odooApi';
+import { getIdFromSlug } from '@/core/utils/slug'
const BasicLayout = dynamic(() =>
import('@/core/components/layouts/BasicLayout')
@@ -52,7 +55,7 @@ const CustomerReviews = dynamic(() =>
);
const ServiceList = dynamic(() => import('@/lib/home/components/ServiceList'));
-export default function Home() {
+export default function Home({categoryId}) {
const bannerRef = useRef(null);
const wrapperRef = useRef(null);
@@ -61,6 +64,18 @@ export default function Home() {
bannerRef.current?.querySelector(':first-child')?.clientHeight + 'px';
};
+ const [dataCategories, setDataCategories] = useState([])
+
+ useEffect(() => {
+ const loadCategories = async () => {
+ const getCategories = await odooApi('GET', '/api/v1/category/child?partner_id='+{categoryId})
+ if(getCategories){
+ setDataCategories(getCategories)
+ }
+ }
+ loadCategories()
+ }, [])
+
return (
<BasicLayout>
<Seo
@@ -104,7 +119,8 @@ export default function Home() {
</div>
<FlashSale />
<PromotinProgram />
- <CategoryHomeId />
+ <CategoryPilihan categories={dataCategories}/>
+ {/* <CategoryHomeId /> */}
<BannerSection />
<CustomerReviews />
</div>
diff --git a/src/pages/shop/category/[slug].jsx b/src/pages/shop/category/[slug].jsx
index 1afe30bf..11840d47 100644
--- a/src/pages/shop/category/[slug].jsx
+++ b/src/pages/shop/category/[slug].jsx
@@ -5,6 +5,8 @@ import { useRouter } from 'next/router';
import Seo from '@/core/components/Seo';
import { getIdFromSlug, getNameFromSlug } from '@/core/utils/slug';
import Breadcrumb from '@/lib/category/components/Breadcrumb';
+import { useEffect, useState } from 'react';
+import odooApi from '@/core/api/odooApi';
const BasicLayout = dynamic(() =>
import('@/core/components/layouts/BasicLayout')
@@ -12,10 +14,14 @@ const BasicLayout = dynamic(() =>
const ProductSearch = dynamic(() =>
import('@/lib/product/components/ProductSearch')
);
+const CategorySection = dynamic(() =>
+ import('@/lib/product/components/CategorySection')
+)
export default function CategoryDetail() {
const router = useRouter();
const { slug = '', page = 1 } = router.query;
+ const [dataCategories, setDataCategories] = useState([])
const categoryName = getNameFromSlug(slug);
const categoryId = getIdFromSlug(slug);
@@ -43,8 +49,9 @@ export default function CategoryDetail() {
<Breadcrumb categoryId={categoryId} />
+
{!_.isEmpty(router.query) && (
- <ProductSearch query={query} prefixUrl={`/shop/category/${slug}`} />
+ <ProductSearch query={query} categories ={categoryId} prefixUrl={`/shop/category/${slug}`} />
)}
</BasicLayout>
);
diff --git a/src/styles/globals.css b/src/styles/globals.css
index f6561b00..505dcab4 100644
--- a/src/styles/globals.css
+++ b/src/styles/globals.css
@@ -583,12 +583,11 @@ button {
@apply absolute
left-[100%]
top-12
- w-[40vw]
bg-gray_r-1/90
backdrop-blur-md
border
border-gray_r-6
- p-6
+ p-6
opacity-0
h-full
transition-all
@@ -604,6 +603,7 @@ button {
transition-colors
ease-linear
duration-100
+ w-fit
font-semibold;
}
@@ -613,6 +613,7 @@ button {
transition-colors
ease-linear
duration-100
+ w-full
font-normal;
}