summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/category/components/Category.jsx4
-rw-r--r--src/lib/category/components/PopularBrand.jsx88
-rw-r--r--src/lib/checkout/components/Checkout.jsx19
-rw-r--r--src/lib/home/components/CategoryDynamic.jsx171
-rw-r--r--src/lib/home/components/CategoryDynamicMobile.jsx4
5 files changed, 156 insertions, 130 deletions
diff --git a/src/lib/category/components/Category.jsx b/src/lib/category/components/Category.jsx
index f76e6e42..91553295 100644
--- a/src/lib/category/components/Category.jsx
+++ b/src/lib/category/components/Category.jsx
@@ -86,14 +86,14 @@ const Category = () => {
</div>
))}
</div>
- <div className='category-mega-box__child-wrapper !w-[260px] !flex !flex-col !gap-4'>
+ {/* <div className='category-mega-box__child-wrapper !w-[260px] !flex !flex-col !gap-4'>
<PopularBrand category={category} />
{Array.isArray(promotionProgram?.data) && promotionProgram?.data.length > 0 && promotionProgram?.data[0]?.map((banner, index) => (
<div key={index} className='flex w-60 h-20 object-cover'>
<Image src={`${banner.image}`} alt={`${banner.name}`} width={275} height={4} />
</div>
))}
- </div>
+ </div> */}
</div>
</div>
))}
diff --git a/src/lib/category/components/PopularBrand.jsx b/src/lib/category/components/PopularBrand.jsx
index 4777fded..8124b5b4 100644
--- a/src/lib/category/components/PopularBrand.jsx
+++ b/src/lib/category/components/PopularBrand.jsx
@@ -13,60 +13,60 @@ import { fetchPopulerProductSolr } from '../api/popularProduct'
const SOLR_HOST = process.env.SOLR_HOST
const PopularBrand = ({ category }) => {
- const [topBrands, setTopBrands] = useState([]);
+ // const [topBrands, setTopBrands] = useState([]);
- const fetchTopBrands = async () => {
- try {
- const items = await fetchPopulerProductSolr(`category_id_ids:(${category?.categoryDataIds?.join(' OR ')})`);
- const getTop12UniqueBrands = (prod) => {
- const brandMap = new Map();
+ // const fetchTopBrands = async () => {
+ // try {
+ // const items = await fetchPopulerProductSolr(`category_id_ids:(${category?.categoryDataIds?.join(' OR ')})`);
+ // const getTop12UniqueBrands = (prod) => {
+ // const brandMap = new Map();
- for (const product of prod) {
- const { manufacture_name, manufacture_id, qty_sold } = product;
+ // for (const product of prod) {
+ // const { manufacture_name, manufacture_id, qty_sold } = product;
- if (brandMap.has(manufacture_name)) {
- // Update the existing brand's qty_sold
- brandMap.set(manufacture_name, {
- name: manufacture_name,
- id: manufacture_id,
- qty_sold: brandMap.get(manufacture_name).qty_sold + qty_sold
- });
- } else {
- // Add a new brand to the map
- brandMap.set(manufacture_name, {
- name: manufacture_name,
- id: manufacture_id,
- qty_sold
- });
- }
- }
+ // if (brandMap.has(manufacture_name)) {
+ // // Update the existing brand's qty_sold
+ // brandMap.set(manufacture_name, {
+ // name: manufacture_name,
+ // id: manufacture_id,
+ // qty_sold: brandMap.get(manufacture_name).qty_sold + qty_sold
+ // });
+ // } else {
+ // // Add a new brand to the map
+ // brandMap.set(manufacture_name, {
+ // name: manufacture_name,
+ // id: manufacture_id,
+ // qty_sold
+ // });
+ // }
+ // }
- // Convert the map to an array and sort by qty_sold in descending order
- const sortedBrands = Array.from(brandMap.values()).sort((a, b) => b.qty_sold - a.qty_sold);
+ // // Convert the map to an array and sort by qty_sold in descending order
+ // const sortedBrands = Array.from(brandMap.values()).sort((a, b) => b.qty_sold - a.qty_sold);
- // Return the top 12 brands
- return sortedBrands.slice(0, 18);
- };
+ // // Return the top 12 brands
+ // return sortedBrands.slice(0, 18);
+ // };
- // Using the fetched products
- const products = items;
- const top12UniqueBrands = getTop12UniqueBrands(products);
+ // // Using the fetched products
+ // const products = items;
+ // const top12UniqueBrands = getTop12UniqueBrands(products);
- // Set the top 12 brands to the state
- setTopBrands(top12UniqueBrands);
- } catch (error) {
- console.error("Error fetching data from Solr", error);
- throw error;
- }
- }
+ // // Set the top 12 brands to the state
+ // setTopBrands(top12UniqueBrands);
+ // } catch (error) {
+ // console.error("Error fetching data from Solr", error);
+ // throw error;
+ // }
+ // }
- useEffect(() => {
- fetchTopBrands();
- }, [category]);
+ // useEffect(() => {
+ // fetchTopBrands();
+ // }, [category]);
return (
<div className='flex flex-col'>
- <div className='grid grid-cols-3 max-h-full w-full gap-2'>
+ {/* <div className='grid grid-cols-3 max-h-full w-full gap-2'>
{topBrands.map((brand, index) => (
<div key={index} className='w-full flex items-center justify-center pb-2'>
<Link
@@ -77,7 +77,7 @@ const PopularBrand = ({ category }) => {
</Link>
</div>
))}
- </div>
+ </div> */}
{/* {topBrands.length > 8 && (
<div className='flex hover:bg-gray_r-8/35 rounded-10'>
<Link
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index 54acdf7c..913bd273 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -174,7 +174,6 @@ const Checkout = () => {
}
return; // Hentikan eksekusi lebih lanjut pada iterasi ini
}
-
// Memeriksa apakah subtotal memenuhi syarat minimal pembelian
if (cartCheckout?.subtotal < addNewLine.minPurchaseAmount) {
SetSelisihHargaCode(
@@ -191,7 +190,9 @@ const Checkout = () => {
// Tambahkan voucher ke list dan set voucher aktif
SetListVoucher((prevList) => [addNewLine, ...prevList]);
- SetActiveVoucher(addNewLine.code);
+ if (addNewLine.canApply) {
+ SetActiveVoucher(addNewLine.code);
+ }
} else {
// Mencari voucher dalam listVoucherShippings
let checkList = listVoucherShippings?.findIndex(
@@ -227,7 +228,9 @@ const Checkout = () => {
// Tambahkan voucher ke list pengiriman dan set voucher aktif pengiriman
SetListVoucherShipping((prevList) => [addNewLine, ...prevList]);
- setActiveVoucherShipping(addNewLine.code);
+ if (addNewLine.canApply) {
+ setActiveVoucherShipping(addNewLine.code);
+ }
}
});
@@ -701,7 +704,9 @@ const Checkout = () => {
{listVoucherShippings && listVoucherShippings?.length > 0 && (
<div>
- <h3 className='font-semibold mb-4'>Promo Extra Potongan Ongkir</h3>
+ <h3 className='font-semibold mb-4'>
+ Promo Extra Potongan Ongkir
+ </h3>
{listVoucherShippings?.map((item) => (
<div key={item.id} className='relative'>
<div
@@ -1028,7 +1033,7 @@ const Checkout = () => {
</div>
<span className='leading-5'>
Jika mengalami kesulitan dalam melakukan pembelian di website
- Indoteknik. Hubungi kami disini
+ Indoteknik. <a href={whatsappUrl()}>Hubungi kami disini</a>
</span>
</Alert>
</div>
@@ -1236,10 +1241,10 @@ const Checkout = () => {
className='object-contain object-center h-6 rounded-md'
/>
</span>
- {activeVoucher ? (
+ {activeVoucher || activeVoucherShipping ? (
<div className=''>
<div className='text-left text-sm text-black font-semibold'>
- Potongan Senilai {currencyFormat(discountVoucher)}
+ Potongan Senilai {currencyFormat(totalDiscountVoucher)}
</div>
<div className='text-left mt-1 text-green-600 text-xs'>
Voucher berhasil digunakan
diff --git a/src/lib/home/components/CategoryDynamic.jsx b/src/lib/home/components/CategoryDynamic.jsx
index b7798a24..c257e9f9 100644
--- a/src/lib/home/components/CategoryDynamic.jsx
+++ b/src/lib/home/components/CategoryDynamic.jsx
@@ -4,102 +4,123 @@ import NextImage from 'next/image';
import Link from "next/link";
import { createSlug } from '@/core/utils/slug';
import odooApi from '@/core/api/odooApi';
-import { Skeleton} from '@chakra-ui/react'
+import { Skeleton } from '@chakra-ui/react';
+import { Swiper, SwiperSlide } from 'swiper/react';
+import 'swiper/css';
+import 'swiper/css/navigation';
+import 'swiper/css/pagination';
+import { Navigation, Pagination, Autoplay } from 'swiper';
const CategoryDynamic = () => {
const { categoryManagement } = useCategoryManagement();
- const [categoryData, setCategoryData] = useState({});
- const [subCategoryData, setSubCategoryData] = useState({});
+ // const [categoryData, setCategoryData] = useState({});
+ // const [subCategoryData, setSubCategoryData] = useState({});
- useEffect(() => {
- const fetchCategoryData = async () => {
- if (categoryManagement && categoryManagement.data) {
- const updatedCategoryData = {};
- const updatedSubCategoryData = {};
+ // useEffect(() => {
+ // const fetchCategoryData = async () => {
+ // if (categoryManagement && categoryManagement.data) {
+ // const updatedCategoryData = {};
+ // const updatedSubCategoryData = {};
- for (const category of categoryManagement.data) {
- const countLevel1 = await odooApi('GET', `/api/v1/category/numFound?parent_id=${category.categoryIdI}`);
+ // for (const category of categoryManagement.data) {
+ // const countLevel1 = await odooApi('GET', `/api/v1/category/numFound?parent_id=${category.categoryIdI}`);
- updatedCategoryData[category.categoryIdI] = countLevel1?.numFound;
+ // updatedCategoryData[category.categoryIdI] = countLevel1?.numFound;
- for (const subCategory of countLevel1.children) {
- updatedSubCategoryData[subCategory.id] = subCategory.numFound;
- }
- }
+ // for (const subCategory of countLevel1?.children) {
+ // updatedSubCategoryData[subCategory.id] = subCategory?.numFound;
+ // }
+ // }
- setCategoryData(updatedCategoryData);
- setSubCategoryData(updatedSubCategoryData);
- }
- };
+ // setCategoryData(updatedCategoryData);
+ // setSubCategoryData(updatedSubCategoryData);
+ // }
+ // };
- fetchCategoryData();
- }, [categoryManagement.isLoading]);
+ // fetchCategoryData();
+ // }, [categoryManagement.isLoading]);
+
+ const swiperBanner = {
+ modules: [Pagination, ],
+ classNames:'mySwiper',
+ slidesPerView: 3,
+ spaceBetween:10,
+ pagination: {
+ dynamicBullets: true,
+ clickable: true,
+ }
+ };
return (
<div>
{categoryManagement && categoryManagement.data?.map((category) => {
- const countLevel1 = categoryData[category.categoryIdI] || 0;
+ // const countLevel1 = categoryData[category.categoryIdI] || 0;
return (
<Skeleton key={category.id} isLoaded={categoryManagement}>
- <div key={category.id}>
- <div className='bagian-judul flex flex-row justify-start items-center gap-3 mb-4 mt-4'>
- <div className='font-semibold sm:text-h-lg mr-2'>{category.name}</div>
- <Skeleton isLoaded={countLevel1 !=0}>
- <p className={`text-gray_r-10 text-sm`}>{countLevel1} Produk tersedia</p>
- </Skeleton>
- <Link href={createSlug('/shop/category/', category?.name, category?.categoryIdI)} className="!text-red-500 font-semibold">Lihat Semua</Link>
- </div>
- <div className='grid grid-cols-3 gap-2'>
- {category.categories.map((subCategory) => {
- const countLevel2 = subCategoryData[subCategory.idLevel2] || 0;
+ <div key={category.id}>
+ <div className='bagian-judul flex flex-row justify-start items-center gap-3 mb-4 mt-4'>
+ <div className='font-semibold sm:text-h-lg mr-2'>{category.name}</div>
+ {/* <Skeleton isLoaded={countLevel1 != 0}>
+ <p className={`text-gray_r-10 text-sm`}>{countLevel1} Produk tersedia</p>
+ </Skeleton> */}
+ <Link href={createSlug('/shop/category/', category?.name, category?.categoryIdI)} className="!text-red-500 font-semibold">Lihat Semua</Link>
+ </div>
+
+ {/* Swiper for SubCategories */}
+ <Swiper {...swiperBanner}
+ >
+ {category.categories.map((subCategory) => {
+ // const countLevel2 = subCategoryData[subCategory.idLevel2] || 0;
- return (
- <div key={subCategory.id} className='border rounded justify-start items-start'>
- <div className='p-3'>
- <div className='flex flex-row border rounded mb-2 justify-start items-center'>
- <NextImage
- src={subCategory.image ? subCategory.image : "/images/noimage.jpeg"}
- alt={subCategory.name}
- width={90}
- height={30}
- className='object-fit'
- />
- <div className='bagian-judul flex flex-col justify-center items-start gap-2 ml-2'>
- <div className='font-semibold text-lg mr-2'>{subCategory.name}</div>
- <Skeleton isLoaded={countLevel2 != 0}>
- <p className={`text-gray_r-10 text-sm`}>
- {countLevel2} Produk tersedia
- </p>
- </Skeleton>
- <Link href={createSlug('/shop/category/', subCategory?.name, subCategory?.idLevel2)} className="!text-red-500 font-semibold">Lihat Semua</Link>
- </div>
- </div>
- <div className='grid grid-cols-2 gap-2 overflow-y-auto max-h-[240px]'>
- {subCategory.childFrontendIdI.map((childCategory) => (
- <div key={childCategory.id}>
- <Link href={createSlug('/shop/category/', childCategory?.name, childCategory?.idLevel3)} className="flex flex-row gap-2 border rounded group hover:border-red-500">
- <NextImage
- src={childCategory.image ? childCategory.image : "/images/noimage.jpeg"}
- alt={childCategory.name}
- className='p-2 ml-1'
- width={40}
- height={40}
- />
- <div className='bagian-judul flex flex-col justify-center items-center gap-2 break-words line-clamp-2 group-hover:text-red-500'>
- <div className='font-semibold line-clamp-2 group-hover:text-red-500 text-sm mr-2'>{childCategory.name}</div>
+ return (
+ <SwiperSlide key={subCategory.id}>
+ <div className='border rounded justify-start items-start '>
+ <div className='p-3'>
+ <div className='flex flex-row border rounded mb-2 justify-start items-center'>
+ <NextImage
+ src={subCategory.image ? subCategory.image : "/images/noimage.jpeg"}
+ alt={subCategory.name}
+ width={90}
+ height={30}
+ className='object-fit p-4'
+ />
+ <div className='bagian-judul flex flex-col justify-center items-start gap-2 ml-2'>
+ <div className='font-semibold text-lg mr-2'>{subCategory?.name}</div>
+ {/* <Skeleton isLoaded={countLevel2 != 0}>
+ <p className={`text-gray_r-10 text-sm`}>
+ {countLevel2} Produk tersedia
+ </p>
+ </Skeleton> */}
+ <Link href={createSlug('/shop/category/', subCategory?.name, subCategory?.idLevel2)} className="!text-red-500 font-semibold">Lihat Semua</Link>
+ </div>
+ </div>
+ <div className='grid grid-cols-2 gap-2 overflow-y-auto max-h-[240px] min-h-[240px] content-start'>
+ {subCategory.childFrontendIdI.map((childCategory) => (
+ <div key={childCategory.id} className=''>
+ <Link href={createSlug('/shop/category/', childCategory?.name, childCategory?.idLevel3)} className="flex flex-row gap-2 border rounded group hover:border-red-500">
+ <NextImage
+ src={childCategory.image ? childCategory.image : "/images/noimage.jpeg"}
+ alt={childCategory.name}
+ className='p-2 ml-1'
+ width={40}
+ height={40}
+ />
+ <div className='bagian-judul flex flex-col justify-center items-center gap-2 break-words line-clamp-2 group-hover:text-red-500'>
+ <div className='font-semibold line-clamp-2 group-hover:text-red-500 text-sm mr-2'>{childCategory.name}</div>
+ </div>
+ </Link>
</div>
- </Link>
+ ))}
</div>
- ))}
+ </div>
</div>
- </div>
- </div>
- );
- })}
+ </SwiperSlide>
+ );
+ })}
+ </Swiper>
</div>
- </div>
- </Skeleton>
+ </Skeleton>
);
})}
</div>
diff --git a/src/lib/home/components/CategoryDynamicMobile.jsx b/src/lib/home/components/CategoryDynamicMobile.jsx
index c1433a2d..2877a5a7 100644
--- a/src/lib/home/components/CategoryDynamicMobile.jsx
+++ b/src/lib/home/components/CategoryDynamicMobile.jsx
@@ -59,11 +59,10 @@ const CategoryDynamicMobile = () => {
alt={index.name}
width={30}
height={30}
- className='object-'
+ className=''
/>
<div className='bagian-judul flex flex-col justify-center items-start gap-1 ml-2'>
<div className='font-semibold text-[10px] line-clamp-1'>{index.name}</div>
- <p className='text-gray_r-10 text-[10px]'>999 rb+ Produk</p>
</div>
</div>
</div>
@@ -82,6 +81,7 @@ const CategoryDynamicMobile = () => {
alt={x.name}
width={40}
height={40}
+ className='p-2'
/>
<div className='bagian-judul flex flex-col justify-center items-start gap-1 break-words line-clamp-2 group-hover:text-red-500'>
<div className='font-semibold line-clamp-2 group-hover:text-red-500 text-[10px]'>{x.name}</div>