From 22a13e2a115dc76fda0f72efbec57f39055af2a3 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Mon, 18 Nov 2024 08:27:26 +0700
Subject: <iman> fix code no data search

---
 src/lib/flashSale/components/FlashSale.jsx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'src/lib/flashSale/components/FlashSale.jsx')

diff --git a/src/lib/flashSale/components/FlashSale.jsx b/src/lib/flashSale/components/FlashSale.jsx
index 89c46de4..8be1d7a6 100644
--- a/src/lib/flashSale/components/FlashSale.jsx
+++ b/src/lib/flashSale/components/FlashSale.jsx
@@ -69,7 +69,7 @@ const FlashSaleProduct = ({ flashSaleId }) => {
   useEffect(() => {
     const loadProducts = async () => {
       const dataProducts = await productSearchApi({
-        query: `fq=flashsale_id_i:${flashSaleId}&fq=flashsale_price_f:[1 TO *]&limit=500&orderBy=flashsale-price-asc`,
+        query: `fq=flashsale_id_i:${flashSaleId}&fq=flashsale_price_f:[1 TO *]&limit=500&orderBy=flashsale-price-asc&source=similar`,
         operation: 'AND',
       });
       setProducts(dataProducts.response);
-- 
cgit v1.2.3


From 4d1dd6ad5b22ffb02e4347cf3159f10988fd7c03 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Tue, 19 Nov 2024 10:49:07 +0700
Subject: <iman> redis v2

---
 src/lib/flashSale/components/FlashSale.jsx | 36 +++++++++++++++++++-----------
 1 file changed, 23 insertions(+), 13 deletions(-)

(limited to 'src/lib/flashSale/components/FlashSale.jsx')

diff --git a/src/lib/flashSale/components/FlashSale.jsx b/src/lib/flashSale/components/FlashSale.jsx
index 8be1d7a6..6d90cad7 100644
--- a/src/lib/flashSale/components/FlashSale.jsx
+++ b/src/lib/flashSale/components/FlashSale.jsx
@@ -2,10 +2,8 @@ import Image from 'next/image';
 import { useEffect, useState } from 'react';
 
 import CountDown from '@/core/components/elements/CountDown/CountDown';
-import productSearchApi from '@/lib/product/api/productSearchApi';
 import ProductSlider from '@/lib/product/components/ProductSlider';
 
-import flashSaleApi from '../api/flashSaleApi';
 import { FlashSaleSkeleton } from '../skeleton/FlashSaleSkeleton';
 
 const FlashSale = () => {
@@ -14,10 +12,14 @@ const FlashSale = () => {
 
   useEffect(() => {
     const loadFlashSales = async () => {
-      const dataFlashSales = await flashSaleApi();
-      setFlashSales(dataFlashSales);
+      const res = await fetch('/api/flashsale-header');
+      const { data } = await res.json();
+      if (data) {
+        setFlashSales(data);
+      }
       setIsLoading(false);
     };
+
     loadFlashSales();
   }, []);
 
@@ -53,7 +55,10 @@ const FlashSale = () => {
                   height={48}
                   className='w-full rounded mb-4 block sm:hidden'
                 />
-                <FlashSaleProduct flashSaleId={flashSale.pricelistId} />
+                <FlashSaleProduct
+                  flashSaleId={flashSale.pricelistId}
+                  duration={flashSale.duration}
+                />
               </div>
             </div>
           ))}
@@ -63,19 +68,24 @@ const FlashSale = () => {
   );
 };
 
-const FlashSaleProduct = ({ flashSaleId }) => {
+const FlashSaleProduct = ({ flashSaleId, duration }) => {
   const [products, setProducts] = useState(null);
-
   useEffect(() => {
+    const data_search = new URLSearchParams({
+      query: `fq=flashsale_id_i:${flashSaleId}&fq=flashsale_price_f:[1 TO *]&limit=500&orderBy=flashsale-price-asc&source=similar`,
+      operation: 'AND',
+      duration: `${duration}`,
+    });
     const loadProducts = async () => {
-      const dataProducts = await productSearchApi({
-        query: `fq=flashsale_id_i:${flashSaleId}&fq=flashsale_price_f:[1 TO *]&limit=500&orderBy=flashsale-price-asc&source=similar`,
-        operation: 'AND',
-      });
-      setProducts(dataProducts.response);
+      const res = await fetch(
+        `/api/search-flashsale?${data_search.toString()}`
+      );
+      const { data } = await res.json();
+      setProducts(data.response);
     };
+
     loadProducts();
-  }, [flashSaleId]);
+  }, []);
 
   return <ProductSlider products={products} />;
 };
-- 
cgit v1.2.3

