summaryrefslogtreecommitdiff
path: root/src-migrate/modules/product-detail/components
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-06-21 11:01:35 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-06-21 11:01:35 +0700
commit220190db66bcc1c6db78180c593f21e9cf8f363c (patch)
tree1517faa9636a6b3b2cc8d468a57b1fe476c229d7 /src-migrate/modules/product-detail/components
parent208b234320b6c42491a4e87a1c3db3abab9c1715 (diff)
parent1cf754b4d8da1aa28700ffc3dad67081f6daf9a5 (diff)
Merge branch 'promotion-program' into feature/all-promotion
Diffstat (limited to 'src-migrate/modules/product-detail/components')
-rw-r--r--src-migrate/modules/product-detail/components/AddToCart.tsx25
-rw-r--r--src-migrate/modules/product-detail/components/Image.tsx53
-rw-r--r--src-migrate/modules/product-detail/components/PriceAction.tsx10
-rw-r--r--src-migrate/modules/product-detail/components/ProductDetail.tsx34
4 files changed, 81 insertions, 41 deletions
diff --git a/src-migrate/modules/product-detail/components/AddToCart.tsx b/src-migrate/modules/product-detail/components/AddToCart.tsx
index 4accab17..097db98a 100644
--- a/src-migrate/modules/product-detail/components/AddToCart.tsx
+++ b/src-migrate/modules/product-detail/components/AddToCart.tsx
@@ -1,8 +1,7 @@
-import React from 'react'
import { Button, useToast } from '@chakra-ui/react'
-import { getAuth } from '~/libs/auth'
import { useRouter } from 'next/router'
-import Link from 'next/link'
+
+import { getAuth } from '~/libs/auth'
import { upsertUserCart } from '~/services/cart'
type Props = {
@@ -26,15 +25,7 @@ const AddToCart = ({
const handleClick = async () => {
if (typeof auth !== 'object') {
const currentUrl = encodeURIComponent(router.asPath)
- toast({
- title: 'Masuk Akun',
- description: <>
- Masuk akun untuk dapat menambahkan barang ke keranjang belanja. {' '}
- <Link className='underline' href={`/login?next=${currentUrl}`}>Klik disini</Link>
- </>,
- status: 'error',
- duration: 4000,
- })
+ router.push(`/login?next=${currentUrl}`)
return;
}
@@ -45,7 +36,15 @@ const AddToCart = ({
) return;
toast.promise(
- upsertUserCart(auth.id, 'product', variantId, quantity, true, source),
+ 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' },
diff --git a/src-migrate/modules/product-detail/components/Image.tsx b/src-migrate/modules/product-detail/components/Image.tsx
index b69cc87f..30ca0d34 100644
--- a/src-migrate/modules/product-detail/components/Image.tsx
+++ b/src-migrate/modules/product-detail/components/Image.tsx
@@ -1,5 +1,5 @@
import style from '../styles/image.module.css';
-
+import ImageNext from 'next/image';
import React, { useEffect, useMemo, useState } from 'react'
import { InfoIcon } from 'lucide-react'
import { Tooltip } from '@chakra-ui/react'
@@ -14,9 +14,10 @@ type Props = {
const Image = ({ product }: Props) => {
const flashSale = product.flash_sale
-
const [count, setCount] = useState(flashSale?.remaining_time || 0);
+
+
useEffect(() => {
let interval: NodeJS.Timeout;
@@ -42,15 +43,43 @@ const Image = ({ product }: Props) => {
return (
<div className={style['wrapper']}>
- <ImageUI
- src={image}
- alt={product.name}
- width={256}
- height={256}
- className={style['image']}
- loading='eager'
- priority
- />
+ {/* <div className="relative"> */}
+ <ImageUI
+ src={image}
+ alt={product.name}
+ width={256}
+ height={256}
+ className={style['image']}
+ loading='eager'
+ priority
+ />
+ <div className="absolute top-4 right-10 flex ">
+ <div className="gambarB ">
+ {product.isSni && (
+ <ImageNext
+ src="/images/sni-logo.png"
+ alt="SNI Logo"
+ className="w-12 h-8 object-contain object-top sm:h-6"
+ width={50}
+ height={50}
+ />
+ )}
+ </div>
+ <div className="gambarC ">
+ {product.isTkdn && (
+ <ImageNext
+ src="/images/TKDN.png"
+ alt="TKDN"
+ className="w-16 h-8 object-contain object-top ml-1 mr-1 sm:h-6"
+ width={50}
+ height={50}
+ />
+ )}
+ </div>
+ </div>
+ {/* </div> */}
+
+
<div className={style['absolute-info']}>
<Tooltip
@@ -67,7 +96,7 @@ const Image = ({ product }: Props) => {
<div className='absolute bottom-0 w-full h-14'>
<div className="relative w-full h-full">
<ImageUI
- src='/images/GAMBAR-BG-FLASH-SALE.jpg'
+ src='/images/BG-FLASH-SALE.jpg'
alt='Flash Sale Indoteknik'
width={200}
height={100}
diff --git a/src-migrate/modules/product-detail/components/PriceAction.tsx b/src-migrate/modules/product-detail/components/PriceAction.tsx
index f25847a5..ad04de43 100644
--- a/src-migrate/modules/product-detail/components/PriceAction.tsx
+++ b/src-migrate/modules/product-detail/components/PriceAction.tsx
@@ -23,6 +23,16 @@ const PriceAction = ({ product }: Props) => {
useEffect(() => {
setActive(product.variants[0])
+ if(product.variants.length > 2 && product.variants[0].price.price === 0){
+ const variants = product.variants
+ for (let i = 0; i < variants.length; i++) {
+ if(variants[i].price.price > 0){
+ setActive(variants[i])
+ break;
+ }
+ }
+ }
+
}, [product, setActive]);
return (
diff --git a/src-migrate/modules/product-detail/components/ProductDetail.tsx b/src-migrate/modules/product-detail/components/ProductDetail.tsx
index 2bd3c901..bfdf5b43 100644
--- a/src-migrate/modules/product-detail/components/ProductDetail.tsx
+++ b/src-migrate/modules/product-detail/components/ProductDetail.tsx
@@ -1,29 +1,29 @@
import style from '../styles/product-detail.module.css'
-import React, { useEffect } from 'react'
import Link from 'next/link'
import { useRouter } from 'next/router'
+import { useEffect } from 'react'
-import { MessageCircleIcon, Share2Icon } from 'lucide-react'
import { Button } from '@chakra-ui/react'
+import { MessageCircleIcon, Share2Icon } from 'lucide-react'
+import { LazyLoadComponent } from 'react-lazy-load-image-component'
+import { RWebShare } from 'react-web-share'
-import { IProductDetail } from '~/types/product'
import useDevice from '@/core/hooks/useDevice'
import { whatsappUrl } from '~/libs/whatsappUrl'
-
+import ProductPromoSection from '~/modules/product-promo/components/Section'
+import { IProductDetail } from '~/types/product'
import { useProductDetail } from '../stores/useProductDetail'
-
-import { RWebShare } from 'react-web-share'
+import AddToWishlist from './AddToWishlist'
+import Breadcrumb from './Breadcrumb'
import ProductImage from './Image'
import Information from './Information'
-import AddToWishlist from './AddToWishlist'
-import VariantList from './VariantList'
-import SimilarSide from './SimilarSide'
-import SimilarBottom from './SimilarBottom'
import PriceAction from './PriceAction'
-import ProductPromoSection from '~/modules/product-promo/components/Section'
-import Breadcrumb from './Breadcrumb'
-import { LazyLoadComponent } from 'react-lazy-load-image-component'
+import SimilarBottom from './SimilarBottom'
+import SimilarSide from './SimilarSide'
+import VariantList from './VariantList'
+
+import { gtagProductDetail } from '@/core/utils/googleTag'
type Props = {
product: IProductDetail
@@ -37,6 +37,10 @@ const ProductDetail = ({ product }: Props) => {
const { setAskAdminUrl, askAdminUrl, activeVariantId } = useProductDetail()
useEffect(() => {
+ gtagProductDetail(product);
+ },[product])
+
+ useEffect(() => {
const createdAskUrl = whatsappUrl({
template: 'product',
payload: {
@@ -117,9 +121,7 @@ const ProductDetail = ({ product }: Props) => {
)}
<div className='h-4 md:h-10' />
- {!!activeVariantId && (
- <ProductPromoSection productId={activeVariantId} />
- )}
+ {!!activeVariantId && <ProductPromoSection productId={activeVariantId} />}
<div className={style['section-card']}>
<h2 className={style['heading']}>