From f15a7f8a4387d215abd1051ee520adca8944fa05 Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Tue, 28 Mar 2023 16:32:45 +0700
Subject: checkout, quotation

---
 src/lib/product/components/Product/ProductDesktop.jsx | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

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

diff --git a/src/lib/product/components/Product/ProductDesktop.jsx b/src/lib/product/components/Product/ProductDesktop.jsx
index 2f73d124..79e7bb45 100644
--- a/src/lib/product/components/Product/ProductDesktop.jsx
+++ b/src/lib/product/components/Product/ProductDesktop.jsx
@@ -11,8 +11,10 @@ import { updateItemCart } from '@/core/utils/cart'
 import useVariantPrice from '@/lib/variant/hooks/useVariantPrice'
 import useProductPrice from '../../hooks/useProductPrice'
 import PriceSkeleton from '@/core/components/elements/Skeleton/PriceSkeleton'
+import { useRouter } from 'next/router'
 
 const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
+  const router = useRouter()
   const { productPrice } = useProductPrice({ id: product.id })
   const [informationTab, setInformationTab] = useState(informationTabOptions[0].value)
 
@@ -41,6 +43,12 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
     toast.success('Berhasil menambahkan ke keranjang')
   }
 
+  const handleBuy = (variantId) => {
+    const quantity = variantQuantityRefs.current[variantId].value
+    if (!validQuantity(quantity)) return
+    router.push(`/shop/checkout?productId=${variantId}&quantity=${quantity}`)
+  }
+
   const variantSectionRef = useRef(null)
   const goToVariantSection = () => {
     if (variantSectionRef.current) {
@@ -193,7 +201,11 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
                       >
                         Keranjang
                       </button>
-                      <button type='button' className='flex-1 py-2 btn-solid-red'>
+                      <button
+                        type='button'
+                        onClick={() => handleBuy(variant.id)}
+                        className='flex-1 py-2 btn-solid-red'
+                      >
                         Beli
                       </button>
                     </td>
@@ -264,7 +276,9 @@ const VariantPrice = ({ id }) => {
       {variantPrice?.data?.priceExcludeAfterDiscount > 0 ? (
         currencyFormat(variantPrice?.data?.priceExcludeAfterDiscount)
       ) : (
-        <a href='https://wa.me/' className='text-red_r-11'>Call for price</a>
+        <a href='https://wa.me/' className='text-red_r-11'>
+          Call for price
+        </a>
       )}
     </>
   )
-- 
cgit v1.2.3

