From 3f849355048e5c280a35a5747577e5296b90e9fd Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Thu, 25 Jan 2024 15:27:27 +0700 Subject: Add all promo page --- src-migrate/pages/shop/promo/index.tsx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src-migrate/pages/shop/promo/index.tsx (limited to 'src-migrate/pages') diff --git a/src-migrate/pages/shop/promo/index.tsx b/src-migrate/pages/shop/promo/index.tsx new file mode 100644 index 00000000..df2e9dcb --- /dev/null +++ b/src-migrate/pages/shop/promo/index.tsx @@ -0,0 +1,17 @@ +import React from 'react' +import Hero from '~/modules/promo/components/Hero' +import Voucher from '~/modules/promo/components/Voucher' + +const PromoPage = () => { + return ( + <> + + +
+ + + + ) +} + +export default PromoPage \ No newline at end of file -- cgit v1.2.3 From 8d8c43d90373aab6238773e291a48d65d55c52a2 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Sat, 17 Feb 2024 10:23:23 +0700 Subject: Add voucher section --- src-migrate/pages/shop/promo/index.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src-migrate/pages') diff --git a/src-migrate/pages/shop/promo/index.tsx b/src-migrate/pages/shop/promo/index.tsx index df2e9dcb..f293bbe3 100644 --- a/src-migrate/pages/shop/promo/index.tsx +++ b/src-migrate/pages/shop/promo/index.tsx @@ -1,15 +1,20 @@ import React from 'react' +import { LazyLoadComponent } from 'react-lazy-load-image-component' import Hero from '~/modules/promo/components/Hero' import Voucher from '~/modules/promo/components/Voucher' const PromoPage = () => { return ( <> - + + +
- + + + ) } -- cgit v1.2.3 From ed0d0293f88adf3c5312cb556bc464e330b3672a Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Fri, 26 Apr 2024 09:44:31 +0700 Subject: hide button checkout if is step approval is true --- src-migrate/pages/shop/cart/index.tsx | 39 ++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 17 deletions(-) (limited to 'src-migrate/pages') diff --git a/src-migrate/pages/shop/cart/index.tsx b/src-migrate/pages/shop/cart/index.tsx index 4b4de92b..9866be46 100644 --- a/src-migrate/pages/shop/cart/index.tsx +++ b/src-migrate/pages/shop/cart/index.tsx @@ -16,13 +16,17 @@ import Image from '~/components/ui/image'; const CartPage = () => { const auth = getAuth(); + const [isStepApproval, setIsStepApproval] = React.useState(false); const { loadCart, cart, summary } = useCartStore(); const useDivvice = useDevice(); useEffect(() => { - if (typeof auth === 'object' && !cart) loadCart(auth.id); + if (typeof auth === 'object' && !cart) { + loadCart(auth.id); + setIsStepApproval(auth?.feature?.soApproval); + } }, [auth, loadCart, cart]); const hasSelectedPromo = useMemo(() => { @@ -123,23 +127,24 @@ const CartPage = () => { Quotation - - - - + + + )}
-- cgit v1.2.3 From 145f9edfd32b385771483b9b95a9fa0fa24c2dec Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Fri, 26 Apr 2024 13:57:55 +0700 Subject: css --- src-migrate/pages/shop/cart/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src-migrate/pages') diff --git a/src-migrate/pages/shop/cart/index.tsx b/src-migrate/pages/shop/cart/index.tsx index 9866be46..e101b5ad 100644 --- a/src-migrate/pages/shop/cart/index.tsx +++ b/src-migrate/pages/shop/cart/index.tsx @@ -110,7 +110,7 @@ const CartPage = () => { )} -
+
Date: Tue, 4 Jun 2024 13:28:20 +0700 Subject: promo line --- src-migrate/pages/shop/promo/index.tsx | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src-migrate/pages') diff --git a/src-migrate/pages/shop/promo/index.tsx b/src-migrate/pages/shop/promo/index.tsx index f293bbe3..133be6df 100644 --- a/src-migrate/pages/shop/promo/index.tsx +++ b/src-migrate/pages/shop/promo/index.tsx @@ -1,6 +1,7 @@ import React from 'react' import { LazyLoadComponent } from 'react-lazy-load-image-component' import Hero from '~/modules/promo/components/Hero' +import PromotionProgram from '~/modules/promo/components/PromotinProgram' import Voucher from '~/modules/promo/components/Voucher' const PromoPage = () => { @@ -12,6 +13,12 @@ const PromoPage = () => {
+ + + + +
+ -- cgit v1.2.3 From 208b234320b6c42491a4e87a1c3db3abab9c1715 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 21 Jun 2024 10:52:28 +0700 Subject: update all-promotion --- src-migrate/pages/shop/promo/index.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src-migrate/pages') diff --git a/src-migrate/pages/shop/promo/index.tsx b/src-migrate/pages/shop/promo/index.tsx index 133be6df..5fdd80aa 100644 --- a/src-migrate/pages/shop/promo/index.tsx +++ b/src-migrate/pages/shop/promo/index.tsx @@ -1,10 +1,13 @@ -import React from 'react' +import dynamic from 'next/dynamic' +import React, { useState } from 'react' import { LazyLoadComponent } from 'react-lazy-load-image-component' import Hero from '~/modules/promo/components/Hero' import PromotionProgram from '~/modules/promo/components/PromotinProgram' import Voucher from '~/modules/promo/components/Voucher' +const PromoList = dynamic(() => import('../../../modules/promo/components/PromoList')); const PromoPage = () => { + const [selectedPromo, setSelectedPromo] = useState('Bundling'); return ( <> @@ -14,9 +17,12 @@ const PromoPage = () => {
- + - +
-- cgit v1.2.3 From 3ada88f0faf901e05bd56ecff8c4bcb209c06787 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 21 Jun 2024 15:31:12 +0700 Subject: update all-promotion --- src-migrate/pages/shop/promo/index.tsx | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src-migrate/pages') diff --git a/src-migrate/pages/shop/promo/index.tsx b/src-migrate/pages/shop/promo/index.tsx index 5fdd80aa..d1d6d70a 100644 --- a/src-migrate/pages/shop/promo/index.tsx +++ b/src-migrate/pages/shop/promo/index.tsx @@ -4,8 +4,11 @@ import { LazyLoadComponent } from 'react-lazy-load-image-component' import Hero from '~/modules/promo/components/Hero' import PromotionProgram from '~/modules/promo/components/PromotinProgram' import Voucher from '~/modules/promo/components/Voucher' +import FlashSale from '../../../modules/promo/components/FlashSale' const PromoList = dynamic(() => import('../../../modules/promo/components/PromoList')); + + const PromoPage = () => { const [selectedPromo, setSelectedPromo] = useState('Bundling'); return ( @@ -14,16 +17,18 @@ const PromoPage = () => { -
- + + + + + + - -
-- cgit v1.2.3 From bfeb27c25e416db41e211de54e7f7d0cac4ad792 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 24 Jun 2024 09:13:24 +0700 Subject: update all promotion add zustand --- src-migrate/pages/shop/promo/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src-migrate/pages') diff --git a/src-migrate/pages/shop/promo/index.tsx b/src-migrate/pages/shop/promo/index.tsx index d1d6d70a..7c4df2c1 100644 --- a/src-migrate/pages/shop/promo/index.tsx +++ b/src-migrate/pages/shop/promo/index.tsx @@ -29,7 +29,7 @@ const PromoPage = () => { - +

-- cgit v1.2.3 From 556cbc1e5ea1c1ef0170c9a1b8f470a3d92d888e Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Tue, 2 Jul 2024 10:40:06 +0700 Subject: IS SO APPROVAL --- src-migrate/pages/shop/cart/cart.module.css | 4 ++++ src-migrate/pages/shop/cart/index.tsx | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'src-migrate/pages') diff --git a/src-migrate/pages/shop/cart/cart.module.css b/src-migrate/pages/shop/cart/cart.module.css index 98a6ac86..806104be 100644 --- a/src-migrate/pages/shop/cart/cart.module.css +++ b/src-migrate/pages/shop/cart/cart.module.css @@ -29,3 +29,7 @@ .summary-buttons { @apply grid grid-cols-2 gap-x-3 mt-6; } + +.summary-buttons-step-approval { + @apply grid grid-cols-1 gap-y-3 mt-6; +} diff --git a/src-migrate/pages/shop/cart/index.tsx b/src-migrate/pages/shop/cart/index.tsx index e101b5ad..d89707d2 100644 --- a/src-migrate/pages/shop/cart/index.tsx +++ b/src-migrate/pages/shop/cart/index.tsx @@ -110,7 +110,7 @@ const CartPage = () => { )} -
+
Date: Fri, 12 Jul 2024 16:52:14 +0700 Subject: update bug button quotation on cart --- src-migrate/pages/shop/cart/index.tsx | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'src-migrate/pages') diff --git a/src-migrate/pages/shop/cart/index.tsx b/src-migrate/pages/shop/cart/index.tsx index d89707d2..7de96425 100644 --- a/src-migrate/pages/shop/cart/index.tsx +++ b/src-migrate/pages/shop/cart/index.tsx @@ -2,8 +2,9 @@ import style from './cart.module.css'; import React, { useEffect, useMemo } from 'react'; import Link from 'next/link'; -import { Button, Tooltip } from '@chakra-ui/react'; - +import { Button, Toast, Tooltip } from '@chakra-ui/react'; +import { toast } from 'react-hot-toast'; +import { useRouter } from 'next/router'; import { getAuth } from '~/libs/auth'; import { useCartStore } from '~/modules/cart/stores/useCartStore'; @@ -15,6 +16,7 @@ import CartSummaryMobile from '~/modules/cart/components/CartSummaryMobile'; import Image from '~/components/ui/image'; const CartPage = () => { + const router = useRouter(); const auth = getAuth(); const [isStepApproval, setIsStepApproval] = React.useState(false); @@ -52,6 +54,18 @@ const CartPage = () => { } return false; }, [cart]); + + const handleCheckout = (()=>{ + router.push('/shop/checkout'); + }) + + const handleQuotation = (()=>{ + if(hasSelectedPromo || !hasSelected){ + toast.error('Maaf, Barang promo tidak dapat dibuat quotation'); + }else{ + router.push('/shop/quotation'); + } + }) return ( <> @@ -121,8 +135,7 @@ const CartPage = () => { colorScheme='yellow' w='full' isDisabled={hasSelectedPromo || !hasSelected} - as={Link} - href='/shop/quotation' + onClick={handleQuotation} > Quotation @@ -138,8 +151,7 @@ const CartPage = () => { colorScheme='red' w='full' isDisabled={!hasSelected || hasSelectNoPrice} - as={Link} - href='/shop/checkout' + onClick={handleCheckout} > Checkout -- cgit v1.2.3 From 4ee24671bc23979d7ac18a5390082c0007928540 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Tue, 16 Jul 2024 15:17:17 +0700 Subject: add select all cart --- src-migrate/pages/shop/cart/index.tsx | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'src-migrate/pages') diff --git a/src-migrate/pages/shop/cart/index.tsx b/src-migrate/pages/shop/cart/index.tsx index 7de96425..1f89c7a3 100644 --- a/src-migrate/pages/shop/cart/index.tsx +++ b/src-migrate/pages/shop/cart/index.tsx @@ -1,8 +1,8 @@ import style from './cart.module.css'; -import React, { useEffect, useMemo } from 'react'; +import React, { useEffect, useMemo, useState } from 'react'; import Link from 'next/link'; -import { Button, Toast, Tooltip } from '@chakra-ui/react'; +import { Button, Checkbox, Toast, Tooltip } from '@chakra-ui/react'; import { toast } from 'react-hot-toast'; import { useRouter } from 'next/router'; import { getAuth } from '~/libs/auth'; @@ -19,6 +19,9 @@ const CartPage = () => { const router = useRouter(); const auth = getAuth(); const [isStepApproval, setIsStepApproval] = React.useState(false); + const [isSelectedAll, setIsSelectedAll] = useState(false); + const [isButtonChek, setIsButtonChek] = useState(false); + const [buttonSelectNow, setButtonSelectNow] = useState(true); const { loadCart, cart, summary } = useCartStore(); @@ -29,8 +32,9 @@ const CartPage = () => { loadCart(auth.id); setIsStepApproval(auth?.feature?.soApproval); } - }, [auth, loadCart, cart]); - + }, [auth, loadCart, cart, isButtonChek, ]); + + const hasSelectedPromo = useMemo(() => { if (!cart) return false; for (const item of cart.products) { @@ -67,10 +71,26 @@ const CartPage = () => { } }) + const handleChange = (()=>{ + setButtonSelectNow(!buttonSelectNow) + setIsSelectedAll(!isSelectedAll) + setIsButtonChek(!isButtonChek) + }) + return ( <>
Keranjang Belanja
- +
+

+ {buttonSelectNow? "Select all" : "Unchek all" } +

+
@@ -81,8 +101,9 @@ const CartPage = () => {
{cart?.products.map((item) => ( - + ))} + {cart?.products?.length === 0 && (
-- cgit v1.2.3 From 0f62655a7fa63a27f3af418108f44e3bc4bab980 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Tue, 16 Jul 2024 16:56:58 +0700 Subject: update location select all --- src-migrate/pages/shop/cart/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src-migrate/pages') diff --git a/src-migrate/pages/shop/cart/index.tsx b/src-migrate/pages/shop/cart/index.tsx index 1f89c7a3..2ecf1c03 100644 --- a/src-migrate/pages/shop/cart/index.tsx +++ b/src-migrate/pages/shop/cart/index.tsx @@ -80,6 +80,7 @@ const CartPage = () => { return ( <>
Keranjang Belanja
+
{ {buttonSelectNow? "Select all" : "Unchek all" }

-
-- cgit v1.2.3 From 795e774bfcf19e474ec4f4158856da0d1629bc3d Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Wed, 24 Jul 2024 10:14:46 +0700 Subject: update all promotion --- src-migrate/pages/shop/promo/index.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src-migrate/pages') diff --git a/src-migrate/pages/shop/promo/index.tsx b/src-migrate/pages/shop/promo/index.tsx index 7c4df2c1..febe31a4 100644 --- a/src-migrate/pages/shop/promo/index.tsx +++ b/src-migrate/pages/shop/promo/index.tsx @@ -16,8 +16,6 @@ const PromoPage = () => { - - { -

+

-- cgit v1.2.3 From 8c848cf35811ee95e88ce03745ee25315172d758 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Thu, 1 Aug 2024 15:29:17 +0700 Subject: update unchek all cart --- src-migrate/pages/shop/cart/index.tsx | 108 ++++++++++++++++++---------------- 1 file changed, 58 insertions(+), 50 deletions(-) (limited to 'src-migrate/pages') diff --git a/src-migrate/pages/shop/cart/index.tsx b/src-migrate/pages/shop/cart/index.tsx index 2ecf1c03..0eb9c554 100644 --- a/src-migrate/pages/shop/cart/index.tsx +++ b/src-migrate/pages/shop/cart/index.tsx @@ -2,29 +2,30 @@ import style from './cart.module.css'; import React, { useEffect, useMemo, useState } from 'react'; import Link from 'next/link'; -import { Button, Checkbox, Toast, Tooltip } from '@chakra-ui/react'; +import { Button, Checkbox, Tooltip } from '@chakra-ui/react'; import { toast } from 'react-hot-toast'; import { useRouter } from 'next/router'; import { getAuth } from '~/libs/auth'; import { useCartStore } from '~/modules/cart/stores/useCartStore'; -import CartItem from '~/modules/cart/components/Item'; +import CartItemModule from '~/modules/cart/components/Item'; import CartSummary from '~/modules/cart/components/Summary'; import clsxm from '~/libs/clsxm'; import useDevice from '@/core/hooks/useDevice'; import CartSummaryMobile from '~/modules/cart/components/CartSummaryMobile'; import Image from '~/components/ui/image'; +import { CartItem } from '~/types/cart' +import { upsertUserCart } from '~/services/cart' const CartPage = () => { const router = useRouter(); const auth = getAuth(); - const [isStepApproval, setIsStepApproval] = React.useState(false); - const [isSelectedAll, setIsSelectedAll] = useState(false); - const [isButtonChek, setIsButtonChek] = useState(false); - const [buttonSelectNow, setButtonSelectNow] = useState(true); + const [isStepApproval, setIsStepApproval] = useState(false); + const [isSelectedAll, setIsSelectedAll] = useState(false); + const [isButtonChek, setIsButtonChek] = useState(false); + const [buttonSelectNow, setButtonSelectNow] = useState(true); const { loadCart, cart, summary } = useCartStore(); - const useDivvice = useDevice(); useEffect(() => { @@ -32,78 +33,85 @@ const CartPage = () => { loadCart(auth.id); setIsStepApproval(auth?.feature?.soApproval); } - }, [auth, loadCart, cart, isButtonChek, ]); - - + }, [auth, loadCart, cart, isButtonChek]); + const hasSelectedPromo = useMemo(() => { if (!cart) return false; - for (const item of cart.products) { - if (item.cart_type === 'promotion' && item.selected) return true; - } - return false; + return cart.products.some(item => item.cart_type === 'promotion' && item.selected); }, [cart]); const hasSelected = useMemo(() => { if (!cart) return false; - for (const item of cart.products) { - if (item.selected) return true; - } - return false; + return cart.products.some(item => item.selected); }, [cart]); const hasSelectNoPrice = useMemo(() => { if (!cart) return false; - for (const item of cart.products) { - if (item.selected && item.price.price_discount == 0) return true; - } - return false; + return cart.products.some(item => item.selected && item.price.price_discount === 0); }, [cart]); - - const handleCheckout = (()=>{ - router.push('/shop/checkout'); - }) - const handleQuotation = (()=>{ - if(hasSelectedPromo || !hasSelected){ + const hasSelectedAll = useMemo(() => { + if (!cart || !Array.isArray(cart.products)) return false; + return cart.products.every(item => item.selected); + }, [cart]); + + const handleCheckout = () => { + router.push('/shop/checkout'); + } + + const handleQuotation = () => { + if (hasSelectedPromo || !hasSelected) { toast.error('Maaf, Barang promo tidak dapat dibuat quotation'); - }else{ + } else { router.push('/shop/quotation'); } - }) + } + + const handleChange = async (e: React.ChangeEvent) => { + if (typeof auth !== 'object' || !cart) return; + + const newSelected = e.target.checked; + setIsSelectedAll(newSelected); - const handleChange = (()=>{ - setButtonSelectNow(!buttonSelectNow) - setIsSelectedAll(!isSelectedAll) - setIsButtonChek(!isButtonChek) - }) + for (const item of cart.products) { + await upsertUserCart({ + userId: auth.id, + type: item.cart_type, + id: item.id, + qty: item.quantity, + selected: newSelected + }); + } + await loadCart(auth.id); + } return ( <>
Keranjang Belanja
-
-

- {buttonSelectNow? "Select all" : "Unchek all" } -

-
+
+ +

+ {hasSelectedAll ? "Unchek all" : "Select all"} +

+
- {!cart && } + {!cart && }
{cart?.products.map((item) => ( - + ))} - {cart?.products?.length === 0 && (
@@ -145,7 +153,7 @@ const CartPage = () => { )} -
+
Date: Fri, 2 Aug 2024 11:19:10 +0700 Subject: add delete all cart button --- src-migrate/pages/shop/cart/index.tsx | 58 +++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 13 deletions(-) (limited to 'src-migrate/pages') diff --git a/src-migrate/pages/shop/cart/index.tsx b/src-migrate/pages/shop/cart/index.tsx index 0eb9c554..cb0156f1 100644 --- a/src-migrate/pages/shop/cart/index.tsx +++ b/src-migrate/pages/shop/cart/index.tsx @@ -2,7 +2,7 @@ import style from './cart.module.css'; import React, { useEffect, useMemo, useState } from 'react'; import Link from 'next/link'; -import { Button, Checkbox, Tooltip } from '@chakra-ui/react'; +import { Button, Checkbox, Spinner, Tooltip } from '@chakra-ui/react'; import { toast } from 'react-hot-toast'; import { useRouter } from 'next/router'; import { getAuth } from '~/libs/auth'; @@ -24,6 +24,7 @@ const CartPage = () => { const [isSelectedAll, setIsSelectedAll] = useState(false); const [isButtonChek, setIsButtonChek] = useState(false); const [buttonSelectNow, setButtonSelectNow] = useState(true); + const [isLoad, setIsLoad] = useState(false) const { loadCart, cart, summary } = useCartStore(); const useDivvice = useDevice(); @@ -69,7 +70,7 @@ const CartPage = () => { const handleChange = async (e: React.ChangeEvent) => { if (typeof auth !== 'object' || !cart) return; - + setIsLoad(true) const newSelected = e.target.checked; setIsSelectedAll(newSelected); @@ -83,23 +84,54 @@ const CartPage = () => { }); } await loadCart(auth.id); + setIsLoad(false) + } + + const handleDelete = () => { + console.log("delete data"); } return ( <>
Keranjang Belanja
-
- -

- {hasSelectedAll ? "Unchek all" : "Select all"} -

+
+
+ {isLoad && ( + + )} + {!isLoad && ( + + )} +

+ {hasSelectedAll ? "Unchek all" : "Select all"} +

+
+
+ + + +
-- cgit v1.2.3 From 30a686e4140a503d88142e71c25bc517092b4bd5 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 2 Aug 2024 13:23:30 +0700 Subject: update delete button --- src-migrate/pages/shop/cart/index.tsx | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'src-migrate/pages') diff --git a/src-migrate/pages/shop/cart/index.tsx b/src-migrate/pages/shop/cart/index.tsx index cb0156f1..4586c65c 100644 --- a/src-migrate/pages/shop/cart/index.tsx +++ b/src-migrate/pages/shop/cart/index.tsx @@ -15,7 +15,8 @@ import useDevice from '@/core/hooks/useDevice'; import CartSummaryMobile from '~/modules/cart/components/CartSummaryMobile'; import Image from '~/components/ui/image'; import { CartItem } from '~/types/cart' -import { upsertUserCart } from '~/services/cart' +import { deleteUserCart ,upsertUserCart } from '~/services/cart' +import { Trash2Icon } from 'lucide-react'; const CartPage = () => { const router = useRouter(); @@ -25,7 +26,7 @@ const CartPage = () => { const [isButtonChek, setIsButtonChek] = useState(false); const [buttonSelectNow, setButtonSelectNow] = useState(true); const [isLoad, setIsLoad] = useState(false) - + const [isLoadDelete, setIsLoadDelete] = useState(false) const { loadCart, cart, summary } = useCartStore(); const useDivvice = useDevice(); @@ -87,8 +88,17 @@ const CartPage = () => { setIsLoad(false) } - const handleDelete = () => { - console.log("delete data"); + const handleDelete = async () => { + if (typeof auth !== 'object' || !cart) return; + + setIsLoadDelete(true) + for (const item of cart.products) { + if(item.selected === true){ + await deleteUserCart(auth.id, [item.cart_id]) + await loadCart(auth.id) + } + } + setIsLoadDelete(false) } return ( @@ -128,7 +138,11 @@ const CartPage = () => { isDisabled={!hasSelected || hasSelectNoPrice} onClick={handleDelete} > - Hapus Barang + {isLoadDelete && } + {!isLoadDelete && } +

+ Hapus Barang +

-- cgit v1.2.3 From 1f5adcf66c175dde3ce3694eedb1acddb05613e5 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 2 Aug 2024 13:30:56 +0700 Subject: add refresh cart after delete chart --- src-migrate/pages/shop/cart/index.tsx | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src-migrate/pages') diff --git a/src-migrate/pages/shop/cart/index.tsx b/src-migrate/pages/shop/cart/index.tsx index 4586c65c..d28e8c4b 100644 --- a/src-migrate/pages/shop/cart/index.tsx +++ b/src-migrate/pages/shop/cart/index.tsx @@ -17,6 +17,7 @@ import Image from '~/components/ui/image'; import { CartItem } from '~/types/cart' import { deleteUserCart ,upsertUserCart } from '~/services/cart' import { Trash2Icon } from 'lucide-react'; +import { useProductCartContext } from '@/contexts/ProductCartContext' const CartPage = () => { const router = useRouter(); @@ -29,6 +30,7 @@ const CartPage = () => { const [isLoadDelete, setIsLoadDelete] = useState(false) const { loadCart, cart, summary } = useCartStore(); const useDivvice = useDevice(); + const { setRefreshCart } = useProductCartContext() useEffect(() => { if (typeof auth === 'object' && !cart) { @@ -99,6 +101,7 @@ const CartPage = () => { } } setIsLoadDelete(false) + setRefreshCart(true) } return ( -- cgit v1.2.3 From 455e7b8daddec77f95929a7cb0eb31e8fa934e6d Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 2 Aug 2024 14:14:53 +0700 Subject: update unchek cart --- src-migrate/pages/shop/cart/index.tsx | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src-migrate/pages') diff --git a/src-migrate/pages/shop/cart/index.tsx b/src-migrate/pages/shop/cart/index.tsx index d28e8c4b..2204857a 100644 --- a/src-migrate/pages/shop/cart/index.tsx +++ b/src-migrate/pages/shop/cart/index.tsx @@ -31,6 +31,20 @@ const CartPage = () => { const { loadCart, cart, summary } = useCartStore(); const useDivvice = useDevice(); const { setRefreshCart } = useProductCartContext() + const [isTop, setIsTop] = useState(true); + + + useEffect(() => { + const handleScroll = () => { + console.log("lokasi",window.scrollY) + setIsTop(window.scrollY < 200); + }; + + window.addEventListener('scroll', handleScroll); + return () => { + window.removeEventListener('scroll', handleScroll); + }; + }, []); useEffect(() => { if (typeof auth === 'object' && !cart) { @@ -108,7 +122,7 @@ const CartPage = () => { <>
Keranjang Belanja
-
+
{isLoad && ( @@ -130,7 +144,6 @@ const CartPage = () => { - +
+
Keranjang Belanja
+
+
+
+ {isLoad && ( + + )} + {!isLoad && ( + + )} +

+ {hasSelectedAll ? "Unchek all" : "Select all"} +

+
+ + + +
+
+
-- cgit v1.2.3 From 4e25a60e9c3cf93cc1faf77a5bf1ad7e6f0555ec Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Sat, 3 Aug 2024 08:58:01 +0700 Subject: update view & add refresh cart --- src-migrate/pages/shop/cart/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src-migrate/pages') diff --git a/src-migrate/pages/shop/cart/index.tsx b/src-migrate/pages/shop/cart/index.tsx index 8d9ea91c..73b002b6 100644 --- a/src-migrate/pages/shop/cart/index.tsx +++ b/src-migrate/pages/shop/cart/index.tsx @@ -118,7 +118,7 @@ const CartPage = () => { return ( <> -
+
Keranjang Belanja
@@ -150,7 +150,7 @@ const CartPage = () => { variant='outline' colorScheme='red' w='full' - isDisabled={!hasSelected || hasSelectNoPrice} + isDisabled={!hasSelected} onClick={handleDelete} > {isLoadDelete && } -- cgit v1.2.3 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/pages/shop/cart/index.tsx | 97 ++++++++++++++++++++++++++++------- 1 file changed, 78 insertions(+), 19 deletions(-) (limited to 'src-migrate/pages') diff --git a/src-migrate/pages/shop/cart/index.tsx b/src-migrate/pages/shop/cart/index.tsx index 73b002b6..cfb20284 100644 --- a/src-migrate/pages/shop/cart/index.tsx +++ b/src-migrate/pages/shop/cart/index.tsx @@ -1,6 +1,6 @@ import style from './cart.module.css'; -import React, { useEffect, useMemo, useState } from 'react'; +import React, { useEffect, useMemo, useRef, useState } from 'react'; import Link from 'next/link'; import { Button, Checkbox, Spinner, Tooltip } from '@chakra-ui/react'; import { toast } from 'react-hot-toast'; @@ -28,10 +28,12 @@ const CartPage = () => { const [buttonSelectNow, setButtonSelectNow] = useState(true); const [isLoad, setIsLoad] = useState(false) const [isLoadDelete, setIsLoadDelete] = useState(false) - const { loadCart, cart, summary } = useCartStore(); + const { loadCart, cart, summary, updateCartItem } = useCartStore(); const useDivvice = useDevice(); const { setRefreshCart } = useProductCartContext() const [isTop, setIsTop] = useState(true); + const [hasChanged, setHasChanged] = useState(false); + const prevCartRef = useRef(null); useEffect(() => { const handleScroll = () => { @@ -51,6 +53,35 @@ const CartPage = () => { } }, [auth, loadCart, cart, isButtonChek]); + useEffect(() => { + if (typeof auth === 'object' && !cart) { + loadCart(auth.id); + setIsStepApproval(auth?.feature?.soApproval); + } + }, [auth, loadCart, cart, isButtonChek]); + + useEffect(() => { + const hasSelectedChanged = () => { + if (prevCartRef.current && cart) { + const prevCart = prevCartRef.current; + return cart.products.some((item, index) => + prevCart[index] && prevCart[index].selected !== item.selected + ); + } + return false; + }; + + if (hasSelectedChanged()) { + setHasChanged(true) + // Perform necessary actions here if selection has changed + }else{ + setHasChanged(false) + } + + // Update the ref to the current cart state + prevCartRef.current = cart ? [...cart.products] : null; + }, [cart]); + const hasSelectedPromo = useMemo(() => { if (!cart) return false; return cart.products.some(item => item.cart_type === 'promotion' && item.selected); @@ -71,6 +102,31 @@ const CartPage = () => { return cart.products.every(item => item.selected); }, [cart]); + + useEffect(() => { + const updateCartItems = async () => { + if (typeof auth === 'object' && cart) { + const upsertPromises = cart.products.map(item => + upsertUserCart({ + userId: auth.id, + type: item.cart_type, + id: item.id, + qty: item.quantity, + selected: item.selected + }) + ); + try { + await Promise.all(upsertPromises); + await loadCart(auth.id); + } catch (error) { + console.error('Failed to update cart items:', error); + } + } + }; + + updateCartItems(); + }, [hasChanged]); + const handleCheckout = () => { router.push('/shop/checkout'); } @@ -84,23 +140,26 @@ const CartPage = () => { } const handleChange = async (e: React.ChangeEvent) => { - if (typeof auth !== 'object' || !cart) return; - setIsLoad(true) - const newSelected = e.target.checked; - setIsSelectedAll(newSelected); - - for (const item of cart.products) { - await upsertUserCart({ - userId: auth.id, - type: item.cart_type, - id: item.id, - qty: item.quantity, - selected: newSelected - }); + + // Ensure that cart is not null before attempting to update + if (cart) { + const updatedCart = { + ...cart, + products: cart.products.map(item => ({ + ...item, + selected: !hasSelectedAll + })) + }; + + updateCartItem(updatedCart); // Pass only valid CartProps to updateCartItem + if(hasSelectedAll){ + setIsSelectedAll(false); + }else{ + setIsSelectedAll(true); + } } - await loadCart(auth.id); - setIsLoad(false) - } + }; + const handleDelete = async () => { if (typeof auth !== 'object' || !cart) return; @@ -136,7 +195,7 @@ const CartPage = () => { /> )}

- {hasSelectedAll ? "Unchek all" : "Select all"} + {hasSelectedAll ? "Uncheck all" : "Select all"}

-- cgit v1.2.3 From 213b4444c48896f24dd6803a9db2ae58af5b0391 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 5 Aug 2024 10:01:18 +0700 Subject: update unchek cart --- src-migrate/pages/shop/cart/index.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src-migrate/pages') diff --git a/src-migrate/pages/shop/cart/index.tsx b/src-migrate/pages/shop/cart/index.tsx index cfb20284..5e3e042a 100644 --- a/src-migrate/pages/shop/cart/index.tsx +++ b/src-migrate/pages/shop/cart/index.tsx @@ -78,7 +78,6 @@ const CartPage = () => { setHasChanged(false) } - // Update the ref to the current cart state prevCartRef.current = cart ? [...cart.products] : null; }, [cart]); @@ -141,7 +140,7 @@ const CartPage = () => { const handleChange = async (e: React.ChangeEvent) => { - // Ensure that cart is not null before attempting to update + if (cart) { const updatedCart = { ...cart, @@ -151,7 +150,7 @@ const CartPage = () => { })) }; - updateCartItem(updatedCart); // Pass only valid CartProps to updateCartItem + updateCartItem(updatedCart); if(hasSelectedAll){ setIsSelectedAll(false); }else{ -- cgit v1.2.3