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

