From c42f03768e4c009a247d5cacbecaf4ac952752c9 Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Mon, 15 Jan 2024 13:54:30 +0700
Subject: Improve product detail performance

---
 .../product-detail/components/PriceAction.tsx      | 42 +++++++++++++++-------
 1 file changed, 30 insertions(+), 12 deletions(-)

(limited to 'src-migrate/modules/product-detail/components/PriceAction.tsx')

diff --git a/src-migrate/modules/product-detail/components/PriceAction.tsx b/src-migrate/modules/product-detail/components/PriceAction.tsx
index 8189e5bd..cfb596fa 100644
--- a/src-migrate/modules/product-detail/components/PriceAction.tsx
+++ b/src-migrate/modules/product-detail/components/PriceAction.tsx
@@ -6,13 +6,21 @@ import { formatToShortText } from '~/libs/formatNumber'
 import { IProductDetail } from '~/types/product'
 import { useProductDetail } from '../stores/useProductDetail'
 import AddToCart from './AddToCart'
+import Link from 'next/link'
 
 type Props = {
   product: IProductDetail
 }
 
 const PriceAction = ({ product }: Props) => {
-  const { activePrice, setActive, activeVariantId, quantityInput, setQuantityInput } = useProductDetail()
+  const {
+    activePrice,
+    setActive,
+    activeVariantId,
+    quantityInput,
+    setQuantityInput,
+    askAdminUrl
+  } = useProductDetail()
 
   useEffect(() => {
     setActive(product.variants[0])
@@ -26,18 +34,28 @@ const PriceAction = ({ product }: Props) => {
         </div>
       )}
       <div className='h-2' />
-      <div className={style['main-price']}>
-        Rp {formatCurrency(activePrice?.price || 0)}
-      </div>
-      <div className='h-1' />
-      <div className={style['secondary-text']}>
-        {!!activePrice && (
-          <>
+
+      {!!activePrice && activePrice.price > 0 && (
+        <>
+          <div className={style['main-price']}>
+            Rp {formatCurrency(activePrice.price || 0)}
+          </div>
+          <div className='h-1' />
+          <div className={style['secondary-text']}>
             Termasuk PPN: {' '}
-            Rp {formatCurrency(Math.round(activePrice?.price * 1.11))}
-          </>
-        )}
-      </div>
+            Rp {formatCurrency(Math.round(activePrice.price * 1.11))}
+          </div>
+        </>
+      )}
+
+      {!!activePrice && activePrice.price === 0 && (
+        <span>
+          Hubungi kami untuk dapatkan harga terbaik,{' '}
+          <Link href={askAdminUrl} target='_blank' className={style['contact-us']}>
+            klik disini
+          </Link>
+        </span>
+      )}
 
       <div className='h-4' />
 
-- 
cgit v1.2.3

