From f90ec98c509fad7146c169d8d762b4c847d07af8 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 15 Sep 2023 09:15:54 +0700 Subject: Add product context provider --- src/contexts/ProductContext.js | 15 +++++++++++++++ src/pages/_app.jsx | 5 ++++- src/pages/shop/product/[slug].jsx | 13 +++++++++++-- 3 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 src/contexts/ProductContext.js (limited to 'src') diff --git a/src/contexts/ProductContext.js b/src/contexts/ProductContext.js new file mode 100644 index 00000000..7bf65989 --- /dev/null +++ b/src/contexts/ProductContext.js @@ -0,0 +1,15 @@ +import { createContext, useContext, useState } from 'react' + +const ProductContext = createContext() + +export const ProductProvider = ({ children }) => { + const [product, setProduct] = useState(null) + + return ( + {children} + ) +} + +export const useProductContext = () => { + return useContext(ProductContext) +} diff --git a/src/pages/_app.jsx b/src/pages/_app.jsx index 7f23b94b..ef737794 100644 --- a/src/pages/_app.jsx +++ b/src/pages/_app.jsx @@ -10,6 +10,7 @@ import { createContext, useContext, useEffect, useState } from 'react' import LogoSpinner from '@/core/components/elements/Spinner/LogoSpinner' import { SessionProvider } from 'next-auth/react' import { getAuth } from '@/core/utils/auth' +import { ProductProvider } from '@/contexts/ProductContext' const queryClient = new QueryClient() @@ -93,7 +94,9 @@ function MyApp({ Component, pageProps: { session, ...pageProps } }) { initial={false} onExitComplete={() => window.scrollTo(0, 0)} > - {!animateLoader && } + + {!animateLoader && } + diff --git a/src/pages/shop/product/[slug].jsx b/src/pages/shop/product/[slug].jsx index af20413f..534aa8da 100644 --- a/src/pages/shop/product/[slug].jsx +++ b/src/pages/shop/product/[slug].jsx @@ -7,6 +7,8 @@ import dynamic from 'next/dynamic' import { useRouter } from 'next/router' import cookie from 'cookie' import axios from 'axios' +import { useProductContext } from '@/contexts/ProductContext' +import { useEffect } from 'react' const BasicLayout = dynamic(() => import('@/core/components/layouts/BasicLayout')) const Product = dynamic(() => import('@/lib/product/components/Product/Product')) @@ -19,7 +21,7 @@ export async function getServerSideProps(context) { const authToken = auth?.token || '' let response = await axios( - `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/product-detail?id=`+getIdFromSlug(slug) + `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/product-detail?id=` + getIdFromSlug(slug) ) let product = response.data // let productSolr = await productApi({ id: getIdFromSlug(slug), headers: { Token: authToken } }) @@ -41,8 +43,15 @@ export async function getServerSideProps(context) { } } -export default function ProductDetail({ product}) { +export default function ProductDetail({ product }) { const router = useRouter() + const { setProduct } = useProductContext() + + useEffect(() => { + if (product) { + setProduct(product) + } + }, [product, setProduct]) if (!product) return -- cgit v1.2.3 From e5c08cb213d0c6dbfa5a931e03eeccac518ddba1 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Fri, 15 Sep 2023 09:32:12 +0700 Subject: change get product odoo to solr di page navbar & basiclayout & bugfix redirect login next page null --- .../components/elements/Navbar/NavbarDesktop.jsx | 37 +++++++++++----------- src/core/components/layouts/BasicLayout.jsx | 17 ++++++++++ src/core/utils/whatsappUrl.js | 5 +-- 3 files changed, 38 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/core/components/elements/Navbar/NavbarDesktop.jsx b/src/core/components/elements/Navbar/NavbarDesktop.jsx index 655c4732..2e4b25fc 100644 --- a/src/core/components/elements/Navbar/NavbarDesktop.jsx +++ b/src/core/components/elements/Navbar/NavbarDesktop.jsx @@ -22,6 +22,7 @@ import productApi from '@/lib/product/api/productApi' import { useSession } from 'next-auth/react' import { AuthContext } from '@/pages/_app' import { TopBannerSkeleton } from '../Skeleton/TopBannerSkeleton' +import { useProductContext } from '@/contexts/ProductContext' const Search = dynamic(() => import('./Search')) const TopBanner = dynamic(() => import('./TopBanner'), { @@ -30,7 +31,7 @@ const TopBanner = dynamic(() => import('./TopBanner'), { const NavbarDesktop = () => { const [isOpenCategory, setIsOpenCategory] = useState(false) - const {authenticated} = useContext(AuthContext) + const { authenticated } = useContext(AuthContext) const auth = useAuth() const [cartCount, setCartCount] = useState(0) @@ -40,7 +41,22 @@ const NavbarDesktop = () => { const [urlPath, setUrlPath] = useState(null) const router = useRouter() - + + const { product } = useProductContext() + + useEffect(() => { + if (router.pathname === '/shop/product/[slug]') { + setPayloadWa({ + name: product?.name, + manufacture: product?.manufacture.name, + url: createSlug('/shop/product/', product?.name, product?.id, true) + }) + setTemplateWA('product') + + setUrlPath(router.asPath) + } + }, [product, router]) + useEffect(() => { const handleCartChange = () => { const cart = async () => { @@ -52,23 +68,6 @@ const NavbarDesktop = () => { handleCartChange() window.addEventListener('localStorageChange', handleCartChange) - if (router.pathname === '/shop/product/[slug]') { - const authToken = getAuth().token - - const { slug } = router.query - const getProduct = async () => { - let product = await productApi({ id: getIdFromSlug(slug), headers: { Token: authToken } }) - setPayloadWa({ - name: product[0]?.name, - manufacture: product[0]?.manufacture.name, - url: createSlug('/shop/product/', product[0]?.name, product[0]?.id, true) - }) - } - getProduct() - setTemplateWA('product') - - setUrlPath(router.asPath) - } return () => { window.removeEventListener('localStorageChange', handleCartChange) diff --git a/src/core/components/layouts/BasicLayout.jsx b/src/core/components/layouts/BasicLayout.jsx index 266223d8..030f916c 100644 --- a/src/core/components/layouts/BasicLayout.jsx +++ b/src/core/components/layouts/BasicLayout.jsx @@ -11,6 +11,7 @@ import { getAuth, setAuth } from '@/core/utils/auth' import { createSlug, getIdFromSlug } from '@/core/utils/slug' import { useSession } from 'next-auth/react' import { setCookie } from 'cookies-next' +import { useProductContext } from '@/contexts/ProductContext' const Navbar = dynamic(() => import('../elements/Navbar/Navbar')) const AnimationLayout = dynamic(() => import('./AnimationLayout')) @@ -22,6 +23,22 @@ const BasicLayout = ({ children }) => { const router = useRouter() + const { product } = useProductContext() + + useEffect(() => { + if (router.pathname === '/shop/product/[slug]') { + setPayloadWa({ + name: product?.name, + manufacture: product?.manufacture.name, + url: createSlug('/shop/product/', product?.name, product?.id, true) + }) + setTemplateWA('product') + + setUrlPath(router.asPath) + } + }, [product, router]) + + useEffect(() => { const getIP = async () => { const ip = await odooApi('GET', '/api/ip-address') diff --git a/src/core/utils/whatsappUrl.js b/src/core/utils/whatsappUrl.js index 6c354924..9a92f424 100644 --- a/src/core/utils/whatsappUrl.js +++ b/src/core/utils/whatsappUrl.js @@ -1,9 +1,10 @@ import { getAuth } from "./auth" -const whatsappUrl = (template = 'default', payload, urlPath = '') => { +const whatsappUrl = (template = 'default', payload, urlPath = null) => { let user = getAuth() if(!user){ - return `/login?next=${urlPath}` + if(urlPath) return `/login?next=${urlPath}` + if(!urlPath) return '/login' } let parentName = user.parentName || '-' let url = 'https://wa.me/628128080622' -- cgit v1.2.3 From 78308df2833127e827bff1e714fc4800219db308 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Fri, 15 Sep 2023 09:58:05 +0700 Subject: delete get prodcutApi di basicLayout --- src/core/components/layouts/BasicLayout.jsx | 17 ----------------- 1 file changed, 17 deletions(-) (limited to 'src') diff --git a/src/core/components/layouts/BasicLayout.jsx b/src/core/components/layouts/BasicLayout.jsx index 030f916c..e6bd4de0 100644 --- a/src/core/components/layouts/BasicLayout.jsx +++ b/src/core/components/layouts/BasicLayout.jsx @@ -50,23 +50,6 @@ const BasicLayout = ({ children }) => { axios.get(`/api/user-activity?page_title=${data.page_title}&url=${data.url}&ip=${data.ip}`) } getIP() - if (router.pathname === '/shop/product/[slug]') { - const authToken = getAuth().token - - const { slug } = router.query - const getProduct = async () => { - let product = await productApi({ id: getIdFromSlug(slug), headers: { Token: authToken } }) - setPayloadWa({ - name: product[0]?.name, - manufacture: product[0]?.manufacture.name, - url: createSlug('/shop/product/', product[0]?.name, product[0]?.id, true) - }) - } - getProduct() - setTemplateWA('product') - - setUrlPath(router.asPath) - } }, []) return ( <> -- cgit v1.2.3 From 97c93a60baba9bba1af1e1774ab166ce0d98db13 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Fri, 15 Sep 2023 15:04:16 +0700 Subject: fix bugs get variant limit --- src/pages/api/shop/product-detail.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/pages/api/shop/product-detail.js b/src/pages/api/shop/product-detail.js index 9020103b..5c3a8231 100644 --- a/src/pages/api/shop/product-detail.js +++ b/src/pages/api/shop/product-detail.js @@ -7,7 +7,7 @@ export default async function handler(req, res) { ) let productVariants = await axios( process.env.SOLR_HOST + - `/solr/variants/select?q=template_id_i:${req.query.id}&q.op=OR&indent=true` + `/solr/variants/select?q=template_id_i:${req.query.id}&q.op=OR&indent=true&rows=100` ) let { auth } = req.cookies if (auth) auth = JSON.parse(auth) -- cgit v1.2.3 From 4c6ad774cbb4be9a28af066c9667bd9765826a75 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Mon, 18 Sep 2023 11:08:27 +0700 Subject: migrasi category home page ke solr --- src/lib/home/api/categoryHomeApi.js | 7 ++++-- src/lib/home/components/CategoryHome.jsx | 10 ++++---- src/pages/api/shop/product-homepage.js | 43 ++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 src/pages/api/shop/product-homepage.js (limited to 'src') diff --git a/src/lib/home/api/categoryHomeApi.js b/src/lib/home/api/categoryHomeApi.js index 44b77daa..9e7d1402 100644 --- a/src/lib/home/api/categoryHomeApi.js +++ b/src/lib/home/api/categoryHomeApi.js @@ -1,8 +1,11 @@ import odooApi from '@/core/api/odooApi' +import axios from 'axios' const categoryHomeIdApi = async ({ id }) => { - const dataCategoryHomeId = await odooApi('GET', `/api/v1/product/category-homepage?id=${id}`) - return dataCategoryHomeId + // const dataCategoryHomeIdO = await odooApi('GET', `/api/v1/product/category-homepage?id=${id}`) + // console.log('ini adalah odoo', dataCategoryHomeIdO) + const dataCategoryHomeId = await axios(`${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/product-homepage?id=` + id) + return dataCategoryHomeId.data } export default categoryHomeIdApi diff --git a/src/lib/home/components/CategoryHome.jsx b/src/lib/home/components/CategoryHome.jsx index 34c28728..9e992640 100644 --- a/src/lib/home/components/CategoryHome.jsx +++ b/src/lib/home/components/CategoryHome.jsx @@ -7,14 +7,14 @@ const CategoryHome = ({ id }) => { return (
- {categoryHome?.data?.length > 0 ? ( + {categoryHome.data ? ( { + let product = await axios( + `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/product-detail?id=${id}` + ) + if (product && product.data.length > 0) { + products.push(product.data[0]) + } + }) + ) + let result = respoonseMap(productHomepage, products) + res.status(200).json(result) + } catch (error) { + console.error('Error fetching data from Solr:', error) + res.status(500).json({ error: 'Internal Server Error' }) + } +} + +const respoonseMap = (productHomepage, products) => { + let productMapped ={ + id: productHomepage.id, + sequence: productHomepage.sequence_i, + categoryId: productHomepage.category_id_i, + name: productHomepage.name_s, + image: productHomepage.image_s, + url: productHomepage.url_s, + products: products + } + + return productMapped +} -- cgit v1.2.3 From 54b3b9670995d62c2e11b761911430e4300fa36e Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Tue, 19 Sep 2023 17:08:55 +0700 Subject: popup cart --- .../components/elements/Navbar/NavbarDesktop.jsx | 8 +- src/lib/cart/components/Cartheader.jsx | 127 +++++++++++++++++++++ 2 files changed, 132 insertions(+), 3 deletions(-) create mode 100644 src/lib/cart/components/Cartheader.jsx (limited to 'src') diff --git a/src/core/components/elements/Navbar/NavbarDesktop.jsx b/src/core/components/elements/Navbar/NavbarDesktop.jsx index 2e4b25fc..2bee64f7 100644 --- a/src/core/components/elements/Navbar/NavbarDesktop.jsx +++ b/src/core/components/elements/Navbar/NavbarDesktop.jsx @@ -23,6 +23,7 @@ import { useSession } from 'next-auth/react' import { AuthContext } from '@/pages/_app' import { TopBannerSkeleton } from '../Skeleton/TopBannerSkeleton' import { useProductContext } from '@/contexts/ProductContext' +import Cardheader from '@/lib/cart/components/Cartheader' const Search = dynamic(() => import('./Search')) const TopBanner = dynamic(() => import('./TopBanner'), { @@ -101,7 +102,7 @@ const NavbarDesktop = () => {
-
+
{
Quotation - + {/* {
Belanja - + */} { + const [count, setCardCount] = useState(null) + const [products, setProducts] = useState(null) + + const getCart = async () => { + const listCart = await getCartApi() + setProducts(listCart.products) + } + + useEffect(() => { + getCart() + }, []) + + return ( +
+ +
0 && 'mr-2'}`}> + + {cartCount.cartCount > 0 && ( + + {cartCount.cartCount} + + )} +
+ + Keranjang +
+ Belanja +
+ + {/*
*/} +
+
+
+
Keranjang Belanja
+ + Lihat Semua + +
+
+
+
    + {products && + products?.map((product, index) => ( + <> +
  • +
    +
    + + {product?.name} + +
    +
    + + {' '} +

    + {product.parent.name} +

    + + + {product?.price?.discountPercentage > 0 && ( +
    +
    + {product?.price?.discountPercentage}% +
    +
    + {currencyFormat(product?.price?.price)} +
    +
    + )} +
    +
    + {currencyFormat(product?.price?.priceDiscount)} +
    +
    +
    +
    +
  • + + ))} +
+
+
+ {/*
+ + Buka Keranjang Belanja + +
*/} +
+
+
+ ) +} + +export default Cardheader -- cgit v1.2.3 From 4f285349adec93a040e41d1d8c0c1c7b57749397 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Thu, 21 Sep 2023 14:56:35 +0700 Subject: add context for list product popup cart --- src/contexts/ProductCartContext.js | 21 ++ .../components/elements/Navbar/NavbarDesktop.jsx | 10 +- src/lib/cart/components/Cartheader.jsx | 309 +++++++++++++++------ src/lib/product/api/productSimilarApi.js | 12 +- .../product/components/Product/ProductDesktop.jsx | 4 + src/pages/_app.jsx | 77 ++--- 6 files changed, 295 insertions(+), 138 deletions(-) create mode 100644 src/contexts/ProductCartContext.js (limited to 'src') diff --git a/src/contexts/ProductCartContext.js b/src/contexts/ProductCartContext.js new file mode 100644 index 00000000..06e97563 --- /dev/null +++ b/src/contexts/ProductCartContext.js @@ -0,0 +1,21 @@ +import { createContext, useCallback, useContext, useEffect, useState } from 'react' + +const ProductCartContext = createContext() + +export const ProductCartProvider = ({ children }) => { + const [productCart, setProductCart] = useState(null) + const [refreshCart, setRefreshCart] = useState(false) + const [isLoading, setIsloading] = useState(false) + + return ( + + {children} + + ) +} + +export const useProductCartContext = () => { + return useContext(ProductCartContext) +} diff --git a/src/core/components/elements/Navbar/NavbarDesktop.jsx b/src/core/components/elements/Navbar/NavbarDesktop.jsx index 2bee64f7..3aba55c9 100644 --- a/src/core/components/elements/Navbar/NavbarDesktop.jsx +++ b/src/core/components/elements/Navbar/NavbarDesktop.jsx @@ -10,17 +10,14 @@ import DesktopView from '../../views/DesktopView' import dynamic from 'next/dynamic' import IndoteknikLogo from '@/images/logo.png' import Category from '@/lib/category/components/Category' -import { useContext, useEffect, useState } from 'react' +import { useCallback, useContext, useEffect, useState } from 'react' import useAuth from '@/core/hooks/useAuth' import NavbarUserDropdown from './NavbarUserDropdown' -import { getCountCart } from '@/core/utils/cart' +import { getCartApi, getCountCart } from '@/core/utils/cart' import whatsappUrl from '@/core/utils/whatsappUrl' import { useRouter } from 'next/router' import { getAuth, setAuth } from '@/core/utils/auth' import { createSlug, getIdFromSlug } from '@/core/utils/slug' -import productApi from '@/lib/product/api/productApi' -import { useSession } from 'next-auth/react' -import { AuthContext } from '@/pages/_app' import { TopBannerSkeleton } from '../Skeleton/TopBannerSkeleton' import { useProductContext } from '@/contexts/ProductContext' import Cardheader from '@/lib/cart/components/Cartheader' @@ -32,7 +29,6 @@ const TopBanner = dynamic(() => import('./TopBanner'), { const NavbarDesktop = () => { const [isOpenCategory, setIsOpenCategory] = useState(false) - const { authenticated } = useContext(AuthContext) const auth = useAuth() const [cartCount, setCartCount] = useState(0) @@ -44,7 +40,7 @@ const NavbarDesktop = () => { const router = useRouter() const { product } = useProductContext() - + useEffect(() => { if (router.pathname === '/shop/product/[slug]') { setPayloadWa({ diff --git a/src/lib/cart/components/Cartheader.jsx b/src/lib/cart/components/Cartheader.jsx index 1760360d..3fc959d4 100644 --- a/src/lib/cart/components/Cartheader.jsx +++ b/src/lib/cart/components/Cartheader.jsx @@ -1,49 +1,128 @@ -import { useEffect, useState } from 'react' +import { useCallback, useEffect, useMemo, useState } from 'react' import { getCartApi } from '../api/CartApi' import currencyFormat from '@/core/utils/currencyFormat' import Image from '@/core/components/elements/Image/Image' import { createSlug } from '@/core/utils/slug' +import useAuth from '@/core/hooks/useAuth' +import { useRouter } from 'next/router' +import odooApi from '@/core/api/odooApi' +import { useProductCartContext } from '@/contexts/ProductCartContext' -const { ShoppingCartIcon } = require('@heroicons/react/24/outline') +const { ShoppingCartIcon, PhotoIcon } = require('@heroicons/react/24/outline') const { default: Link } = require('next/link') const Cardheader = (cartCount) => { - const [count, setCardCount] = useState(null) - const [products, setProducts] = useState(null) + const router = useRouter() + const [subTotal, setSubTotal] = useState(null) + const [buttonLoading, SetButtonTerapkan] = useState(false) + const itemLoading = [1, 2, 3] + const auth = useAuth() + const [countCart, setCountCart] = useState(null) + const { productCart, setRefreshCart, setProductCart, refreshCart, isLoading, setIsloading } = + useProductCartContext() - const getCart = async () => { - const listCart = await getCartApi() - setProducts(listCart.products) + const [isHovered, setIsHovered] = useState(false) + + const products = useMemo(() => { + return productCart?.products || [] + }, [productCart]) + + + const handleMouseEnter = () => { + setIsHovered(true) + getCart() + } + + const handleMouseLeave = () => { + setIsHovered(false) + } + + const getCart = () => { + if (!productCart && auth) { + refreshCartf() + } } + const refreshCartf = useCallback(async () => { + setIsloading(true) + let cart = await getCartApi() + setProductCart(cart) + setCountCart(cart.productTotal) + setIsloading(false) + }, [setProductCart]) useEffect(() => { - getCart() + if (!products) return + + let calculateTotalPriceBeforeTax = 0 + let calculateTotalTaxAmount = 0 + let calculateTotalDiscountAmount = 0 + for (const product of products) { + if (product.quantity == '') continue + + let priceBeforeTax = product.price.price / 1.11 + calculateTotalPriceBeforeTax += priceBeforeTax * product.quantity + calculateTotalTaxAmount += (product.price.price - priceBeforeTax) * product.quantity + calculateTotalDiscountAmount += + (product.price.price - product.price.priceDiscount) * product.quantity + } + let subTotal = + calculateTotalPriceBeforeTax - calculateTotalDiscountAmount + calculateTotalTaxAmount + setSubTotal(subTotal) + }, [products]) + + useEffect(() => { + if (refreshCart) { + refreshCartf() + } + setRefreshCart(false) + }, [refreshCart, refreshCartf, setRefreshCart]) + + useEffect(() => { + setCountCart(cartCount.cartCount) }, []) + const handleCheckout = async () => { + SetButtonTerapkan(true) + let checkoutAll = await odooApi('POST', `/api/v1/user/${auth.id}/cart/select-all`) + router.push('/shop/checkout') + } + return (
- + +
0 && 'mr-2'}`}> + + {countCart > 0 && ( + + {countCart} + + )} +
+ + Keranjang +
+ Belanja +
+ +
+
+
-
0 && 'mr-2'}`}> - - {cartCount.cartCount > 0 && ( - - {cartCount.cartCount} - - )} -
- - Keranjang -
- Belanja -
- - {/*
*/} -
Keranjang Belanja
@@ -53,71 +132,121 @@ const Cardheader = (cartCount) => {

-
    - {products && - products?.map((product, index) => ( - <> -
  • -
    -
    - - {product?.name} - -
    -
    - - {' '} -

    - {product.parent.name} -

    - - - {product?.price?.discountPercentage > 0 && ( -
    -
    - {product?.price?.discountPercentage}% -
    -
    - {currencyFormat(product?.price?.price)} -
    + {!auth && ( +
    +

    + Silahkan{' '} + + Login + {' '} + Untuk Melihat Daftar Keranjang Belanja Anda +

    +
    + )} + {isLoading && + itemLoading.map((item) => ( +
    +
    +
    + +
    +
    +
    +
    +
    +
    +
    +
    + ))} + {products.length === 0 && !isLoading && ( +
    +

    + Tidak Ada Produk di Keranjang Belanja Anda +

    +
    + )} + {products.length > 0 && !isLoading && ( + <> +
      + {products && + products?.map((product, index) => ( + <> +
    • +
      +
      + + {product?.name} +
      - )} -
      -
      - {currencyFormat(product?.price?.priceDiscount)} +
      + + {' '} +

      + {product.parent.name} +

      + + + {product?.price?.discountPercentage > 0 && ( +
      +
      + {product?.price?.discountPercentage}% +
      +
      + {currencyFormat(product?.price?.price)} +
      +
      + )} +
      +
      + {currencyFormat(product?.price?.priceDiscount)} +
      +
      -
      -
      -
    • - - ))} -
    -
    +
  • + + ))} +
+
+ + )}
- {/*
- - Buka Keranjang Belanja - -
*/} + {products.length > 0 && !isLoading && ( + <> +
+ Sub Total Sebelum PPN : + Rp. {currencyFormat(subTotal)} +
+
+ +
+ + )}
diff --git a/src/lib/product/api/productSimilarApi.js b/src/lib/product/api/productSimilarApi.js index c1bccd59..a008ce5d 100644 --- a/src/lib/product/api/productSimilarApi.js +++ b/src/lib/product/api/productSimilarApi.js @@ -21,10 +21,14 @@ const productSimilarApi = async ({ query, source }) => { const dataProductSimilar = await axios( `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/search?q=${query}&page=1&orderBy=popular-weekly&operation=OR` ) - dataProductSimilar.data.response.products = [ - ...dataflashSale, - ...dataProductSimilar.data.response.products, - ]; + if (dataflashSale) { + dataProductSimilar.data.response.products = [ + ...dataflashSale, + ...dataProductSimilar.data.response.products + ] + } else { + dataProductSimilar.data.response.products = [...dataProductSimilar.data.response.products] + } return dataProductSimilar.data.response } diff --git a/src/lib/product/components/Product/ProductDesktop.jsx b/src/lib/product/components/Product/ProductDesktop.jsx index 937f2746..6da289bc 100644 --- a/src/lib/product/components/Product/ProductDesktop.jsx +++ b/src/lib/product/components/Product/ProductDesktop.jsx @@ -22,6 +22,7 @@ import ImageNext from 'next/image' import CountDown2 from '@/core/components/elements/CountDown/CountDown2' import { LazyLoadComponent } from 'react-lazy-load-image-component' import ColumnsSLA from './ColumnsSLA' +import { useProductCartContext } from '@/contexts/ProductCartContext' const ProductDesktop = ({ products, wishlist, toggleWishlist }) => { const router = useRouter() @@ -39,6 +40,8 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => { const [selectVariantPromoActive, setSelectVariantPromoActive] = useState(null) const [backgorundFlashSale, setBackgorundFlashSale] = useState(null) + const {setRefreshCart , refreshCart} = useProductCartContext() + const getLowestPrice = useCallback(() => { const prices = product.variants.map((variant) => variant.price) const lowest = prices.reduce((lowest, price) => { @@ -116,6 +119,7 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => { let source = 'cart' updateCart(variantId, quantity, source) + setRefreshCart(true) setAddCartAlert(true) } diff --git a/src/pages/_app.jsx b/src/pages/_app.jsx index ef737794..0062f7fc 100644 --- a/src/pages/_app.jsx +++ b/src/pages/_app.jsx @@ -11,12 +11,13 @@ import LogoSpinner from '@/core/components/elements/Spinner/LogoSpinner' import { SessionProvider } from 'next-auth/react' import { getAuth } from '@/core/utils/auth' import { ProductProvider } from '@/contexts/ProductContext' +import { ProductCartProvider } from '@/contexts/ProductCartContext' const queryClient = new QueryClient() export const AuthContext = createContext({ - authenticated : false, - setAuthenticated : (auth) => {} + authenticated: false, + setAuthenticated: (auth) => {} }) function MyApp({ Component, pageProps: { session, ...pageProps } }) { @@ -63,43 +64,45 @@ function MyApp({ Component, pageProps: { session, ...pageProps } }) { return ( // - - - {animateLoader && ( - - - - )} - - - - - window.scrollTo(0, 0)} + + + {animateLoader && ( + - + + + )} + + + + + window.scrollTo(0, 0)} + > + + {!animateLoader && } - - - - + + + + + // ) } -- cgit v1.2.3 From bda91439b6ef4605a579bde8bef603b551aab3dd Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Fri, 22 Sep 2023 09:08:13 +0700 Subject: cart call for price --- src/lib/cart/components/Cart.jsx | 4 ++++ src/lib/cart/components/Cartheader.jsx | 28 +++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/lib/cart/components/Cart.jsx b/src/lib/cart/components/Cart.jsx index efbcf76b..b5976a1b 100644 --- a/src/lib/cart/components/Cart.jsx +++ b/src/lib/cart/components/Cart.jsx @@ -22,6 +22,7 @@ import LogoSpinner from '@/core/components/elements/Spinner/LogoSpinner' import { getPromotionProgram } from '@/lib/promotinProgram/api/homepageApi' import PromotionType from '@/lib/promotinProgram/components/PromotionType' import { gtagBeginCheckout } from '@/core/utils/googleTag' +import { useProductCartContext } from '@/contexts/ProductCartContext' const Cart = () => { const router = useRouter() @@ -31,6 +32,8 @@ const Cart = () => { const [cart, setCart] = useState(null) + const {setRefreshCart} = useProductCartContext() + useEffect(() => { if (!auth) return }, [auth]) @@ -196,6 +199,7 @@ const Cart = () => { deleteItemCart({ productId }) setDeleteConfirmation(null) setProducts([...productsToUpdate]) + setRefreshCart(true) toast.success('Berhasil menghapus barang dari keranjang') } diff --git a/src/lib/cart/components/Cartheader.jsx b/src/lib/cart/components/Cartheader.jsx index 3fc959d4..dd6c276e 100644 --- a/src/lib/cart/components/Cartheader.jsx +++ b/src/lib/cart/components/Cartheader.jsx @@ -7,6 +7,7 @@ import useAuth from '@/core/hooks/useAuth' import { useRouter } from 'next/router' import odooApi from '@/core/api/odooApi' import { useProductCartContext } from '@/contexts/ProductCartContext' +import whatsappUrl from '@/core/utils/whatsappUrl' const { ShoppingCartIcon, PhotoIcon } = require('@heroicons/react/24/outline') const { default: Link } = require('next/link') @@ -27,7 +28,6 @@ const Cardheader = (cartCount) => { return productCart?.products || [] }, [productCart]) - const handleMouseEnter = () => { setIsHovered(true) getCart() @@ -79,7 +79,7 @@ const Cardheader = (cartCount) => { useEffect(() => { setCountCart(cartCount.cartCount) - }, []) + }, [cartCount]) const handleCheckout = async () => { SetButtonTerapkan(true) @@ -216,7 +216,29 @@ const Cardheader = (cartCount) => { )}
- {currencyFormat(product?.price?.priceDiscount)} + {product?.price?.priceDiscount > 0 ? ( + currencyFormat(product?.price?.priceDiscount) + ) : ( + + + Call For Price + + + )}
-- cgit v1.2.3