diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2024-08-02 10:16:46 +0000 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2024-08-02 10:16:46 +0000 |
| commit | d8510399c21b2cf4bf606441397a0142bc265a94 (patch) | |
| tree | 75543baf82a73fb7e8dea6c8a1c353e02c57bbcd /src/lib | |
| parent | 6a2c25e83a45eeb5d613a99a0caa6f0ec1aae15f (diff) | |
| parent | 55c9f5e1fb868c85e704529ac914b3d75fc7744e (diff) | |
Merged in Feature/new-cart-popup (pull request #208)
Feature/new cart popup
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/cart/components/Cartheader.jsx | 9 | ||||
| -rw-r--r-- | src/lib/checkout/api/getVoucher.js | 10 | ||||
| -rw-r--r-- | src/lib/checkout/components/Checkout.jsx | 40 | ||||
| -rw-r--r-- | src/lib/product/components/ProductCard.jsx | 2 |
4 files changed, 43 insertions, 18 deletions
diff --git a/src/lib/cart/components/Cartheader.jsx b/src/lib/cart/components/Cartheader.jsx index 7d43a4da..f76634ce 100644 --- a/src/lib/cart/components/Cartheader.jsx +++ b/src/lib/cart/components/Cartheader.jsx @@ -7,10 +7,12 @@ import useAuth from '@/core/hooks/useAuth' import { useRouter } from 'next/router' import odooApi from '@/core/api/odooApi' import { useProductCartContext } from '@/contexts/ProductCartContext' +import currencyFormat from '@/core/utils/currencyFormat' +import Image from '@/core/components/elements/Image/Image' +import { createSlug } from '@/core/utils/slug' import whatsappUrl from '@/core/utils/whatsappUrl' import { AnimatePresence, motion } from 'framer-motion' import style from '../../../../src-migrate/modules/cart/styles/item-promo.module.css' - const { ShoppingCartIcon, PhotoIcon } = require('@heroicons/react/24/outline') const { default: Link } = require('next/link') @@ -27,7 +29,6 @@ const Cardheader = (cartCount) => { const [isHovered, setIsHovered] = useState(false) const [isTop, setIsTop] = useState(true) - const products = useMemo(() => { return productCart?.products || [] }, [productCart]) @@ -89,7 +90,6 @@ const Cardheader = (cartCount) => { const handleScroll = () => { setIsTop(window.scrollY === 0) } - window.addEventListener('scroll', handleScroll) return () => { window.removeEventListener('scroll', handleScroll) @@ -139,7 +139,6 @@ const Cardheader = (cartCount) => { transition={{ duration: 0.15, top: { duration: 0.3 } }} className={`fixed left-0 w-full h-full bg-black/50 z-10`} /> - <motion.div initial={{ opacity: 0 }} animate={{ opacity: 1, transition: { duration: 0.2 } }} @@ -249,7 +248,6 @@ const Cardheader = (cartCount) => { </p> </Link> )} - {product?.hasFlashsale && ( <div className='flex gap-x-1 items-center mb-2 mt-1'> <div className='badge-solid-red'> @@ -371,7 +369,6 @@ const Cardheader = (cartCount) => { </> )} </AnimatePresence> - </div> ) } diff --git a/src/lib/checkout/api/getVoucher.js b/src/lib/checkout/api/getVoucher.js index 54c8cce5..779cef43 100644 --- a/src/lib/checkout/api/getVoucher.js +++ b/src/lib/checkout/api/getVoucher.js @@ -1,4 +1,5 @@ import odooApi from '@/core/api/odooApi'; +import { getAuth } from '@/core/utils/auth' export const getVoucher = async (id, query) => { const queryParam = new URLSearchParams(query); @@ -22,3 +23,12 @@ export const findVoucher = async (code, id, source) => { } return dataVoucher; }; + + +export const getVoucherNew = async (source) => { + const id = getAuth()?.id; + const dataVoucher = await odooApi('GET', `/api/v1/user/${id}/voucher?${source}`) + + return dataVoucher + +}
\ No newline at end of file diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx index fde6f6de..09a791ee 100644 --- a/src/lib/checkout/components/Checkout.jsx +++ b/src/lib/checkout/components/Checkout.jsx @@ -30,7 +30,7 @@ import whatsappUrl from '@/core/utils/whatsappUrl'; import addressesApi from '@/lib/address/api/addressesApi'; import CartItem from '~/modules/cart/components/Item.tsx'; import ExpedisiList from '../api/ExpedisiList'; -import { findVoucher, getVoucher } from '../api/getVoucher'; +import { findVoucher, getVoucher, getVoucherNew } from '../api/getVoucher'; const SELF_PICKUP_ID = 32; @@ -40,6 +40,7 @@ const { getProductsCheckout } = require('../api/checkoutApi'); const Checkout = () => { const router = useRouter(); const query = router.query.source ?? null; + const qVoucher = router.query.voucher ?? null; const auth = useAuth(); const [activeVoucher, SetActiveVoucher] = useState(null); @@ -145,14 +146,16 @@ const Checkout = () => { }; const VoucherCode = async (code) => { - let dataVoucher = await findVoucher(code, auth.id, query); + const source = 'code=' + code + '&source=' + query; + // let dataVoucher = await findVoucher(code, auth.id, query); + let dataVoucher = await getVoucherNew(source); if (dataVoucher.length <= 0) { SetFindVoucher(1); return; } let addNewLine = dataVoucher[0]; - let checkList = listVouchers.findIndex( + let checkList = listVouchers?.findIndex( (voucher) => voucher.code == addNewLine.code ); if (checkList >= 0) { @@ -184,6 +187,7 @@ const Checkout = () => { }, [bottomPopup]); useEffect(() => { + voucher(); const loadExpedisi = async () => { let dataExpedisi = await ExpedisiList(); dataExpedisi = dataExpedisi.map((expedisi) => ({ @@ -204,7 +208,6 @@ const Checkout = () => { return () => { window.onpopstate = null; }; - // voucher() }, []); const hitungDiscountVoucher = (code) => { @@ -240,10 +243,19 @@ const Checkout = () => { }, [activeVoucher, listVouchers]); useEffect(() => { + if (qVoucher === 'PASTIHEMAT' && listVouchers) { + let code = qVoucher; + VoucherCode(code); + } + }, [listVouchers]); + + useEffect(() => { setProducts(cartCheckout?.products); setCheckWeight(cartCheckout?.hasProductWithoutWeight); setTotalWeight(cartCheckout?.totalWeight.g); - const hasFlashSale = cartCheckout?.products.some(product => product.hasFlashsale); + const hasFlashSale = cartCheckout?.products.some( + (product) => product.hasFlashsale + ); setHasFlashSale(hasFlashSale); }, [cartCheckout]); @@ -364,7 +376,7 @@ const Checkout = () => { carrier_id: selectedCarrierId, estimated_arrival_days: splitDuration(etd), delivery_service_type: selectedExpedisiService, - flash_sale : hasFlashSale, // dibuat negasi untuk ngetest kebalikan nilai false + flash_sale: hasFlashSale, // dibuat negasi untuk ngetest kebalikan nilai false voucher: activeVoucher, voucher_shipping: activeVoucherShipping, type: 'sale_order', @@ -381,7 +393,7 @@ const Checkout = () => { toast.error('Gagal melakukan transaksi, terjadi kesalahan internal'); return; } - + gtagPurchase(products, biayaKirim, isCheckouted.name); const midtrans = async () => { @@ -425,13 +437,17 @@ const Checkout = () => { } else { SetActiveVoucher(code); SetFindVoucher(null); - document.getElementById('uniqCode').value = ''; + document.getElementById('uniqCode') + ? (document.getElementById('uniqCode').value = '') + : ''; SetButtonTerapkan(false); } } else { SetActiveVoucher(code); SetFindVoucher(null); - document.getElementById('uniqCode').value = ''; + document.getElementById('uniqCode') + ? (document.getElementById('uniqCode').value = '') + : ''; SetButtonTerapkan(false); } }; @@ -1750,9 +1766,11 @@ const PickupAddress = ({ label }) => ( Kodepos : 14440 </p> <p className='mt-1 text-gray_r-11'>Telp : 021-2933 8828/29</p> - <p className='mt-1 text-gray_r-11 hover:text-red-500'><a href={whatsappUrl()} target='_blank' rel='noreferrer'> + <p className='mt-1 text-gray_r-11 hover:text-red-500'> + <a href={whatsappUrl()} target='_blank' rel='noreferrer'> Mobile : 0817-1718-1922 - </a></p> + </a> + </p> </div> </div> ); diff --git a/src/lib/product/components/ProductCard.jsx b/src/lib/product/components/ProductCard.jsx index a9d23b8c..94db144d 100644 --- a/src/lib/product/components/ProductCard.jsx +++ b/src/lib/product/components/ProductCard.jsx @@ -71,7 +71,7 @@ const ProductCard = ({ product, simpleTitle, variant = 'vertical' }) => { if (variant == 'vertical') { return ( - <div className='rounded shadow-sm border border-gray_r-4 bg-white h-[310px] md:h-[380px]'> + <div className='rounded shadow-sm border border-gray_r-4 bg-white h-[330px] md:h-[380px]'> <Link href={URL.product} className='border-b border-gray_r-4 relative'> <div className='relative'> <Image |
