From 89f32128f37d99b490de7590e2116a9cfd853f89 Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Fri, 22 Dec 2023 17:33:46 +0700
Subject: Update promotion program feature

---
 src-migrate/modules/cart/components/ItemSelect.tsx | 47 ++++++++++++++++++++++
 1 file changed, 47 insertions(+)
 create mode 100644 src-migrate/modules/cart/components/ItemSelect.tsx

(limited to 'src-migrate/modules/cart/components/ItemSelect.tsx')

diff --git a/src-migrate/modules/cart/components/ItemSelect.tsx b/src-migrate/modules/cart/components/ItemSelect.tsx
new file mode 100644
index 00000000..96e7c713
--- /dev/null
+++ b/src-migrate/modules/cart/components/ItemSelect.tsx
@@ -0,0 +1,47 @@
+import { Checkbox, Spinner } from '@chakra-ui/react'
+import React, { useState } from 'react'
+
+import { getAuth } from '~/common/libs/auth'
+import { CartItem } from '~/common/types/cart'
+import { upsertUserCart } from '~/services/cart'
+
+import { useCartStore } from '../stores/useCartStore'
+
+type Props = {
+  item: CartItem
+}
+
+const CartItemSelect = ({ item }: Props) => {
+  const auth = getAuth()
+  const { loadCart } = useCartStore()
+
+  const [isLoad, setIsLoad] = useState<boolean>(false)
+
+  const handleChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
+    if (typeof auth !== 'object') return
+
+    setIsLoad(true)
+    await upsertUserCart(auth.id, item.cart_type, item.id, item.quantity, e.target.checked)
+    await loadCart(auth.id)
+    setIsLoad(false)
+  }
+
+  return (
+    <div className='w-5 my-auto'>
+      {isLoad && (
+        <Spinner className='my-auto' size='sm' />
+      )}
+      {!isLoad && (
+        <Checkbox
+          borderColor='gray.600'
+          colorScheme='red'
+          size='lg'
+          isChecked={item.selected}
+          onChange={handleChange}
+        />
+      )}
+    </div>
+  )
+}
+
+export default CartItemSelect
\ No newline at end of file
-- 
cgit v1.2.3


From ee0b5893ac039ab05fe8247647364a923d707da3 Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Fri, 5 Jan 2024 09:30:08 +0700
Subject: Fixing UI cart page

---
 src-migrate/modules/cart/components/ItemSelect.tsx | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

(limited to 'src-migrate/modules/cart/components/ItemSelect.tsx')

diff --git a/src-migrate/modules/cart/components/ItemSelect.tsx b/src-migrate/modules/cart/components/ItemSelect.tsx
index 96e7c713..10d7493a 100644
--- a/src-migrate/modules/cart/components/ItemSelect.tsx
+++ b/src-migrate/modules/cart/components/ItemSelect.tsx
@@ -27,10 +27,11 @@ const CartItemSelect = ({ item }: Props) => {
   }
 
   return (
-    <div className='w-5 my-auto'>
+    <div className='w-6 my-auto'>
       {isLoad && (
         <Spinner className='my-auto' size='sm' />
       )}
+
       {!isLoad && (
         <Checkbox
           borderColor='gray.600'
-- 
cgit v1.2.3


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

---
 src-migrate/modules/cart/components/ItemSelect.tsx | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

(limited to 'src-migrate/modules/cart/components/ItemSelect.tsx')

diff --git a/src-migrate/modules/cart/components/ItemSelect.tsx b/src-migrate/modules/cart/components/ItemSelect.tsx
index 10d7493a..1d8886a2 100644
--- a/src-migrate/modules/cart/components/ItemSelect.tsx
+++ b/src-migrate/modules/cart/components/ItemSelect.tsx
@@ -1,8 +1,8 @@
 import { Checkbox, Spinner } from '@chakra-ui/react'
 import React, { useState } from 'react'
 
-import { getAuth } from '~/common/libs/auth'
-import { CartItem } from '~/common/types/cart'
+import { getAuth } from '~/libs/auth'
+import { CartItem } from '~/types/cart'
 import { upsertUserCart } from '~/services/cart'
 
 import { useCartStore } from '../stores/useCartStore'
-- 
cgit v1.2.3


From a698514b32353d8f6386ce8ba8c20941ab65f569 Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Mon, 26 Feb 2024 15:12:12 +0700
Subject: Add qty append on upsert cart api

---
 src-migrate/modules/cart/components/ItemSelect.tsx | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

(limited to 'src-migrate/modules/cart/components/ItemSelect.tsx')

diff --git a/src-migrate/modules/cart/components/ItemSelect.tsx b/src-migrate/modules/cart/components/ItemSelect.tsx
index 1d8886a2..b904a1de 100644
--- a/src-migrate/modules/cart/components/ItemSelect.tsx
+++ b/src-migrate/modules/cart/components/ItemSelect.tsx
@@ -21,7 +21,13 @@ const CartItemSelect = ({ item }: Props) => {
     if (typeof auth !== 'object') return
 
     setIsLoad(true)
-    await upsertUserCart(auth.id, item.cart_type, item.id, item.quantity, e.target.checked)
+    await upsertUserCart({
+      userId: auth.id,
+      type: item.cart_type,
+      id: item.id,
+      qty: item.quantity,
+      selected: e.target.checked
+    })
     await loadCart(auth.id)
     setIsLoad(false)
   }
-- 
cgit v1.2.3

