From 755b61a8a7a082cc13f7ecb4a79807f90e60b3d6 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Wed, 5 Jun 2024 16:50:38 +0700
Subject: <iman> add feature SNI-TKDN

---
 src/lib/product/components/ProductCard.jsx | 103 +++++++++--------------------
 1 file changed, 32 insertions(+), 71 deletions(-)

(limited to 'src/lib/product/components/ProductCard.jsx')

diff --git a/src/lib/product/components/ProductCard.jsx b/src/lib/product/components/ProductCard.jsx
index 8dde4dbe..48a30b51 100644
--- a/src/lib/product/components/ProductCard.jsx
+++ b/src/lib/product/components/ProductCard.jsx
@@ -1,7 +1,7 @@
 import clsx from 'clsx';
 import ImageNext from 'next/image';
 import { useRouter } from 'next/router';
-import { useMemo, useEffect, useState } from 'react';
+import { useMemo} from 'react';
 
 import Image from '@/core/components/elements/Image/Image';
 import Link from '@/core/components/elements/Link/Link';
@@ -15,46 +15,7 @@ const ProductCard = ({ product, simpleTitle, variant = 'vertical' }) => {
   const router = useRouter();
   const utmSource = useUtmSource();
 
-  const [isSni, setIsSni] = useState(false);
-  const [isTkdn, setTkdn] = useState(false);
-
-  useEffect(() => {
-    // Lakukan pemanggilan API untuk memeriksa isSni
-    const fetchSniData = async () => {
-      try {
-        const response = await fetch('URL_API_SNI');
-        const data = await response.json();
-        if (data && data.sni) {
-          setIsSni(true);
-        } else {
-          setIsSni(false);
-        }
-      } catch (error) {
-        console.error('Error fetching SNI data:', error);
-        setIsSni(false);
-      }
-    };
-
-    // Lakukan pemanggilan API untuk memeriksa isTkdn
-    const fetchTkdnData = async () => {
-      try {
-        const response = await fetch('URL_API_TKDN');
-        const data = await response.json();
-        if (data && data.tkdn) {
-          setTkdn(true);
-        } else {
-          setTkdn(false);
-        }
-      } catch (error) {
-        console.error('Error fetching TKDN data:', error);
-        setTkdn(false);
-      }
-    };
-    fetchSniData();
-    fetchTkdnData();
-    return () => {
-    };
-  }, []);
+  
 
   const callForPriceWhatsapp = whatsappUrl('product', {
     name: product.name,
@@ -90,7 +51,7 @@ const ProductCard = ({ product, simpleTitle, variant = 'vertical' }) => {
           />
           <div className="absolute top-0 right-0 flex  mt-3">
             <div className="gambarB ">
-              {!isSni && (
+              {product.isSni && (
                 <ImageNext
                   src="/images/sni-logo.png"
                   alt="SNI Logo"
@@ -101,7 +62,7 @@ const ProductCard = ({ product, simpleTitle, variant = 'vertical' }) => {
               )}
             </div>
             <div className="gambarC  ">
-              {!isTkdn && (
+              {product.isTkdn && (
                 <ImageNext
                   src="/images/TKDN.png"
                   alt="TKDN"
@@ -241,35 +202,35 @@ const ProductCard = ({ product, simpleTitle, variant = 'vertical' }) => {
         <div className='w-4/12'>
           <Link href={URL.product} className='relative'>
           <div className="relative">
-          <Image
-            src={image}
-            alt={product?.name}
-            className="gambarA w-full object-contain object-center h-36 sm:h-48"
-          />
-          <div className="absolute top-0 right-0 flex  mt-3">
-            <div className="gambarB ">
-              {!isSni && (
-                <ImageNext
-                  src="/images/sni-logo.png"
-                  alt="SNI Logo"
-                  className="w-4 h-5 object-contain object-top   sm:h-6"
-                  width={50}
-                  height={50}
-                />
-              )}
-            </div>
-            <div className="gambarC  ">
-              {!isTkdn && (
-                <ImageNext
-                  src="/images/TKDN.png"
-                  alt="TKDN"
-                  className="w-11 h-6 object-contain object-top  ml-1 sm:h-6"
-                  width={50}
-                  height={50}
-                />
-              )}
+            <Image
+              src={image}
+              alt={product?.name}
+              className="gambarA w-full object-contain object-center h-36 sm:h-48"
+            />
+            <div className="absolute top-0 right-0 flex  mt-3">
+              <div className="gambarB ">
+                {product.isSni && (
+                  <ImageNext
+                    src="/images/sni-logo.png"
+                    alt="SNI Logo"
+                    className="w-4 h-5 object-contain object-top   sm:h-6"
+                    width={50}
+                    height={50}
+                  />
+                )}
+              </div>
+              <div className="gambarC  ">
+                {product.isTkdn && (
+                  <ImageNext
+                    src="/images/TKDN.png"
+                    alt="TKDN"
+                    className="w-11 h-6 object-contain object-top  ml-1 sm:h-6"
+                    width={50}
+                    height={50}
+                  />
+                )}
+              </div>
             </div>
-          </div>
         </div>
             {product.variantTotal > 1 && (
               <div className='absolute badge-gray bottom-1.5 left-1.5'>
-- 
cgit v1.2.3

