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 | |
| parent | 6a2c25e83a45eeb5d613a99a0caa6f0ec1aae15f (diff) | |
| parent | 55c9f5e1fb868c85e704529ac914b3d75fc7744e (diff) | |
Merged in Feature/new-cart-popup (pull request #208)
Feature/new cart popup
| -rw-r--r-- | src-migrate/hooks/useUtmSource.ts | 2 | ||||
| -rw-r--r-- | src-migrate/modules/product-detail/components/AddToCart.tsx | 11 | ||||
| -rw-r--r-- | src-migrate/modules/product-promo/components/AddToCart.tsx | 4 | ||||
| -rw-r--r-- | src-migrate/modules/product-promo/components/Card.tsx | 5 | ||||
| -rw-r--r-- | src-migrate/modules/product-promo/components/ModalContent.tsx | 1 | ||||
| -rw-r--r-- | src-migrate/modules/product-promo/components/Section.tsx | 4 | ||||
| -rw-r--r-- | src-migrate/modules/register/components/Form.tsx | 2 | ||||
| -rw-r--r-- | src/core/components/elements/Navbar/NavbarDesktop.jsx | 2 | ||||
| -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 | ||||
| -rw-r--r-- | src/pages/my/recomendation/components/products-recomendatison.jsx | 10 | ||||
| -rw-r--r-- | src/pages/shop/brands/[slug].jsx | 6 |
14 files changed, 68 insertions, 40 deletions
diff --git a/src-migrate/hooks/useUtmSource.ts b/src-migrate/hooks/useUtmSource.ts index a72fae36..43fbdcae 100644 --- a/src-migrate/hooks/useUtmSource.ts +++ b/src-migrate/hooks/useUtmSource.ts @@ -7,7 +7,7 @@ const useUtmSource = () => { const [source, setSource] = useState<string>(); useEffect(() => { - console.log(router.pathname); + // console.log(router.pathname); if (router.pathname) { setSource(UTM_SOURCE[router.pathname as keyof typeof UTM_SOURCE]); diff --git a/src-migrate/modules/product-detail/components/AddToCart.tsx b/src-migrate/modules/product-detail/components/AddToCart.tsx index 0ac8229e..6c9aedf8 100644 --- a/src-migrate/modules/product-detail/components/AddToCart.tsx +++ b/src-migrate/modules/product-detail/components/AddToCart.tsx @@ -31,16 +31,17 @@ const AddToCart = ({ position: 'top', isClosable: true }) + const [product, setProducts] = useState(products); + const { productCart, setRefreshCart, setProductCart, refreshCart, isLoading, setIsloading } = - useProductCartContext() + 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 () => { @@ -55,8 +56,10 @@ const AddToCart = ({ isNaN(quantity) || typeof auth !== 'object' ) return; + setRefreshCart(true); setAddCartAlert(true); + toast.promise( upsertUserCart({ userId: auth.id, @@ -103,8 +106,7 @@ const AddToCart = ({ active={addCartAlert} close={() => { setAddCartAlert(false); - } - } + }} > <div className='flex mt-4'> <div className='w-[10%]'> @@ -128,7 +130,6 @@ const AddToCart = ({ </Link> </div> </div> - <div className='mt-8 mb-4'> <div className='text-h-sm font-semibold mb-6'> Kamu Mungkin Juga Suka diff --git a/src-migrate/modules/product-promo/components/AddToCart.tsx b/src-migrate/modules/product-promo/components/AddToCart.tsx index f066a4c8..10904f90 100644 --- a/src-migrate/modules/product-promo/components/AddToCart.tsx +++ b/src-migrate/modules/product-promo/components/AddToCart.tsx @@ -16,7 +16,6 @@ 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 @@ -32,11 +31,11 @@ const ProductPromoAddToCart = ({product, promotion }: Props) => { const [status, setStatus] = useState<Status>('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 () => { @@ -139,7 +138,6 @@ const ProductPromoAddToCart = ({product, promotion }: Props) => { </Link> </div> </div> - <div className='mt-8 mb-4'> <div className='text-h-sm font-semibold mb-6'> 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 b286aa5b..5c323276 100644 --- a/src-migrate/modules/product-promo/components/Card.tsx +++ b/src-migrate/modules/product-promo/components/Card.tsx @@ -16,7 +16,6 @@ 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'; @@ -133,7 +132,7 @@ const ProductPromoCard = ({product, promotion}: Props) => { </div> <div> - <ProductPromoAddToCart product={product} promotion={promotion} /> + <ProductPromoAddToCart product={product} promotion={promotion} /> </div> </div> @@ -190,7 +189,7 @@ const ProductPromoCard = ({product, promotion}: Props) => { </div> </div> <div> - <ProductPromoAddToCart product={product} promotion={promotion} /> + <ProductPromoAddToCart product={product} promotion={promotion} /> </div> </div> diff --git a/src-migrate/modules/product-promo/components/ModalContent.tsx b/src-migrate/modules/product-promo/components/ModalContent.tsx index 44ad52d6..256ef61a 100644 --- a/src-migrate/modules/product-promo/components/ModalContent.tsx +++ b/src-migrate/modules/product-promo/components/ModalContent.tsx @@ -5,6 +5,7 @@ import { getVariantPromoByCategory } from "~/services/productVariant" import { useModalStore } from "../stores/useModalStore" import ProductPromoCard from "./Card" + import { IProductDetail } from '~/types/product'; type Props = { product: IProductDetail diff --git a/src-migrate/modules/product-promo/components/Section.tsx b/src-migrate/modules/product-promo/components/Section.tsx index 05b849c7..1228a6f0 100644 --- a/src-migrate/modules/product-promo/components/Section.tsx +++ b/src-migrate/modules/product-promo/components/Section.tsx @@ -13,10 +13,10 @@ import { IProductDetail } from '~/types/product'; type Props = { productId: number; - product: IProductDetail + product: IProductDetail; } -const ProductPromoSection = ({product, 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[] } diff --git a/src-migrate/modules/register/components/Form.tsx b/src-migrate/modules/register/components/Form.tsx index 4baaf380..b834f97a 100644 --- a/src-migrate/modules/register/components/Form.tsx +++ b/src-migrate/modules/register/components/Form.tsx @@ -168,7 +168,7 @@ const Form = () => { <button type="submit" className="btn-yellow w-full mt-2" - disabled={!isFormValid || !isCheckedTNC || mutation.isLoading} + disabled={!isFormValid || !isCheckedTNC || mutation.isLoading || !isValidCaptcha} > {mutation.isLoading ? 'Loading...' : 'Daftar'} </button> diff --git a/src/core/components/elements/Navbar/NavbarDesktop.jsx b/src/core/components/elements/Navbar/NavbarDesktop.jsx index c6e80e87..7d9e4264 100644 --- a/src/core/components/elements/Navbar/NavbarDesktop.jsx +++ b/src/core/components/elements/Navbar/NavbarDesktop.jsx @@ -19,7 +19,6 @@ import DesktopView from '../../views/DesktopView'; import Link from '../Link/Link'; import NavbarUserDropdown from './NavbarUserDropdown'; import NextImage from 'next/image'; -import style from "./style/NavbarDesktop.module.css"; import { Button, Menu, @@ -28,6 +27,7 @@ import { MenuList, useDisclosure, } from '@chakra-ui/react'; +import style from "./style/NavbarDesktop.module.css"; const Search = dynamic(() => import('./Search'), { ssr: false }); const TopBanner = dynamic(() => import('./TopBanner'), { ssr: false }); 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 diff --git a/src/pages/my/recomendation/components/products-recomendatison.jsx b/src/pages/my/recomendation/components/products-recomendatison.jsx index d39d2a99..7da2fab1 100644 --- a/src/pages/my/recomendation/components/products-recomendatison.jsx +++ b/src/pages/my/recomendation/components/products-recomendatison.jsx @@ -80,7 +80,7 @@ const ProductsRecomendation = ({ id }) => { } }); - console.log('ini result', searchProduct.data.response); + // console.log('ini result', searchProduct.data.response); } return resultMapping; @@ -112,7 +112,7 @@ const ProductsRecomendation = ({ id }) => { setIsLoading(false); } else { setIsLoading(false); - console.log('No excel data available'); + // console.log('No excel data available'); } }; @@ -129,7 +129,7 @@ const ProductsRecomendation = ({ id }) => { const jsonData = XLSX.utils.sheet_to_json(worksheet); setExcelData(jsonData); - console.log('ini json data', jsonData); + // console.log('ini json data', jsonData); setIsLoading(false); }; @@ -146,13 +146,13 @@ const ProductsRecomendation = ({ id }) => { products[foundIndex].result.code = variant?.code; products[foundIndex].result.name = variant?.name; } else { - console.log('Data not found.'); + // console.log('Data not found.'); } setIsOpen(false); }; const handlingOtherRec = ({ product }) => { - console.log('ini product', product); + // console.log('ini product', product); const result = async () => await searchRecomendation({ product, index: 0, operator: 'OR' }); diff --git a/src/pages/shop/brands/[slug].jsx b/src/pages/shop/brands/[slug].jsx index c3a7299f..e786ef78 100644 --- a/src/pages/shop/brands/[slug].jsx +++ b/src/pages/shop/brands/[slug].jsx @@ -5,6 +5,7 @@ import _ from 'lodash' import Seo from '@/core/components/Seo' import Breadcrumb from '@/lib/brand/components/Breadcrumb' import useBrand from '@/lib/brand/hooks/useBrand' +import PageNotFound from '@/pages/404'; const BasicLayout = dynamic(() => import('@/core/components/layouts/BasicLayout')) const ProductSearch = dynamic(() => import('@/lib/product/components/ProductSearch')) @@ -17,10 +18,13 @@ export default function BrandDetail() { const brandName = getNameFromSlug(slug) const id = getIdFromSlug(slug) const {brand} = useBrand({id}) + if (!brand || !brand.data || _.isEmpty(brand.data)) { + return <PageNotFound />; + } return ( <BasicLayout> <Seo - title={`Distributor ${brandName} Indonesia Harga Official Indoteknik.com`} + title={`Jual Produk Resmi ${brandName} Indonesia | Indoteknik.com`} description='B2B Marketplace MRO & Industri dengan Layanan Pembayaran Tempo, Faktur Pajak, Online Quotation, Garansi Resmi & Harga Kompetitif' additionalMetaTags={[ { |
