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

---
 .../product-detail/components/VariantList.tsx      | 31 +++++++++++++++++-----
 1 file changed, 25 insertions(+), 6 deletions(-)

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

diff --git a/src-migrate/modules/product-detail/components/VariantList.tsx b/src-migrate/modules/product-detail/components/VariantList.tsx
index e8c18921..931563e0 100644
--- a/src-migrate/modules/product-detail/components/VariantList.tsx
+++ b/src-migrate/modules/product-detail/components/VariantList.tsx
@@ -10,6 +10,7 @@ import { useProductDetail } from '../stores/useProductDetail'
 import { LazyLoadComponent } from 'react-lazy-load-image-component';
 import { getVariantSLA } from '~/services/productVariant'
 import { useQuery } from 'react-query'
+import useDevice from '@/core/hooks/useDevice'
 
 type Props = {
   variants: IProductVariantDetail[]
@@ -20,12 +21,13 @@ const VariantList = ({ variants }: Props) => {
     <div className='overflow-auto'>
       <div className={style['wrapper']}>
         <div className={style['header']}>
-          <div className="w-2/12 sticky left-0 bg-gray-200">Part Number</div>
+          <div className="w-2/12">Part Number</div>
           <div className="w-2/12">Variant</div>
           <div className="w-1/12">Stock</div>
           <div className="w-2/12">Masa Persiapan</div>
           <div className="w-1/12">Berat</div>
           <div className="w-3/12">Harga</div>
+          <div className='w-1/12 sticky right-0 bg-gray-200'></div>
         </div>
         {variants.map((variant) => (
           <LazyLoadComponent key={variant.id}>
@@ -38,6 +40,8 @@ const VariantList = ({ variants }: Props) => {
 }
 
 const Row = ({ variant }: { variant: IProductVariantDetail }) => {
+  const { isMobile } = useDevice()
+
   const { activeVariantId, setActive } = useProductDetail()
   const querySLA = useQuery<IProductVariantSLA>({
     queryKey: ['variant-sla', variant.id],
@@ -46,17 +50,32 @@ const Row = ({ variant }: { variant: IProductVariantDetail }) => {
 
   const sla = querySLA?.data
 
+  const handleSelect = (variant: IProductVariantDetail) => {
+    const priceSectionEl = document.getElementById('price-section')
+    if (isMobile && priceSectionEl) {
+      window.scrollTo({
+        top: priceSectionEl.offsetTop - 120,
+        behavior: 'smooth'
+      })
+    }
+    setActive(variant)
+  }
+
   return (
     <div className={style['row']}>
-      <div className='w-2/12 sticky left-0 bg-white md:bg-transparent'>{variant.code}</div>
+      <div className='w-2/12'>{variant.code}</div>
       <div className='w-2/12'>{variant.attributes.join(', ') || '-'}</div>
       <div className='w-1/12'>
         <Skeleton isLoaded={querySLA.isSuccess} h='21px' w={16}>
           {sla?.qty !== undefined && (
-            <>
+            <div className={clsxm('text-center rounded-md', {
+              [style['stock-empty']]: sla.qty == 0,
+              [style['stock-ready']]: sla.qty > 0,
+            })}
+            >
               {sla.qty > 0 && sla.qty}
               {sla.qty == 0 && '-'}
-            </>
+            </div>
           )}
         </Skeleton>
       </div>
@@ -72,9 +91,9 @@ const Row = ({ variant }: { variant: IProductVariantDetail }) => {
         {variant.price.price > 0 && `Rp ${formatCurrency(variant.price.price)}`}
         {variant.price.price === 0 && '-'}
       </div>
-      <div className='w-1/12'>
+      <div className='w-1/12 sticky right-0 bg-white md:bg-transparent'>
         <Button
-          onClick={() => setActive(variant)}
+          onClick={() => handleSelect(variant)}
           size='sm'
           w='100%'
           className={clsxm(style['select-btn'], {
-- 
cgit v1.2.3

