From 4339c49be8f30dbb47b6882e61e909837dc91e81 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Wed, 31 Jul 2024 15:39:21 +0700 Subject: update auto reload add cart --- src-migrate/modules/product-detail/components/AddToCart.tsx | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src-migrate') diff --git a/src-migrate/modules/product-detail/components/AddToCart.tsx b/src-migrate/modules/product-detail/components/AddToCart.tsx index 097db98a..c4df555b 100644 --- a/src-migrate/modules/product-detail/components/AddToCart.tsx +++ b/src-migrate/modules/product-detail/components/AddToCart.tsx @@ -51,6 +51,9 @@ const AddToCart = ({ error: { title: 'Menambahkan ke keranjang', description: 'Gagal menambahkan ke keranjang belanja' }, } ) + setTimeout(() => { + window.location.reload(); + }, 1500); if (source === 'buy') { router.push('/shop/checkout?source=buy') -- cgit v1.2.3 From 0abd42f8b528b3166169fef7093d4d8b22f3fb79 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Thu, 1 Aug 2024 08:48:48 +0700 Subject: add pop up when hit keranjang button --- .../product-detail/components/AddToCart.tsx | 83 +++++++++++++++++++--- .../product-detail/components/PriceAction.tsx | 2 + .../product-detail/components/ProductDetail.tsx | 2 +- .../modules/product-promo/components/AddToCart.tsx | 65 ++++++++++++++++- .../modules/product-promo/components/Card.tsx | 9 +-- .../modules/product-promo/components/Section.tsx | 8 ++- src-migrate/types/promotion.ts | 3 + 7 files changed, 152 insertions(+), 20 deletions(-) (limited to 'src-migrate') diff --git a/src-migrate/modules/product-detail/components/AddToCart.tsx b/src-migrate/modules/product-detail/components/AddToCart.tsx index c4df555b..b2fed55d 100644 --- a/src-migrate/modules/product-detail/components/AddToCart.tsx +++ b/src-migrate/modules/product-detail/components/AddToCart.tsx @@ -1,19 +1,28 @@ -import { Button, useToast } from '@chakra-ui/react' +import BottomPopup from '@/core/components/elements/Popup/BottomPopup' +import { Button, Link, useToast } from '@chakra-ui/react' +import product from 'next-seo/lib/jsonld/product' import { useRouter } from 'next/router' - +import { useState } from 'react' +import Image from '~/components/ui/image' import { getAuth } from '~/libs/auth' import { upsertUserCart } from '~/services/cart' +import LazyLoad from 'react-lazy-load'; +import ProductSimilar from '../../../../src/lib/product/components/ProductSimilar'; +import { IProductDetail } from '~/types/product'; +import ImageNext from 'next/image'; type Props = { variantId: number | null, quantity?: number; source?: 'buy' | 'add_to_cart'; + products : IProductDetail } const AddToCart = ({ variantId, quantity = 1, - source = 'add_to_cart' + source = 'add_to_cart', + products }: Props) => { const auth = getAuth() const router = useRouter() @@ -21,6 +30,15 @@ const AddToCart = ({ position: 'top', isClosable: true }) + const [product, setProducts] = useState(products); + + const productSimilarQuery = [ + product?.name, + `fq=-product_id_i:${product.id}`, + `fq=-manufacture_id_i:${product.manufacture?.id || 0}`, + ].join('&'); + + const [addCartAlert, setAddCartAlert] = useState(false); const handleClick = async () => { if (typeof auth !== 'object') { @@ -34,6 +52,7 @@ const AddToCart = ({ isNaN(quantity) || typeof auth !== 'object' ) return; + setAddCartAlert(true); toast.promise( upsertUserCart({ @@ -51,9 +70,8 @@ const AddToCart = ({ error: { title: 'Menambahkan ke keranjang', description: 'Gagal menambahkan ke keranjang belanja' }, } ) - setTimeout(() => { - window.location.reload(); - }, 1500); + + if (source === 'buy') { router.push('/shop/checkout?source=buy') @@ -72,10 +90,55 @@ const AddToCart = ({ } return ( - +
+ + { + setAddCartAlert(false); + setTimeout(() => { + window.location.reload(); + }, 1500); + }} + > +
+
+ +
+
+ {product.name} +
+
+ + Lihat Keranjang + +
+
+ +
+
+ Kamu Mungkin Juga Suka +
+ + + +
+
+
) } -export default AddToCart \ No newline at end of file +export default AddToCart \ No newline at end of file diff --git a/src-migrate/modules/product-detail/components/PriceAction.tsx b/src-migrate/modules/product-detail/components/PriceAction.tsx index 81271f6e..9021264e 100644 --- a/src-migrate/modules/product-detail/components/PriceAction.tsx +++ b/src-migrate/modules/product-detail/components/PriceAction.tsx @@ -97,12 +97,14 @@ const PriceAction = ({ product }: Props) => { className={style['quantity-input']} /> {!isApproval && ( diff --git a/src-migrate/modules/product-detail/components/ProductDetail.tsx b/src-migrate/modules/product-detail/components/ProductDetail.tsx index fad35a7d..e4555913 100644 --- a/src-migrate/modules/product-detail/components/ProductDetail.tsx +++ b/src-migrate/modules/product-detail/components/ProductDetail.tsx @@ -129,7 +129,7 @@ const ProductDetail = ({ product }: Props) => { )}
- {!!activeVariantId && !isApproval && } + {!!activeVariantId && !isApproval && }

diff --git a/src-migrate/modules/product-promo/components/AddToCart.tsx b/src-migrate/modules/product-promo/components/AddToCart.tsx index 87017c14..488f3f98 100644 --- a/src-migrate/modules/product-promo/components/AddToCart.tsx +++ b/src-migrate/modules/product-promo/components/AddToCart.tsx @@ -9,19 +9,34 @@ import { IPromotion } from '~/types/promotion' import DesktopView from '../../../../src/core/components/views/DesktopView'; import MobileView from '../../../../src/core/components/views/MobileView'; +import BottomPopup from '@/core/components/elements/Popup/BottomPopup' +import ImageNext from 'next/image'; +import Link from 'next/link' +import LazyLoad from 'react-lazy-load' +import ProductSimilar from '../../../../src/lib/product/components/ProductSimilar'; +import { IProductDetail } from '~/types/product'; type Props = { promotion: IPromotion + product: IProductDetail } type Status = 'idle' | 'loading' | 'success' -const ProductPromoAddToCart = ({ promotion }: Props) => { +const ProductPromoAddToCart = ({product, promotion }: Props) => { + console.log("promotion",promotion) const auth = getAuth() const toast = useToast() const router = useRouter() const [status, setStatus] = useState('idle') + + const productSimilarQuery = [ + promotion?.name, + `fq=-product_id_i:${promotion.products[0].product_id}`, + ].join('&'); + + const [addCartAlert, setAddCartAlert] = useState(false); const handleButton = async () => { if (typeof auth !== 'object') { @@ -42,7 +57,7 @@ const ProductPromoAddToCart = ({ promotion }: Props) => { qtyAppend: true }) setStatus('idle') - + setAddCartAlert(true); toast({ title: 'Tambah ke keranjang', description: 'Berhasil menambahkan barang ke keranjang belanja', @@ -51,6 +66,9 @@ const ProductPromoAddToCart = ({ promotion }: Props) => { isClosable: true, position: 'top', }) + // setTimeout(() => { + // window.location.reload(); + // }, 1500); } useEffect(() => { @@ -92,6 +110,49 @@ const ProductPromoAddToCart = ({ promotion }: Props) => { {status === 'success' && Berhasil} {status !== 'success' && Keranjang} + { + setAddCartAlert(false); + setTimeout(() => { + window.location.reload(); + }, 1500); + }} + > +
+
+ +
+
+ {product.name} +
+
+ + Lihat Keranjang + +
+
+ +
+
+ Kamu Mungkin Juga Suka +
+ + + +
+

) diff --git a/src-migrate/modules/product-promo/components/Card.tsx b/src-migrate/modules/product-promo/components/Card.tsx index 728d23ca..b286aa5b 100644 --- a/src-migrate/modules/product-promo/components/Card.tsx +++ b/src-migrate/modules/product-promo/components/Card.tsx @@ -15,16 +15,17 @@ import clsxm from '~/libs/clsxm' import ProductPromoItem from './Item' import ProductPromoAddToCart from "./AddToCart" import ProductPromoCardCountdown from "./CardCountdown" +import { IProductDetail } from '~/types/product'; import MobileView from '../../../../src/core/components/views/MobileView'; import DesktopView from '../../../../src/core/components/views/DesktopView'; type Props = { promotion: IPromotion - + product: IProductDetail } -const ProductPromoCard = ({ promotion}: Props) => { +const ProductPromoCard = ({product, promotion}: Props) => { const [products, setProducts] = useState([]) const [freeProducts, setFreeProducts] = useState([]) const [error, setError] = useState(null) @@ -132,7 +133,7 @@ const ProductPromoCard = ({ promotion}: Props) => {
- +
@@ -189,7 +190,7 @@ const ProductPromoCard = ({ promotion}: Props) => {
- +
diff --git a/src-migrate/modules/product-promo/components/Section.tsx b/src-migrate/modules/product-promo/components/Section.tsx index 4e8a7dd5..ff565539 100644 --- a/src-migrate/modules/product-promo/components/Section.tsx +++ b/src-migrate/modules/product-promo/components/Section.tsx @@ -9,12 +9,14 @@ import { IPromotion } from '~/types/promotion' import { useModalStore } from "../stores/useModalStore" import ProductPromoCard from './Card' import ProductPromoModal from "./Modal" +import { IProductDetail } from '~/types/product'; type Props = { productId: number; + product: IProductDetail } -const ProductPromoSection = ({ productId }: Props) => { +const ProductPromoSection = ({product, productId }: Props) => { const promotionsQuery = useQuery({ queryKey: [`promotions.highlight`, productId], queryFn: async () => await fetch(`/api/product-variant/${productId}/promotion/highlight`).then((res) => res.json()) as { data: IPromotion[] } @@ -23,7 +25,7 @@ const ProductPromoSection = ({ productId }: Props) => { const promotions = promotionsQuery.data const { openModal } = useModalStore() - + console.log("productId",productId) return ( 0) || false} @@ -50,7 +52,7 @@ const ProductPromoSection = ({ productId }: Props) => { > {promotions?.data.map((promotion) => (
- +
))} diff --git a/src-migrate/types/promotion.ts b/src-migrate/types/promotion.ts index 85190aad..217bba33 100644 --- a/src-migrate/types/promotion.ts +++ b/src-migrate/types/promotion.ts @@ -10,15 +10,18 @@ export interface IPromotion { limit_user: number; limit_trx: number; price: number; + image: string; total_qty: number; products: { product_id: number; qty: number; + name: string; }[]; free_products: { product_id: number; qty: number; }[]; + } export interface IProductVariantPromo { -- cgit v1.2.3 From 7dbca25dede6cf213831f45321f5c7a28b4a6122 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Thu, 1 Aug 2024 09:07:41 +0700 Subject: add parameter product --- src-migrate/modules/product-promo/components/Modal.tsx | 8 ++++++-- src-migrate/modules/product-promo/components/ModalContent.tsx | 9 ++++++--- src-migrate/modules/product-promo/components/Section.tsx | 2 +- src-migrate/modules/promo/components/PromoList.tsx | 4 ++-- 4 files changed, 15 insertions(+), 8 deletions(-) (limited to 'src-migrate') diff --git a/src-migrate/modules/product-promo/components/Modal.tsx b/src-migrate/modules/product-promo/components/Modal.tsx index 0de672c2..1722b9df 100644 --- a/src-migrate/modules/product-promo/components/Modal.tsx +++ b/src-migrate/modules/product-promo/components/Modal.tsx @@ -3,8 +3,12 @@ import { Modal } from "~/components/ui/modal" import { useModalStore } from '../stores/useModalStore' import ProductPromoCategoryTab from './CategoryTab' import ProductPromoModalContent from './ModalContent' +import { IProductDetail } from '~/types/product'; -const ProductPromoModal = () => { +type Props = { + product: IProductDetail +} +const ProductPromoModal = ({product}:Props) => { const { active, closeModal } = useModalStore() return ( @@ -17,7 +21,7 @@ const ProductPromoModal = () => {
- + ) } diff --git a/src-migrate/modules/product-promo/components/ModalContent.tsx b/src-migrate/modules/product-promo/components/ModalContent.tsx index ab5129f8..44ad52d6 100644 --- a/src-migrate/modules/product-promo/components/ModalContent.tsx +++ b/src-migrate/modules/product-promo/components/ModalContent.tsx @@ -5,8 +5,11 @@ import { getVariantPromoByCategory } from "~/services/productVariant" import { useModalStore } from "../stores/useModalStore" import ProductPromoCard from "./Card" - -const ProductPromoModalContent = () => { +import { IProductDetail } from '~/types/product'; +type Props = { + product: IProductDetail +} +const ProductPromoModalContent = ({product}:Props) => { const { activeTab, variantId } = useModalStore() const promotionsQuery = useQuery( @@ -24,7 +27,7 @@ const ProductPromoModalContent = () => {
{promotions?.data.map((promo) => ( - + ))} {promotions?.data.length === 0 && (
Belum ada promo pada kategori ini
diff --git a/src-migrate/modules/product-promo/components/Section.tsx b/src-migrate/modules/product-promo/components/Section.tsx index ff565539..05b849c7 100644 --- a/src-migrate/modules/product-promo/components/Section.tsx +++ b/src-migrate/modules/product-promo/components/Section.tsx @@ -32,7 +32,7 @@ const ProductPromoSection = ({product, productId }: Props) => { height='450px' duration='700ms' > - + {promotions?.data && promotions?.data.length > 0 && (
diff --git a/src-migrate/modules/promo/components/PromoList.tsx b/src-migrate/modules/promo/components/PromoList.tsx index 42725034..4d0db3c2 100644 --- a/src-migrate/modules/promo/components/PromoList.tsx +++ b/src-migrate/modules/promo/components/PromoList.tsx @@ -114,7 +114,7 @@ const PromoList: React.FC = ({ selectedPromo }) => { {promoData?.map((promotion: IPromotion) => (
- +
))} @@ -122,7 +122,7 @@ const PromoList: React.FC = ({ selectedPromo }) => { )} {isMobile && (promoData?.map((promotion: IPromotion) => (
- +
)))} -- cgit v1.2.3 From 285e91d4b63ca8dbd0a9f55e9c7db8b833749c0a Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Thu, 1 Aug 2024 13:28:41 +0700 Subject: update popup cart --- .../modules/product-detail/components/AddToCart.tsx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src-migrate') diff --git a/src-migrate/modules/product-detail/components/AddToCart.tsx b/src-migrate/modules/product-detail/components/AddToCart.tsx index b2fed55d..42586032 100644 --- a/src-migrate/modules/product-detail/components/AddToCart.tsx +++ b/src-migrate/modules/product-detail/components/AddToCart.tsx @@ -10,6 +10,7 @@ import LazyLoad from 'react-lazy-load'; import ProductSimilar from '../../../../src/lib/product/components/ProductSimilar'; import { IProductDetail } from '~/types/product'; import ImageNext from 'next/image'; +import { useProductCartContext } from '@/contexts/ProductCartContext' type Props = { variantId: number | null, @@ -31,7 +32,9 @@ const AddToCart = ({ isClosable: true }) const [product, setProducts] = useState(products); - + const { productCart, setRefreshCart, setProductCart, refreshCart, isLoading, setIsloading } = + useProductCartContext() + const productSimilarQuery = [ product?.name, `fq=-product_id_i:${product.id}`, @@ -53,7 +56,7 @@ const AddToCart = ({ typeof auth !== 'object' ) return; setAddCartAlert(true); - + setRefreshCart(true) toast.promise( upsertUserCart({ userId: auth.id, @@ -100,10 +103,11 @@ const AddToCart = ({ active={addCartAlert} close={() => { setAddCartAlert(false); - setTimeout(() => { - window.location.reload(); - }, 1500); - }} + // setTimeout(() => { + // window.location.reload(); + // }, 1500); + } + } >
-- cgit v1.2.3 From 42829a0907590139ecf4328a7a9ff9f6504a9113 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Thu, 1 Aug 2024 13:40:57 +0700 Subject: update pop up cart --- src-migrate/modules/product-detail/components/AddToCart.tsx | 5 +---- src-migrate/modules/product-promo/components/AddToCart.tsx | 12 ++++-------- 2 files changed, 5 insertions(+), 12 deletions(-) (limited to 'src-migrate') diff --git a/src-migrate/modules/product-detail/components/AddToCart.tsx b/src-migrate/modules/product-detail/components/AddToCart.tsx index 42586032..644d5b90 100644 --- a/src-migrate/modules/product-detail/components/AddToCart.tsx +++ b/src-migrate/modules/product-detail/components/AddToCart.tsx @@ -56,7 +56,7 @@ const AddToCart = ({ typeof auth !== 'object' ) return; setAddCartAlert(true); - setRefreshCart(true) + setRefreshCart(true); toast.promise( upsertUserCart({ userId: auth.id, @@ -103,9 +103,6 @@ const AddToCart = ({ active={addCartAlert} close={() => { setAddCartAlert(false); - // setTimeout(() => { - // window.location.reload(); - // }, 1500); } } > diff --git a/src-migrate/modules/product-promo/components/AddToCart.tsx b/src-migrate/modules/product-promo/components/AddToCart.tsx index 488f3f98..aae5cfc0 100644 --- a/src-migrate/modules/product-promo/components/AddToCart.tsx +++ b/src-migrate/modules/product-promo/components/AddToCart.tsx @@ -15,6 +15,7 @@ import Link from 'next/link' import LazyLoad from 'react-lazy-load' import ProductSimilar from '../../../../src/lib/product/components/ProductSimilar'; import { IProductDetail } from '~/types/product'; +import { useProductCartContext } from '@/contexts/ProductCartContext' type Props = { promotion: IPromotion @@ -24,13 +25,13 @@ type Props = { type Status = 'idle' | 'loading' | 'success' const ProductPromoAddToCart = ({product, promotion }: Props) => { - console.log("promotion",promotion) const auth = getAuth() const toast = useToast() const router = useRouter() const [status, setStatus] = useState('idle') - + const { productCart, setRefreshCart, setProductCart, refreshCart, isLoading, setIsloading } = + useProductCartContext() const productSimilarQuery = [ promotion?.name, `fq=-product_id_i:${promotion.products[0].product_id}`, @@ -58,6 +59,7 @@ const ProductPromoAddToCart = ({product, promotion }: Props) => { }) setStatus('idle') setAddCartAlert(true); + setRefreshCart(true); toast({ title: 'Tambah ke keranjang', description: 'Berhasil menambahkan barang ke keranjang belanja', @@ -66,9 +68,6 @@ const ProductPromoAddToCart = ({product, promotion }: Props) => { isClosable: true, position: 'top', }) - // setTimeout(() => { - // window.location.reload(); - // }, 1500); } useEffect(() => { @@ -116,9 +115,6 @@ const ProductPromoAddToCart = ({product, promotion }: Props) => { active={addCartAlert} close={() => { setAddCartAlert(false); - setTimeout(() => { - window.location.reload(); - }, 1500); }} >
-- cgit v1.2.3 From 3542d65853072df17355f47a6abc3622375807ab Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Thu, 1 Aug 2024 17:10:17 +0700 Subject: update setRefresh cart --- src-migrate/modules/product-detail/components/AddToCart.tsx | 2 +- src-migrate/modules/product-promo/components/AddToCart.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src-migrate') diff --git a/src-migrate/modules/product-detail/components/AddToCart.tsx b/src-migrate/modules/product-detail/components/AddToCart.tsx index 644d5b90..0ac8229e 100644 --- a/src-migrate/modules/product-detail/components/AddToCart.tsx +++ b/src-migrate/modules/product-detail/components/AddToCart.tsx @@ -55,8 +55,8 @@ const AddToCart = ({ isNaN(quantity) || typeof auth !== 'object' ) return; - setAddCartAlert(true); setRefreshCart(true); + setAddCartAlert(true); toast.promise( upsertUserCart({ userId: auth.id, diff --git a/src-migrate/modules/product-promo/components/AddToCart.tsx b/src-migrate/modules/product-promo/components/AddToCart.tsx index aae5cfc0..f066a4c8 100644 --- a/src-migrate/modules/product-promo/components/AddToCart.tsx +++ b/src-migrate/modules/product-promo/components/AddToCart.tsx @@ -58,8 +58,8 @@ const ProductPromoAddToCart = ({product, promotion }: Props) => { qtyAppend: true }) setStatus('idle') - setAddCartAlert(true); setRefreshCart(true); + setAddCartAlert(true); toast({ title: 'Tambah ke keranjang', description: 'Berhasil menambahkan barang ke keranjang belanja', -- cgit v1.2.3 From f86b2adc680a9c6fa0ac92c84bf6d14e2f866d9a Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 2 Aug 2024 14:48:51 +0700 Subject: update popup cart --- .../product-detail/components/AddToCart.tsx | 79 ++++++++++++++++++++-- .../product-detail/components/PriceAction.tsx | 2 + .../product-detail/components/ProductDetail.tsx | 2 +- .../modules/product-promo/components/AddToCart.tsx | 61 ++++++++++++++++- .../modules/product-promo/components/Card.tsx | 10 +-- .../modules/product-promo/components/Modal.tsx | 8 ++- .../product-promo/components/ModalContent.tsx | 8 ++- .../modules/product-promo/components/Section.tsx | 8 ++- src-migrate/modules/promo/components/PromoList.tsx | 4 +- src-migrate/types/promotion.ts | 2 + 10 files changed, 159 insertions(+), 25 deletions(-) (limited to 'src-migrate') diff --git a/src-migrate/modules/product-detail/components/AddToCart.tsx b/src-migrate/modules/product-detail/components/AddToCart.tsx index 097db98a..320b7234 100644 --- a/src-migrate/modules/product-detail/components/AddToCart.tsx +++ b/src-migrate/modules/product-detail/components/AddToCart.tsx @@ -1,19 +1,28 @@ -import { Button, useToast } from '@chakra-ui/react' +import BottomPopup from '@/core/components/elements/Popup/BottomPopup' +import { Button, Link, useToast } from '@chakra-ui/react' +import product from 'next-seo/lib/jsonld/product' import { useRouter } from 'next/router' - +import { useState } from 'react' +import Image from '~/components/ui/image' import { getAuth } from '~/libs/auth' import { upsertUserCart } from '~/services/cart' - +import LazyLoad from 'react-lazy-load'; +import ProductSimilar from '../../../../src/lib/product/components/ProductSimilar'; +import { IProductDetail } from '~/types/product'; +import ImageNext from 'next/image'; +import { useProductCartContext } from '@/contexts/ProductCartContext' type Props = { variantId: number | null, quantity?: number; source?: 'buy' | 'add_to_cart'; + products : IProductDetail } const AddToCart = ({ variantId, quantity = 1, - source = 'add_to_cart' + source = 'add_to_cart', + products }: Props) => { const auth = getAuth() const router = useRouter() @@ -22,6 +31,18 @@ const AddToCart = ({ isClosable: true }) + const [product, setProducts] = useState(products); + + const { productCart, setRefreshCart, setProductCart, refreshCart, isLoading, setIsloading } = + useProductCartContext() + + const productSimilarQuery = [ + product?.name, + `fq=-product_id_i:${product.id}`, + `fq=-manufacture_id_i:${product.manufacture?.id || 0}`, + ].join('&'); + const [addCartAlert, setAddCartAlert] = useState(false); + const handleClick = async () => { if (typeof auth !== 'object') { const currentUrl = encodeURIComponent(router.asPath) @@ -35,6 +56,9 @@ const AddToCart = ({ typeof auth !== 'object' ) return; + setRefreshCart(true); + setAddCartAlert(true); + toast.promise( upsertUserCart({ userId: auth.id, @@ -69,9 +93,50 @@ const AddToCart = ({ } return ( - +
+ + { + setAddCartAlert(false); + }} + > +
+
+ +
+
+ {product.name} +
+
+ + Lihat Keranjang + +
+
+
+
+ Kamu Mungkin Juga Suka +
+ + + +
+
+
) } diff --git a/src-migrate/modules/product-detail/components/PriceAction.tsx b/src-migrate/modules/product-detail/components/PriceAction.tsx index 81271f6e..9021264e 100644 --- a/src-migrate/modules/product-detail/components/PriceAction.tsx +++ b/src-migrate/modules/product-detail/components/PriceAction.tsx @@ -97,12 +97,14 @@ const PriceAction = ({ product }: Props) => { className={style['quantity-input']} /> {!isApproval && ( diff --git a/src-migrate/modules/product-detail/components/ProductDetail.tsx b/src-migrate/modules/product-detail/components/ProductDetail.tsx index fad35a7d..e4555913 100644 --- a/src-migrate/modules/product-detail/components/ProductDetail.tsx +++ b/src-migrate/modules/product-detail/components/ProductDetail.tsx @@ -129,7 +129,7 @@ const ProductDetail = ({ product }: Props) => { )}
- {!!activeVariantId && !isApproval && } + {!!activeVariantId && !isApproval && }

diff --git a/src-migrate/modules/product-promo/components/AddToCart.tsx b/src-migrate/modules/product-promo/components/AddToCart.tsx index 87017c14..10904f90 100644 --- a/src-migrate/modules/product-promo/components/AddToCart.tsx +++ b/src-migrate/modules/product-promo/components/AddToCart.tsx @@ -9,19 +9,34 @@ import { IPromotion } from '~/types/promotion' import DesktopView from '../../../../src/core/components/views/DesktopView'; import MobileView from '../../../../src/core/components/views/MobileView'; - +import BottomPopup from '@/core/components/elements/Popup/BottomPopup' +import ImageNext from 'next/image'; +import Link from 'next/link' +import LazyLoad from 'react-lazy-load' +import ProductSimilar from '../../../../src/lib/product/components/ProductSimilar'; +import { IProductDetail } from '~/types/product'; +import { useProductCartContext } from '@/contexts/ProductCartContext' type Props = { promotion: IPromotion + product: IProductDetail } type Status = 'idle' | 'loading' | 'success' -const ProductPromoAddToCart = ({ promotion }: Props) => { +const ProductPromoAddToCart = ({product, promotion }: Props) => { const auth = getAuth() const toast = useToast() const router = useRouter() const [status, setStatus] = useState('idle') + const { productCart, setRefreshCart, setProductCart, refreshCart, isLoading, setIsloading } = + useProductCartContext() + + const productSimilarQuery = [ + promotion?.name, + `fq=-product_id_i:${promotion.products[0].product_id}`, + ].join('&'); + const [addCartAlert, setAddCartAlert] = useState(false); const handleButton = async () => { if (typeof auth !== 'object') { @@ -42,7 +57,8 @@ const ProductPromoAddToCart = ({ promotion }: Props) => { qtyAppend: true }) setStatus('idle') - + setRefreshCart(true); + setAddCartAlert(true); toast({ title: 'Tambah ke keranjang', description: 'Berhasil menambahkan barang ke keranjang belanja', @@ -92,6 +108,45 @@ const ProductPromoAddToCart = ({ promotion }: Props) => { {status === 'success' && Berhasil} {status !== 'success' && Keranjang} + { + setAddCartAlert(false); + }} + > +
+
+ +
+
+ {product.name} +
+
+ + Lihat Keranjang + +
+
+
+
+ Kamu Mungkin Juga Suka +
+ + + +
+

) diff --git a/src-migrate/modules/product-promo/components/Card.tsx b/src-migrate/modules/product-promo/components/Card.tsx index 728d23ca..5c323276 100644 --- a/src-migrate/modules/product-promo/components/Card.tsx +++ b/src-migrate/modules/product-promo/components/Card.tsx @@ -15,16 +15,16 @@ import clsxm from '~/libs/clsxm' import ProductPromoItem from './Item' import ProductPromoAddToCart from "./AddToCart" import ProductPromoCardCountdown from "./CardCountdown" - +import { IProductDetail } from '~/types/product'; import MobileView from '../../../../src/core/components/views/MobileView'; import DesktopView from '../../../../src/core/components/views/DesktopView'; type Props = { promotion: IPromotion - + product: IProductDetail } -const ProductPromoCard = ({ promotion}: Props) => { +const ProductPromoCard = ({product, promotion}: Props) => { const [products, setProducts] = useState([]) const [freeProducts, setFreeProducts] = useState([]) const [error, setError] = useState(null) @@ -132,7 +132,7 @@ const ProductPromoCard = ({ promotion}: Props) => {
- +
@@ -189,7 +189,7 @@ const ProductPromoCard = ({ promotion}: Props) => {
- +
diff --git a/src-migrate/modules/product-promo/components/Modal.tsx b/src-migrate/modules/product-promo/components/Modal.tsx index 0de672c2..1722b9df 100644 --- a/src-migrate/modules/product-promo/components/Modal.tsx +++ b/src-migrate/modules/product-promo/components/Modal.tsx @@ -3,8 +3,12 @@ import { Modal } from "~/components/ui/modal" import { useModalStore } from '../stores/useModalStore' import ProductPromoCategoryTab from './CategoryTab' import ProductPromoModalContent from './ModalContent' +import { IProductDetail } from '~/types/product'; -const ProductPromoModal = () => { +type Props = { + product: IProductDetail +} +const ProductPromoModal = ({product}:Props) => { const { active, closeModal } = useModalStore() return ( @@ -17,7 +21,7 @@ const ProductPromoModal = () => {
- + ) } diff --git a/src-migrate/modules/product-promo/components/ModalContent.tsx b/src-migrate/modules/product-promo/components/ModalContent.tsx index ab5129f8..256ef61a 100644 --- a/src-migrate/modules/product-promo/components/ModalContent.tsx +++ b/src-migrate/modules/product-promo/components/ModalContent.tsx @@ -6,7 +6,11 @@ import { getVariantPromoByCategory } from "~/services/productVariant" import { useModalStore } from "../stores/useModalStore" import ProductPromoCard from "./Card" -const ProductPromoModalContent = () => { +import { IProductDetail } from '~/types/product'; +type Props = { + product: IProductDetail +} +const ProductPromoModalContent = ({product}:Props) => { const { activeTab, variantId } = useModalStore() const promotionsQuery = useQuery( @@ -24,7 +28,7 @@ const ProductPromoModalContent = () => {
{promotions?.data.map((promo) => ( - + ))} {promotions?.data.length === 0 && (
Belum ada promo pada kategori ini
diff --git a/src-migrate/modules/product-promo/components/Section.tsx b/src-migrate/modules/product-promo/components/Section.tsx index 4e8a7dd5..2c94c2bb 100644 --- a/src-migrate/modules/product-promo/components/Section.tsx +++ b/src-migrate/modules/product-promo/components/Section.tsx @@ -9,12 +9,14 @@ import { IPromotion } from '~/types/promotion' import { useModalStore } from "../stores/useModalStore" import ProductPromoCard from './Card' import ProductPromoModal from "./Modal" +import { IProductDetail } from '~/types/product'; type Props = { productId: number; + product: IProductDetail; } -const ProductPromoSection = ({ productId }: Props) => { +const ProductPromoSection = ({ product, productId }: Props) => { const promotionsQuery = useQuery({ queryKey: [`promotions.highlight`, productId], queryFn: async () => await fetch(`/api/product-variant/${productId}/promotion/highlight`).then((res) => res.json()) as { data: IPromotion[] } @@ -30,7 +32,7 @@ const ProductPromoSection = ({ productId }: Props) => { height='450px' duration='700ms' > - + {promotions?.data && promotions?.data.length > 0 && (
@@ -50,7 +52,7 @@ const ProductPromoSection = ({ productId }: Props) => { > {promotions?.data.map((promotion) => (
- +
))} diff --git a/src-migrate/modules/promo/components/PromoList.tsx b/src-migrate/modules/promo/components/PromoList.tsx index 42725034..4d0db3c2 100644 --- a/src-migrate/modules/promo/components/PromoList.tsx +++ b/src-migrate/modules/promo/components/PromoList.tsx @@ -114,7 +114,7 @@ const PromoList: React.FC = ({ selectedPromo }) => { {promoData?.map((promotion: IPromotion) => (
- +
))} @@ -122,7 +122,7 @@ const PromoList: React.FC = ({ selectedPromo }) => { )} {isMobile && (promoData?.map((promotion: IPromotion) => (
- +
)))} diff --git a/src-migrate/types/promotion.ts b/src-migrate/types/promotion.ts index 85190aad..10f6d8b0 100644 --- a/src-migrate/types/promotion.ts +++ b/src-migrate/types/promotion.ts @@ -10,10 +10,12 @@ export interface IPromotion { limit_user: number; limit_trx: number; price: number; + image: string; total_qty: number; products: { product_id: number; qty: number; + name: string; }[]; free_products: { product_id: number; -- cgit v1.2.3 From 0f4938c0f9ce12d60bac2eb012a98b818fcd5110 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Tue, 6 Aug 2024 08:59:31 +0700 Subject: update refresh cart --- src-migrate/modules/product-detail/components/AddToCart.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src-migrate') diff --git a/src-migrate/modules/product-detail/components/AddToCart.tsx b/src-migrate/modules/product-detail/components/AddToCart.tsx index 6c9aedf8..c73d7b36 100644 --- a/src-migrate/modules/product-detail/components/AddToCart.tsx +++ b/src-migrate/modules/product-detail/components/AddToCart.tsx @@ -34,8 +34,7 @@ const AddToCart = ({ const [product, setProducts] = useState(products); - const { productCart, setRefreshCart, setProductCart, refreshCart, isLoading, setIsloading } = - useProductCartContext() + const {setRefreshCart} = useProductCartContext() const productSimilarQuery = [ product?.name, @@ -50,16 +49,17 @@ const AddToCart = ({ router.push(`/login?next=${currentUrl}`) return; } - + if ( !variantId || isNaN(quantity) || typeof auth !== 'object' ) return; - + setRefreshCart(true); + // console.log('Refresh cart triggered'); setAddCartAlert(true); - + toast.promise( upsertUserCart({ userId: auth.id, @@ -78,7 +78,7 @@ const AddToCart = ({ ) - + if (source === 'buy') { router.push('/shop/checkout?source=buy') } -- cgit v1.2.3 From 1ce47f63e967d32d8e6026c0f2e8da931d23fd4c Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Tue, 6 Aug 2024 10:21:43 +0700 Subject: update add to cart pop up --- .../product-detail/components/AddToCart.tsx | 59 +++++++++++++++++++++- .../modules/product-promo/components/AddToCart.tsx | 56 +++++++++++++++++++- 2 files changed, 111 insertions(+), 4 deletions(-) (limited to 'src-migrate') diff --git a/src-migrate/modules/product-detail/components/AddToCart.tsx b/src-migrate/modules/product-detail/components/AddToCart.tsx index c73d7b36..bebc793f 100644 --- a/src-migrate/modules/product-detail/components/AddToCart.tsx +++ b/src-migrate/modules/product-detail/components/AddToCart.tsx @@ -1,4 +1,5 @@ import BottomPopup from '@/core/components/elements/Popup/BottomPopup' +import style from '../styles/price-action.module.css'; import { Button, Link, useToast } from '@chakra-ui/react' import product from 'next-seo/lib/jsonld/product' import { useRouter } from 'next/router' @@ -11,6 +12,9 @@ import ProductSimilar from '../../../../src/lib/product/components/ProductSimila import { IProductDetail } from '~/types/product'; import ImageNext from 'next/image'; import { useProductCartContext } from '@/contexts/ProductCartContext' +import { createSlug } from '~/libs/slug' +import formatCurrency from '~/libs/formatCurrency' +import { useProductDetail } from '../stores/useProductDetail'; type Props = { variantId: number | null, @@ -32,6 +36,10 @@ const AddToCart = ({ isClosable: true }) + const { + askAdminUrl, + } = useProductDetail(); + const [product, setProducts] = useState(products); const {setRefreshCart} = useProductCartContext() @@ -118,8 +126,55 @@ const AddToCart = ({ height={80} />
-
- {product.name} +
+ {!!product.manufacture.name ? ( + + {product.manufacture.name} + + ) : '-'} +

+ {product.name} +

+

+ {product.code} +

+ {!!product.lowest_price && product.lowest_price.price > 0 && ( + <> +
+ {product.lowest_price.discount_percentage > 0 && ( + <> +
+ {Math.floor(product.lowest_price.discount_percentage)}% +
+
+ Rp {formatCurrency(product.lowest_price.price || 0)} +
+ + )} +
+ Rp {formatCurrency(product.lowest_price.price_discount || 0)} +
+
+ + )} + + {!!product.lowest_price && product.lowest_price.price === 0 && ( + + Hubungi kami untuk dapatkan harga terbaik,{' '} + + klik disini + + + )}
{ + const auth = getAuth() const toast = useToast() const router = useRouter() + const {askAdminUrl} = useProductDetail(); const [status, setStatus] = useState('idle') const { productCart, setRefreshCart, setProductCart, refreshCart, isLoading, setIsloading } = useProductCartContext() @@ -126,8 +131,55 @@ const ProductPromoAddToCart = ({product, promotion }: Props) => { height={80} />
-
- {product.name} +
+ {!!product.manufacture.name ? ( + + {product.manufacture.name} + + ) : '-'} +

+ {product.name} +

+

+ {product.code} +

+ {!!product.lowest_price && product.lowest_price.price > 0 && ( + <> +
+ {product.lowest_price.discount_percentage > 0 && ( + <> +
+ {Math.floor(product.lowest_price.discount_percentage)}% +
+
+ Rp {formatCurrency(product.lowest_price.price || 0)} +
+ + )} +
+ Rp {formatCurrency(product.lowest_price.price_discount || 0)} +
+
+ + )} + + {!!product.lowest_price && product.lowest_price.price === 0 && ( + + Hubungi kami untuk dapatkan harga terbaik,{' '} + + klik disini + + + )}
Date: Thu, 8 Aug 2024 11:37:58 +0700 Subject: update quotation pop up --- src-migrate/modules/product-detail/components/AddToCart.tsx | 1 - 1 file changed, 1 deletion(-) (limited to 'src-migrate') diff --git a/src-migrate/modules/product-detail/components/AddToCart.tsx b/src-migrate/modules/product-detail/components/AddToCart.tsx index bebc793f..2f87311f 100644 --- a/src-migrate/modules/product-detail/components/AddToCart.tsx +++ b/src-migrate/modules/product-detail/components/AddToCart.tsx @@ -65,7 +65,6 @@ const AddToCart = ({ ) return; setRefreshCart(true); - // console.log('Refresh cart triggered'); setAddCartAlert(true); toast.promise( -- cgit v1.2.3 From 079f8029445fdd243e267a4af7c7a4d5780afa24 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Thu, 8 Aug 2024 14:11:32 +0700 Subject: update pop up quotation & cart --- .../product-detail/components/AddToCart.tsx | 47 +++++++++++++--------- 1 file changed, 27 insertions(+), 20 deletions(-) (limited to 'src-migrate') diff --git a/src-migrate/modules/product-detail/components/AddToCart.tsx b/src-migrate/modules/product-detail/components/AddToCart.tsx index 2f87311f..a5284637 100644 --- a/src-migrate/modules/product-detail/components/AddToCart.tsx +++ b/src-migrate/modules/product-detail/components/AddToCart.tsx @@ -3,7 +3,7 @@ import style from '../styles/price-action.module.css'; import { Button, Link, useToast } from '@chakra-ui/react' import product from 'next-seo/lib/jsonld/product' import { useRouter } from 'next/router' -import { useState } from 'react' +import { useEffect, useState } from 'react' import Image from '~/components/ui/image' import { getAuth } from '~/libs/auth' import { upsertUserCart } from '~/services/cart' @@ -23,6 +23,8 @@ type Props = { products : IProductDetail } +type Status = 'idle' | 'loading' | 'success' + const AddToCart = ({ variantId, quantity = 1, @@ -41,8 +43,9 @@ const AddToCart = ({ } = useProductDetail(); const [product, setProducts] = useState(products); - - const {setRefreshCart} = useProductCartContext() + const [status, setStatus] = useState('idle') + const { productCart, setRefreshCart, setProductCart, refreshCart, isLoading, setIsloading } = + useProductCartContext() const productSimilarQuery = [ product?.name, @@ -51,7 +54,7 @@ const AddToCart = ({ ].join('&'); const [addCartAlert, setAddCartAlert] = useState(false); - const handleClick = async () => { + const handleButton = async () => { if (typeof auth !== 'object') { const currentUrl = encodeURIComponent(router.asPath) router.push(`/login?next=${currentUrl}`) @@ -63,33 +66,37 @@ const AddToCart = ({ isNaN(quantity) || typeof auth !== 'object' ) return; - - setRefreshCart(true); - setAddCartAlert(true); - - toast.promise( - upsertUserCart({ - userId: auth.id, + if (status === 'success') return + setStatus('loading') + await upsertUserCart({ + userId: auth.id, type: 'product', id: variantId, qty: quantity, selected: true, source: source, qtyAppend: true - }), - { - loading: { title: 'Menambahkan ke keranjang', description: 'Mohon tunggu...' }, - success: { title: 'Menambahkan ke keranjang', description: 'Berhasil menambahkan ke keranjang belanja' }, - error: { title: 'Menambahkan ke keranjang', description: 'Gagal menambahkan ke keranjang belanja' }, - } - ) - + }) + setStatus('idle') + setRefreshCart(true); + setAddCartAlert(true); + toast({ + title: 'Tambah ke keranjang', + description: 'Berhasil menambahkan barang ke keranjang belanja', + status: 'success', + duration: 3000, + isClosable: true, + position: 'top', + }) if (source === 'buy') { router.push('/shop/checkout?source=buy') } } + useEffect(() => { + if (status === 'success') setTimeout(() => { setStatus('idle') }, 3000) + }, [status]) const btnConfig = { 'add_to_cart': { @@ -104,7 +111,7 @@ const AddToCart = ({ return (
- Date: Thu, 8 Aug 2024 16:22:00 +0700 Subject: update link button --- src-migrate/modules/product-promo/components/AddToCart.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src-migrate') diff --git a/src-migrate/modules/product-promo/components/AddToCart.tsx b/src-migrate/modules/product-promo/components/AddToCart.tsx index 8567dad8..3d0955e3 100644 --- a/src-migrate/modules/product-promo/components/AddToCart.tsx +++ b/src-migrate/modules/product-promo/components/AddToCart.tsx @@ -132,7 +132,7 @@ const ProductPromoAddToCart = ({product, promotion }: Props) => { />
- {!!product.manufacture.name ? ( + {!!product?.manufacture?.name ? ( Date: Sat, 31 Aug 2024 09:42:34 +0700 Subject: update cart pop up --- src-migrate/pages/shop/cart/index.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src-migrate') diff --git a/src-migrate/pages/shop/cart/index.tsx b/src-migrate/pages/shop/cart/index.tsx index f33dde09..a2e477da 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, } = useCartStore(); const useDivvice = useDevice(); const { setRefreshCart } = useProductCartContext() const [isTop, setIsTop] = useState(true); + const [hasChanged, setHasChanged] = useState(false); + const prevCartRef = useRef(null); useEffect(() => { const handleScroll = () => { -- cgit v1.2.3 From ae6033238a4e7765bce7cbe96a2662f3c00b67c1 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Sat, 31 Aug 2024 09:51:26 +0700 Subject: upadate new cart pop up --- src-migrate/modules/cart/components/ItemAction.tsx | 5 +++-- src-migrate/modules/cart/stores/useCartStore.ts | 14 ++++++++++++-- src-migrate/pages/shop/cart/index.tsx | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) (limited to 'src-migrate') diff --git a/src-migrate/modules/cart/components/ItemAction.tsx b/src-migrate/modules/cart/components/ItemAction.tsx index e73d507b..7220e362 100644 --- a/src-migrate/modules/cart/components/ItemAction.tsx +++ b/src-migrate/modules/cart/components/ItemAction.tsx @@ -11,7 +11,7 @@ import { deleteUserCart, upsertUserCart } from '~/services/cart' import { useDebounce } from 'usehooks-ts' import { useCartStore } from '../stores/useCartStore' - +import { useProductCartContext } from '@/contexts/ProductCartContext' type Props = { item: CartItem @@ -19,7 +19,7 @@ type Props = { const CartItemAction = ({ item }: Props) => { const auth = getAuth() - + const { setRefreshCart } = useProductCartContext() const [isLoadDelete, setIsLoadDelete] = useState(false) const [isLoadQuantity, setIsLoadQuantity] = useState(false) @@ -36,6 +36,7 @@ const CartItemAction = ({ item }: Props) => { await deleteUserCart(auth.id, [item.cart_id]) await loadCart(auth.id) setIsLoadDelete(false) + setRefreshCart(true) } const decreaseQty = () => { setQuantity((quantity) => quantity -= 1) } diff --git a/src-migrate/modules/cart/stores/useCartStore.ts b/src-migrate/modules/cart/stores/useCartStore.ts index 3d9a0aed..aad39a30 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) => { @@ -61,4 +71,4 @@ const computeSummary = (cart: CartProps) => { let grandTotal = total + tax; return { subtotal, discount, total, tax, grandTotal }; -}; +}; \ No newline at end of file diff --git a/src-migrate/pages/shop/cart/index.tsx b/src-migrate/pages/shop/cart/index.tsx index a2e477da..c9ff86b7 100644 --- a/src-migrate/pages/shop/cart/index.tsx +++ b/src-migrate/pages/shop/cart/index.tsx @@ -28,7 +28,7 @@ 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); -- cgit v1.2.3 From a76376b74c02ee6875b68b6cfb59090a159df40a Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Sat, 31 Aug 2024 11:44:49 +0700 Subject: update new cart pop up --- src-migrate/modules/cart/components/ItemSelect.tsx | 28 +++++++++-------- .../modules/product-promo/components/AddToCart.tsx | 2 +- src-migrate/pages/shop/cart/index.tsx | 35 ++++++++++++++++++---- 3 files changed, 46 insertions(+), 19 deletions(-) (limited to 'src-migrate') 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/product-promo/components/AddToCart.tsx b/src-migrate/modules/product-promo/components/AddToCart.tsx index 3d0955e3..a3938142 100644 --- a/src-migrate/modules/product-promo/components/AddToCart.tsx +++ b/src-migrate/modules/product-promo/components/AddToCart.tsx @@ -135,7 +135,7 @@ const ProductPromoAddToCart = ({product, promotion }: Props) => { {!!product?.manufacture?.name ? ( {product.manufacture.name} diff --git a/src-migrate/pages/shop/cart/index.tsx b/src-migrate/pages/shop/cart/index.tsx index c9ff86b7..2fa53681 100644 --- a/src-migrate/pages/shop/cart/index.tsx +++ b/src-migrate/pages/shop/cart/index.tsx @@ -28,7 +28,7 @@ const CartPage = () => { const [buttonSelectNow, setButtonSelectNow] = useState(true); const [isLoad, setIsLoad] = useState(false) const [isLoadDelete, setIsLoadDelete] = useState(false) - const { loadCart, cart, summary, updateCartItem} = useCartStore(); + const { loadCart, cart, summary, updateCartItem } = useCartStore(); const useDivvice = useDevice(); const { setRefreshCart } = useProductCartContext() const [isTop, setIsTop] = useState(true); @@ -101,6 +101,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'); } @@ -151,7 +176,7 @@ const CartPage = () => { return ( <> -
+
Keranjang Belanja
@@ -169,7 +194,7 @@ const CartPage = () => { /> )}

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

@@ -183,7 +208,7 @@ const CartPage = () => { variant='outline' colorScheme='red' w='full' - isDisabled={!hasSelected || hasSelectNoPrice} + isDisabled={!hasSelected} onClick={handleDelete} > {isLoadDelete && } @@ -290,4 +315,4 @@ const CartPage = () => { ); }; -export default CartPage; +export default CartPage; \ No newline at end of file -- cgit v1.2.3 From a2221f7b66f259cddc83ae95c159b30d7e5612ce Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Sat, 31 Aug 2024 12:28:43 +0700 Subject: update new cart pop up image --- .../modules/product-promo/components/AddToCart.tsx | 23 +++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'src-migrate') diff --git a/src-migrate/modules/product-promo/components/AddToCart.tsx b/src-migrate/modules/product-promo/components/AddToCart.tsx index a3938142..757253f7 100644 --- a/src-migrate/modules/product-promo/components/AddToCart.tsx +++ b/src-migrate/modules/product-promo/components/AddToCart.tsx @@ -34,6 +34,7 @@ const ProductPromoAddToCart = ({product, promotion }: Props) => { const {askAdminUrl} = useProductDetail(); const [status, setStatus] = useState('idle') + const [idProduct, setidProduct] = useState() const { productCart, setRefreshCart, setProductCart, refreshCart, isLoading, setIsloading } = useProductCartContext() @@ -61,6 +62,7 @@ const ProductPromoAddToCart = ({product, promotion }: Props) => { source: 'add_to_cart', qtyAppend: true }) + setidProduct(promotion?.products[0]?.product_id) setStatus('idle') setRefreshCart(true); setAddCartAlert(true); @@ -123,13 +125,20 @@ const ProductPromoAddToCart = ({product, promotion }: Props) => { >
- + +
{!!product?.manufacture?.name ? ( -- cgit v1.2.3 From 702b5d9b6e215ad812fadaff3325e1e6164d3b24 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 2 Sep 2024 10:54:00 +0700 Subject: update pop up tambah keranjang --- src-migrate/modules/cart/stores/useCartStore.ts | 2 +- .../modules/product-promo/components/AddToCart.tsx | 97 ++++++++++------------ .../modules/product-promo/components/Card.tsx | 4 +- src-migrate/pages/api/product-variant/[id].tsx | 1 + src-migrate/types/promotion.ts | 4 + 5 files changed, 53 insertions(+), 55 deletions(-) (limited to 'src-migrate') diff --git a/src-migrate/modules/cart/stores/useCartStore.ts b/src-migrate/modules/cart/stores/useCartStore.ts index aad39a30..c2ebf50f 100644 --- a/src-migrate/modules/cart/stores/useCartStore.ts +++ b/src-migrate/modules/cart/stores/useCartStore.ts @@ -54,7 +54,7 @@ export const useCartStore = create((set, get) => ({ const computeSummary = (cart: CartProps) => { let subtotal = 0; let discount = 0; - for (const item of cart.products) { + for (const item of cart?.products) { if (!item.selected) continue; let price = 0; diff --git a/src-migrate/modules/product-promo/components/AddToCart.tsx b/src-migrate/modules/product-promo/components/AddToCart.tsx index 757253f7..7b3863f9 100644 --- a/src-migrate/modules/product-promo/components/AddToCart.tsx +++ b/src-migrate/modules/product-promo/components/AddToCart.tsx @@ -5,7 +5,7 @@ import { useEffect, useState } from 'react' import { getAuth } from '~/libs/auth' import { upsertUserCart } from '~/services/cart' -import { IPromotion } from '~/types/promotion' +import { IPromotion, IProductVariantPromo } from '~/types/promotion' import DesktopView from '../../../../src/core/components/views/DesktopView'; import MobileView from '../../../../src/core/components/views/MobileView'; @@ -22,59 +22,54 @@ import { useProductDetail } from '../../product-detail/stores/useProductDetail'; type Props = { promotion: IPromotion product: IProductDetail + variant: IProductVariantPromo, } type Status = 'idle' | 'loading' | 'success' -const ProductPromoAddToCart = ({product, promotion }: Props) => { - +const ProductPromoAddToCart = ({product, promotion, variant }: Props) => { const auth = getAuth() const toast = useToast() const router = useRouter() - const {askAdminUrl} = useProductDetail(); const [status, setStatus] = useState('idle') - const [idProduct, setidProduct] = useState() const { productCart, setRefreshCart, setProductCart, refreshCart, isLoading, setIsloading } = useProductCartContext() - const productSimilarQuery = [ promotion?.name, `fq=-product_id_i:${promotion.products[0].product_id}`, ].join('&'); const [addCartAlert, setAddCartAlert] = useState(false); - + const handleButton = async () => { if (typeof auth !== 'object') { - const currentUrl = encodeURIComponent(router.asPath) - router.push(`/login?next=${currentUrl}`) - return - } - if (status === 'success') return - - setStatus('loading') - await upsertUserCart({ - userId: auth.id, - type: 'promotion', - id: promotion.id, - qty: 1, - selected: true, - source: 'add_to_cart', - qtyAppend: true - }) - setidProduct(promotion?.products[0]?.product_id) - setStatus('idle') - setRefreshCart(true); - setAddCartAlert(true); - toast({ - title: 'Tambah ke keranjang', - description: 'Berhasil menambahkan barang ke keranjang belanja', - status: 'success', - duration: 3000, - isClosable: true, - position: 'top', - }) + const currentUrl = encodeURIComponent(router.asPath) + router.push(`/login?next=${currentUrl}`) + return } + if (status === 'success') return + setStatus('loading') + await upsertUserCart({ + userId: auth.id, + type: 'promotion', + id: promotion.id, + qty: 1, + selected: true, + source: 'add_to_cart', + qtyAppend: true + }) + setStatus('idle') + setRefreshCart(true); + setAddCartAlert(true); + toast({ + title: 'Tambah ke keranjang', + description: 'Berhasil menambahkan barang ke keranjang belanja', + status: 'success', + duration: 3000, + isClosable: true, + position: 'top', + }) +} useEffect(() => { if (status === 'success') setTimeout(() => { setStatus('idle') }, 3000) @@ -128,12 +123,10 @@ const ProductPromoAddToCart = ({product, promotion }: Props) => { {
- {!!product?.manufacture?.name ? ( + {!!product?.manufacture?.name || variant?.manufacture && ( - {product.manufacture.name} + {product?.manufacture?.name ? product?.manufacture?.name : variant?.manufacture?.manufacture_name} - ) : '-'} + )}

- {product.name} + {product?.name ? product?.name : variant?.name}

- {product.code} + {product?.code}

- {!!product.lowest_price && product.lowest_price.price > 0 && ( + {(!!product?.lowest_price && product?.lowest_price?.price > 0) || variant?.price?.price > 0 && ( <>
- {product.lowest_price.discount_percentage > 0 && ( + {(product?.lowest_price?.discount_percentage > 0) || variant?.price?.discount_percentage > 0 && ( <>
- {Math.floor(product.lowest_price.discount_percentage)}% + {Math.floor(product?.lowest_price?.discount_percentage ? product?.lowest_price?.discount_percentage : variant?.price?.discount_percentage)}%
- Rp {formatCurrency(product.lowest_price.price || 0)} + Rp {formatCurrency(product?.lowest_price?.price ? product?.lowest_price?.price || 0 : variant?.price?.price || 0)}
)}
- Rp {formatCurrency(product.lowest_price.price_discount || 0)} + Rp {formatCurrency(product?.lowest_price?.price_discount? product?.lowest_price?.price_discount || 0 : variant?.price?.price_discount)}
)} - {!!product.lowest_price && product.lowest_price.price === 0 && ( + {(!!product?.lowest_price && product?.lowest_price?.price === 0) || variant?.price?.price === 0 && ( Hubungi kami untuk dapatkan harga terbaik,{' '} {
- +
@@ -189,7 +189,7 @@ const ProductPromoCard = ({product, promotion}: Props) => {
- +
diff --git a/src-migrate/pages/api/product-variant/[id].tsx b/src-migrate/pages/api/product-variant/[id].tsx index 955fde6a..2c46ac89 100644 --- a/src-migrate/pages/api/product-variant/[id].tsx +++ b/src-migrate/pages/api/product-variant/[id].tsx @@ -38,6 +38,7 @@ const map = async (variant: any, price_tier: string) => { data.name = variant.name_s data.default_code = variant.default_code_s data.price = { discount_percentage: 0, price, price_discount: price } + data.manufacture = {manufacture_name: variant.manufacture_name_s, manufacture_id:variant.manufacture_id_i} return data } diff --git a/src-migrate/types/promotion.ts b/src-migrate/types/promotion.ts index 217bba33..dce442ad 100644 --- a/src-migrate/types/promotion.ts +++ b/src-migrate/types/promotion.ts @@ -37,6 +37,10 @@ export interface IProductVariantPromo { price_discount: number; }; qty: number; + manufacture: { + manufacture_name: string; + manufacture_id:number; + } } export type CategoryPromo = 'bundling' | 'discount_loading' | 'merchandise'; -- cgit v1.2.3