From f62b2345f463695ef0f8f79830cd76b6e0332821 Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Sat, 13 Jan 2024 10:35:22 +0700
Subject: Refactor src migrate folder

---
 .../product-detail/components/PriceAction.tsx      | 53 ++++++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 src-migrate/modules/product-detail/components/PriceAction.tsx

(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
new file mode 100644
index 00000000..8189e5bd
--- /dev/null
+++ b/src-migrate/modules/product-detail/components/PriceAction.tsx
@@ -0,0 +1,53 @@
+import style from '../styles/price-action.module.css'
+
+import React, { useEffect } from 'react'
+import formatCurrency from '~/libs/formatCurrency'
+import { formatToShortText } from '~/libs/formatNumber'
+import { IProductDetail } from '~/types/product'
+import { useProductDetail } from '../stores/useProductDetail'
+import AddToCart from './AddToCart'
+
+type Props = {
+  product: IProductDetail
+}
+
+const PriceAction = ({ product }: Props) => {
+  const { activePrice, setActive, activeVariantId, quantityInput, setQuantityInput } = useProductDetail()
+
+  useEffect(() => {
+    setActive(product.variants[0])
+  }, [product, setActive]);
+
+  return (
+    <div className='block md:sticky top-[150px] bg-white py-0 md:py-6 z-10'>
+      {product.qty_sold > 0 && (
+        <div className={style['secondary-text']}>
+          {formatToShortText(product.qty_sold)} Terjual
+        </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 && (
+          <>
+            Termasuk PPN: {' '}
+            Rp {formatCurrency(Math.round(activePrice?.price * 1.11))}
+          </>
+        )}
+      </div>
+
+      <div className='h-4' />
+
+      <div className={style['action-wrapper']}>
+        <input type='number' value={quantityInput} onChange={(e) => setQuantityInput(e.target.value)} className={style['quantity-input']} />
+        <AddToCart variantId={activeVariantId} quantity={Number(quantityInput)} />
+        <AddToCart source='buy' variantId={activeVariantId} quantity={Number(quantityInput)} />
+      </div>
+    </div>
+  )
+}
+
+export default PriceAction
\ No newline at end of file
-- 
cgit v1.2.3


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


From a70fd5b6d9c7a769ac1aaa22a7d037ba3be27a05 Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Tue, 16 Jan 2024 16:08:43 +0700
Subject: Update improve product detail performance

---
 src-migrate/modules/product-detail/components/PriceAction.tsx | 10 ++--------
 1 file changed, 2 insertions(+), 8 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 cfb596fa..dd211f6f 100644
--- a/src-migrate/modules/product-detail/components/PriceAction.tsx
+++ b/src-migrate/modules/product-detail/components/PriceAction.tsx
@@ -28,13 +28,6 @@ const PriceAction = ({ product }: Props) => {
 
   return (
     <div className='block md:sticky top-[150px] bg-white py-0 md:py-6 z-10'>
-      {product.qty_sold > 0 && (
-        <div className={style['secondary-text']}>
-          {formatToShortText(product.qty_sold)} Terjual
-        </div>
-      )}
-      <div className='h-2' />
-
       {!!activePrice && activePrice.price > 0 && (
         <>
           <div className={style['main-price']}>
@@ -60,7 +53,8 @@ const PriceAction = ({ product }: Props) => {
       <div className='h-4' />
 
       <div className={style['action-wrapper']}>
-        <input type='number' value={quantityInput} onChange={(e) => setQuantityInput(e.target.value)} className={style['quantity-input']} />
+        <label htmlFor="quantity" className='hidden'>Quantity</label>
+        <input type='number' id='quantity' value={quantityInput} onChange={(e) => setQuantityInput(e.target.value)} className={style['quantity-input']} />
         <AddToCart variantId={activeVariantId} quantity={Number(quantityInput)} />
         <AddToCart source='buy' variantId={activeVariantId} quantity={Number(quantityInput)} />
       </div>
-- 
cgit v1.2.3


From f7a0be1407da7edab60f6cb2ca3f1ef97acf811a Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Wed, 17 Jan 2024 16:03:48 +0700
Subject: Update product detail page ui

---
 src-migrate/modules/product-detail/components/PriceAction.tsx | 3 +--
 1 file changed, 1 insertion(+), 2 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 dd211f6f..cade21b8 100644
--- a/src-migrate/modules/product-detail/components/PriceAction.tsx
+++ b/src-migrate/modules/product-detail/components/PriceAction.tsx
@@ -2,7 +2,6 @@ import style from '../styles/price-action.module.css'
 
 import React, { useEffect } from 'react'
 import formatCurrency from '~/libs/formatCurrency'
-import { formatToShortText } from '~/libs/formatNumber'
 import { IProductDetail } from '~/types/product'
 import { useProductDetail } from '../stores/useProductDetail'
 import AddToCart from './AddToCart'
@@ -27,7 +26,7 @@ const PriceAction = ({ product }: Props) => {
   }, [product, setActive]);
 
   return (
-    <div className='block md:sticky top-[150px] bg-white py-0 md:py-6 z-10'>
+    <div className='block md:sticky top-[150px] bg-white py-0 md:py-6 z-10' id='price-section'>
       {!!activePrice && activePrice.price > 0 && (
         <>
           <div className={style['main-price']}>
-- 
cgit v1.2.3


From 5ac82c38ed3ec4db1fe4ae96e7493a55154716ef Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Thu, 18 Jan 2024 16:24:54 +0700
Subject: Update product detail page

---
 .../modules/product-detail/components/PriceAction.tsx  | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 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 cade21b8..f25847a5 100644
--- a/src-migrate/modules/product-detail/components/PriceAction.tsx
+++ b/src-migrate/modules/product-detail/components/PriceAction.tsx
@@ -29,13 +29,25 @@ const PriceAction = ({ product }: Props) => {
     <div className='block md:sticky top-[150px] bg-white py-0 md:py-6 z-10' id='price-section'>
       {!!activePrice && activePrice.price > 0 && (
         <>
-          <div className={style['main-price']}>
-            Rp {formatCurrency(activePrice.price || 0)}
+          <div className='flex items-end gap-x-2'>
+            {activePrice.discount_percentage > 0 && (
+              <>
+                <div className={style['disc-badge']}>
+                  {Math.floor(activePrice.discount_percentage)}%
+                </div>
+                <div className={style['disc-price']}>
+                  Rp {formatCurrency(activePrice.price || 0)}
+                </div>
+              </>
+            )}
+            <div className={style['main-price']}>
+              Rp {formatCurrency(activePrice.price_discount || 0)}
+            </div>
           </div>
           <div className='h-1' />
           <div className={style['secondary-text']}>
             Termasuk PPN: {' '}
-            Rp {formatCurrency(Math.round(activePrice.price * 1.11))}
+            Rp {formatCurrency(Math.round(activePrice.price_discount * 1.11))}
           </div>
         </>
       )}
-- 
cgit v1.2.3


From 1850e105ce6578465a015e395fa4c38544afdafe Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Mon, 29 Apr 2024 10:17:54 +0700
Subject: CR - Price Product detail = variant yg ada harganya

---
 src-migrate/modules/product-detail/components/PriceAction.tsx | 10 ++++++++++
 1 file changed, 10 insertions(+)

(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 f25847a5..ad04de43 100644
--- a/src-migrate/modules/product-detail/components/PriceAction.tsx
+++ b/src-migrate/modules/product-detail/components/PriceAction.tsx
@@ -23,6 +23,16 @@ const PriceAction = ({ product }: Props) => {
 
   useEffect(() => {
     setActive(product.variants[0])
+    if(product.variants.length > 2 && product.variants[0].price.price === 0){
+      const variants = product.variants
+      for (let i = 0; i < variants.length; i++) {
+        if(variants[i].price.price > 0){
+          setActive(variants[i])
+          break;
+        }
+      }
+    }
+   
   }, [product, setActive]);
 
   return (
-- 
cgit v1.2.3


From 556cbc1e5ea1c1ef0170c9a1b8f470a3d92d888e Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Tue, 2 Jul 2024 10:40:06 +0700
Subject: IS SO APPROVAL

---
 .../product-detail/components/PriceAction.tsx      | 75 +++++++++++++++-------
 1 file changed, 52 insertions(+), 23 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 f25847a5..d91ea49c 100644
--- a/src-migrate/modules/product-detail/components/PriceAction.tsx
+++ b/src-migrate/modules/product-detail/components/PriceAction.tsx
@@ -1,15 +1,16 @@
-import style from '../styles/price-action.module.css'
+import style from '../styles/price-action.module.css';
 
-import React, { useEffect } from 'react'
-import formatCurrency from '~/libs/formatCurrency'
-import { IProductDetail } from '~/types/product'
-import { useProductDetail } from '../stores/useProductDetail'
-import AddToCart from './AddToCart'
-import Link from 'next/link'
+import React, { useEffect } from 'react';
+import formatCurrency from '~/libs/formatCurrency';
+import { IProductDetail } from '~/types/product';
+import { useProductDetail } from '../stores/useProductDetail';
+import AddToCart from './AddToCart';
+import Link from 'next/link';
+import { getAuth } from '~/libs/auth';
 
 type Props = {
-  product: IProductDetail
-}
+  product: IProductDetail;
+};
 
 const PriceAction = ({ product }: Props) => {
   const {
@@ -18,15 +19,22 @@ const PriceAction = ({ product }: Props) => {
     activeVariantId,
     quantityInput,
     setQuantityInput,
-    askAdminUrl
-  } = useProductDetail()
+    askAdminUrl,
+    isApproval,
+    setIsApproval,
+  } = useProductDetail();
 
   useEffect(() => {
-    setActive(product.variants[0])
+    setActive(product.variants[0]);
   }, [product, setActive]);
 
+
+
   return (
-    <div className='block md:sticky top-[150px] bg-white py-0 md:py-6 z-10' id='price-section'>
+    <div
+      className='block md:sticky top-[150px] bg-white py-0 md:py-6 z-10'
+      id='price-section'
+    >
       {!!activePrice && activePrice.price > 0 && (
         <>
           <div className='flex items-end gap-x-2'>
@@ -46,8 +54,8 @@ const PriceAction = ({ product }: Props) => {
           </div>
           <div className='h-1' />
           <div className={style['secondary-text']}>
-            Termasuk PPN: {' '}
-            Rp {formatCurrency(Math.round(activePrice.price_discount * 1.11))}
+            Termasuk PPN: Rp{' '}
+            {formatCurrency(Math.round(activePrice.price_discount * 1.11))}
           </div>
         </>
       )}
@@ -55,7 +63,11 @@ const PriceAction = ({ product }: Props) => {
       {!!activePrice && activePrice.price === 0 && (
         <span>
           Hubungi kami untuk dapatkan harga terbaik,{' '}
-          <Link href={askAdminUrl} target='_blank' className={style['contact-us']}>
+          <Link
+            href={askAdminUrl}
+            target='_blank'
+            className={style['contact-us']}
+          >
             klik disini
           </Link>
         </span>
@@ -64,13 +76,30 @@ const PriceAction = ({ product }: Props) => {
       <div className='h-4' />
 
       <div className={style['action-wrapper']}>
-        <label htmlFor="quantity" className='hidden'>Quantity</label>
-        <input type='number' id='quantity' value={quantityInput} onChange={(e) => setQuantityInput(e.target.value)} className={style['quantity-input']} />
-        <AddToCart variantId={activeVariantId} quantity={Number(quantityInput)} />
-        <AddToCart source='buy' variantId={activeVariantId} quantity={Number(quantityInput)} />
+        <label htmlFor='quantity' className='hidden'>
+          Quantity
+        </label>
+        <input
+          type='number'
+          id='quantity'
+          value={quantityInput}
+          onChange={(e) => setQuantityInput(e.target.value)}
+          className={style['quantity-input']}
+        />
+        <AddToCart
+          variantId={activeVariantId}
+          quantity={Number(quantityInput)}
+        />
+        {!isApproval && (
+          <AddToCart
+            source='buy'
+            variantId={activeVariantId}
+            quantity={Number(quantityInput)}
+          />
+        )}
       </div>
     </div>
-  )
-}
+  );
+};
 
-export default PriceAction
\ No newline at end of file
+export default PriceAction;
-- 
cgit v1.2.3

