From 865f509a8b45c6db195661f35417623572d33cea Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Sat, 3 Aug 2024 13:33:59 +0700 Subject: update unchek cart --- src-migrate/modules/cart/components/ItemSelect.tsx | 28 ++++++++++++---------- src-migrate/modules/cart/stores/useCartStore.ts | 12 +++++++++- 2 files changed, 26 insertions(+), 14 deletions(-) (limited to 'src-migrate/modules/cart') diff --git a/src-migrate/modules/cart/components/ItemSelect.tsx b/src-migrate/modules/cart/components/ItemSelect.tsx index b904a1de..d4a1b537 100644 --- a/src-migrate/modules/cart/components/ItemSelect.tsx +++ b/src-migrate/modules/cart/components/ItemSelect.tsx @@ -13,23 +13,25 @@ type Props = { const CartItemSelect = ({ item }: Props) => { const auth = getAuth() - const { loadCart } = useCartStore() + const { updateCartItem, cart } = useCartStore() const [isLoad, setIsLoad] = useState(false) const handleChange = async (e: React.ChangeEvent) => { - if (typeof auth !== 'object') return - - setIsLoad(true) - 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) + if (typeof auth !== 'object' || !cart) return + + setIsLoad(true); + const updatedCartItems = cart.products.map(cartItem => + cartItem.id === item.id + ? { ...cartItem, selected: e.target.checked } + : cartItem + ); + + // Update the entire cart + const updatedCart = { ...cart, products: updatedCartItems }; + updateCartItem(updatedCart); + + setIsLoad(false); } return ( diff --git a/src-migrate/modules/cart/stores/useCartStore.ts b/src-migrate/modules/cart/stores/useCartStore.ts index 3d9a0aed..3b50ec32 100644 --- a/src-migrate/modules/cart/stores/useCartStore.ts +++ b/src-migrate/modules/cart/stores/useCartStore.ts @@ -1,5 +1,5 @@ import { create } from 'zustand'; -import { CartProps } from '~/types/cart'; +import { CartItem, CartProps } from '~/types/cart'; import { getUserCart } from '~/services/cart'; type State = { @@ -16,6 +16,7 @@ type State = { type Action = { loadCart: (userId: number) => Promise; + updateCartItem: (updateCart: CartProps) => void; }; export const useCartStore = create((set, get) => ({ @@ -39,6 +40,15 @@ export const useCartStore = create((set, get) => ({ const summary = computeSummary(cart); set({ summary }); }, + updateCartItem: (updatedCart) => { + const cart = get().cart; + if (!cart) return; + + set({ cart: updatedCart }); + const summary = computeSummary(updatedCart); + set({ summary }); + }, + })); const computeSummary = (cart: CartProps) => { -- cgit v1.2.3 From e8745f729cb48a2cab96f8f216617240326f2018 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Tue, 13 Aug 2024 14:39:08 +0700 Subject: add feature pickup service --- src-migrate/modules/cart/components/Item.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src-migrate/modules/cart') diff --git a/src-migrate/modules/cart/components/Item.tsx b/src-migrate/modules/cart/components/Item.tsx index 47893498..44ec4fd5 100644 --- a/src-migrate/modules/cart/components/Item.tsx +++ b/src-migrate/modules/cart/components/Item.tsx @@ -17,11 +17,11 @@ import CartItemSelect from './ItemSelect' type Props = { item: CartItemProps editable?: boolean + selfPicking?: boolean pilihSemuaCart?: boolean } -const CartItem = ({ item, editable = true,}: Props) => { - +const CartItem = ({ item, editable = true, selfPicking}: Props) => { return (
{item.cart_type === 'promotion' && ( @@ -53,6 +53,7 @@ const CartItem = ({ item, editable = true,}: Props) => {
+ {/* disini */}
-- cgit v1.2.3 From a72f9273664715e9708523ca1a6a4554bd22c917 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Tue, 13 Aug 2024 15:37:29 +0700 Subject: update pickup service add field --- src-migrate/modules/cart/components/Item.tsx | 1 + 1 file changed, 1 insertion(+) (limited to 'src-migrate/modules/cart') diff --git a/src-migrate/modules/cart/components/Item.tsx b/src-migrate/modules/cart/components/Item.tsx index 44ec4fd5..25df62fe 100644 --- a/src-migrate/modules/cart/components/Item.tsx +++ b/src-migrate/modules/cart/components/Item.tsx @@ -54,6 +54,7 @@ const CartItem = ({ item, editable = true, selfPicking}: Props) => {
{/* disini */} + {/* {selfPicking && (item.is_in_bu) && (item.on_hand_qty > item.quantity)} */}
-- cgit v1.2.3 From 62704c101d17afb7f71389ef23d6183b2cd16dfa Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Wed, 14 Aug 2024 15:11:33 +0700 Subject: update self picking di product card --- src-migrate/modules/cart/components/Item.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src-migrate/modules/cart') diff --git a/src-migrate/modules/cart/components/Item.tsx b/src-migrate/modules/cart/components/Item.tsx index 25df62fe..ce4c5bff 100644 --- a/src-migrate/modules/cart/components/Item.tsx +++ b/src-migrate/modules/cart/components/Item.tsx @@ -54,7 +54,11 @@ const CartItem = ({ item, editable = true, selfPicking}: Props) => {
{/* disini */} - {/* {selfPicking && (item.is_in_bu) && (item.on_hand_qty > item.quantity)} */} + {selfPicking && (item.is_in_bu) && (item.on_hand_qty > item.quantity) && ( +
+ Barang ini bisa di pickup maksimal pukul 16.00 +
+ )}
-- cgit v1.2.3 From 08e5b76ba58645929ddeda1830f85f3eaf43969e Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Wed, 14 Aug 2024 17:01:44 +0700 Subject: update pickup service logic --- src-migrate/modules/cart/components/Item.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src-migrate/modules/cart') diff --git a/src-migrate/modules/cart/components/Item.tsx b/src-migrate/modules/cart/components/Item.tsx index ce4c5bff..272fa622 100644 --- a/src-migrate/modules/cart/components/Item.tsx +++ b/src-migrate/modules/cart/components/Item.tsx @@ -54,7 +54,7 @@ const CartItem = ({ item, editable = true, selfPicking}: Props) => {
{/* disini */} - {selfPicking && (item.is_in_bu) && (item.on_hand_qty > item.quantity) && ( + {selfPicking && (item.is_in_bu) && (item.on_hand_qty >= item.quantity) && (
Barang ini bisa di pickup maksimal pukul 16.00
-- cgit v1.2.3 From ad82ceb618565eec7b1e955c8ba12243d26253f1 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Thu, 15 Aug 2024 11:27:35 +0700 Subject: update view --- src-migrate/modules/cart/components/Item.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src-migrate/modules/cart') diff --git a/src-migrate/modules/cart/components/Item.tsx b/src-migrate/modules/cart/components/Item.tsx index 272fa622..a9b2d968 100644 --- a/src-migrate/modules/cart/components/Item.tsx +++ b/src-migrate/modules/cart/components/Item.tsx @@ -22,6 +22,8 @@ type Props = { } const CartItem = ({ item, editable = true, selfPicking}: Props) => { + console.log("item",item) + console.log("selfPicking",selfPicking) return (
{item.cart_type === 'promotion' && ( @@ -55,8 +57,8 @@ const CartItem = ({ item, editable = true, selfPicking}: Props) => {
{/* disini */} {selfPicking && (item.is_in_bu) && (item.on_hand_qty >= item.quantity) && ( -
- Barang ini bisa di pickup maksimal pukul 16.00 +
+ *Barang ini bisa di pickup maksimal pukul 16.00
)} -- cgit v1.2.3 From 33363a1a8dc7f4641b7b054dc72339bf53495102 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Thu, 15 Aug 2024 16:55:28 +0700 Subject: update pickup image on product card --- src-migrate/modules/cart/components/Item.tsx | 2 -- 1 file changed, 2 deletions(-) (limited to 'src-migrate/modules/cart') diff --git a/src-migrate/modules/cart/components/Item.tsx b/src-migrate/modules/cart/components/Item.tsx index a9b2d968..a54d4648 100644 --- a/src-migrate/modules/cart/components/Item.tsx +++ b/src-migrate/modules/cart/components/Item.tsx @@ -22,8 +22,6 @@ type Props = { } const CartItem = ({ item, editable = true, selfPicking}: Props) => { - console.log("item",item) - console.log("selfPicking",selfPicking) return (
{item.cart_type === 'promotion' && ( -- cgit v1.2.3 From 92ab4f77d4b31e606838921170a16cbdc0caf4d4 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Thu, 22 Aug 2024 13:34:59 +0700 Subject: update logic self pickup --- src-migrate/modules/cart/components/Item.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src-migrate/modules/cart') diff --git a/src-migrate/modules/cart/components/Item.tsx b/src-migrate/modules/cart/components/Item.tsx index a54d4648..6ffbb524 100644 --- a/src-migrate/modules/cart/components/Item.tsx +++ b/src-migrate/modules/cart/components/Item.tsx @@ -53,8 +53,7 @@ const CartItem = ({ item, editable = true, selfPicking}: Props) => {
- {/* disini */} - {selfPicking && (item.is_in_bu) && (item.on_hand_qty >= item.quantity) && ( + {(item.is_in_bu) && (item.on_hand_qty >= item.quantity) && (
*Barang ini bisa di pickup maksimal pukul 16.00
-- cgit v1.2.3