diff options
| author | HATEC\SPVDEV001 <tri.susilo@altama.co.id> | 2023-10-16 11:28:34 +0700 |
|---|---|---|
| committer | HATEC\SPVDEV001 <tri.susilo@altama.co.id> | 2023-10-16 11:28:34 +0700 |
| commit | 954be13467b02889414db600fee8e8b7b76cc2aa (patch) | |
| tree | 4331a21338b2ac33b6f7a2911e61365b8950c33c /src/lib/product/components/Product/ProductMobile.jsx | |
| parent | ca445ab4e089b98fb67b004a6cb4a8968f471ae4 (diff) | |
| parent | 6aa5fa70cf5ccd2825e5657ec1a90e370dea3bcf (diff) | |
Merge branch 'CR/UI' of https://bitbucket.org/altafixco/next-indoteknik into CR/UI
Diffstat (limited to 'src/lib/product/components/Product/ProductMobile.jsx')
| -rw-r--r-- | src/lib/product/components/Product/ProductMobile.jsx | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/lib/product/components/Product/ProductMobile.jsx b/src/lib/product/components/Product/ProductMobile.jsx index 402490f7..70ac1cbc 100644 --- a/src/lib/product/components/Product/ProductMobile.jsx +++ b/src/lib/product/components/Product/ProductMobile.jsx @@ -20,9 +20,12 @@ import odooApi from '@/core/api/odooApi' import ImageNext from 'next/image' import CountDown2 from '@/core/components/elements/CountDown/CountDown2' import Breadcrumb from './Breadcrumb' +import useAuth from '@/core/hooks/useAuth' const ProductMobile = ({ product, wishlist, toggleWishlist }) => { const router = useRouter() + const auth = useAuth() + const { slug } = router.query const [quantity, setQuantity] = useState('1') const [selectedVariant, setSelectedVariant] = useState(null) @@ -128,9 +131,20 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => { return isValid } + const redirectToLogin = (action) => { + const nextURL = `/shop/product/${slug}?action=${action}&variantId=${activeVariant.id}&qty=${quantity}` + router.push(`/login?next=${encodeURIComponent(nextURL)}`) + return true + } + const handleClickCart = () => { if (!validAction()) return gtagAddToCart(activeVariant, quantity) + + if (!auth) { + return redirectToLogin('add_to_cart') + } + updateItemCart({ productId: activeVariant.id, quantity, @@ -143,6 +157,10 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => { const handleClickBuy = () => { if (!validAction()) return + if (!auth) { + return redirectToLogin('buy') + } + updateItemCart({ productId: activeVariant.id, quantity, |
