summaryrefslogtreecommitdiff
path: root/src/lib/product/components/Product
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/product/components/Product')
-rw-r--r--src/lib/product/components/Product/ProductDesktopVariant.jsx86
-rw-r--r--src/lib/product/components/Product/ProductMobileVariant.jsx71
2 files changed, 28 insertions, 129 deletions
diff --git a/src/lib/product/components/Product/ProductDesktopVariant.jsx b/src/lib/product/components/Product/ProductDesktopVariant.jsx
index c8a5a205..09b30a44 100644
--- a/src/lib/product/components/Product/ProductDesktopVariant.jsx
+++ b/src/lib/product/components/Product/ProductDesktopVariant.jsx
@@ -6,11 +6,6 @@ import { useRouter } from 'next/router';
import { useCallback, useEffect, useRef, useState } from 'react';
import { toast } from 'react-hot-toast';
import LazyLoad from 'react-lazy-load';
-import { Button } from '@chakra-ui/react'
-import { MessageCircleIcon, Share2Icon } from 'lucide-react'
-import AddToWishlist from '../../../../../src-migrate/modules/product-detail/components/AddToWishlist'
-import { RWebShare } from 'react-web-share'
-// import Link from 'next/link'
import { useProductCartContext } from '@/contexts/ProductCartContext';
import odooApi from '@/core/api/odooApi';
@@ -23,14 +18,11 @@ import { updateItemCart } from '@/core/utils/cart';
import currencyFormat from '@/core/utils/currencyFormat';
import { createSlug } from '@/core/utils/slug';
import whatsappUrl from '@/core/utils/whatsappUrl';
-import Breadcrumb from '../../../../../src-migrate/modules/product-detail/components/Breadcrumb';
import productSimilarApi from '../../api/productSimilarApi';
import ProductCard from '../ProductCard';
import ProductSimilar from '../ProductSimilar';
-const SELF_HOST = process.env.NEXT_PUBLIC_SELF_HOST
-
const ProductDesktopVariant = ({
product,
wishlist,
@@ -40,7 +32,7 @@ const ProductDesktopVariant = ({
const router = useRouter();
const auth = useAuth();
const { slug } = router.query;
- const [ askAdminUrl, setAskAdminUrl ] = useState()
+
const [lowestPrice, setLowestPrice] = useState(null);
const [addCartAlert, setAddCartAlert] = useState(false);
@@ -61,20 +53,6 @@ const ProductDesktopVariant = ({
setLowestPrice(lowest);
}, [getLowestPrice]);
- useEffect(() => {
- const createdAskUrl = whatsappUrl({
- template: 'product',
- payload: {
- manufacture: product.manufacture.name,
- productName: product.name,
- url: process.env.NEXT_PUBLIC_SELF_HOST + router.asPath
- },
- fallbackUrl: router.asPath
- })
-
- setAskAdminUrl(createdAskUrl)
- }, [router.asPath, product.manufacture.name, product.name, setAskAdminUrl])
-
const [informationTab, setInformationTab] = useState(
informationTabOptions[0].value
);
@@ -137,25 +115,20 @@ const ProductDesktopVariant = ({
});
}
};
- const regex = /\b(?![A-Z\s]+\b)[A-Za-z\s]+\b/g;
- const matches = product?.parent?.name?.match(regex);
- const extractedName = matches ? matches.join(' ').trim() : '';
- console.log("extractedName",extractedName)
const productSimilarQuery = [
product?.name,
`fq=-product_id_i:${product.id}`,
`fq=-manufacture_id_i:${product.manufacture?.id || 0}`,
].join('&');
-
+
const [productSimilarInBrand, setProductSimilarInBrand] = useState(null);
-
+
useEffect(() => {
const loadProductSimilarInBrand = async () => {
const productSimilarQuery = [
product?.name,
`fq=-product_id_i:${product.id}`,
- `fq=display_name_s:${extractedName}`,
].join('&');
const dataProductSimilar = await productSimilarApi({
query: productSimilarQuery,
@@ -181,7 +154,6 @@ const ProductDesktopVariant = ({
return (
<DesktopView>
<div className='container mx-auto pt-10'>
- <Breadcrumb id={product.id} name={product.parent.name} />
<div className='flex'>
<div className='w-full flex flex-wrap'>
<div className='w-5/12'>
@@ -291,42 +263,9 @@ const ProductDesktopVariant = ({
</div>
</div>
</div>
- <div className='h-6' />
- <div className="flex gap-x-5">
- <Button
- as={Link}
- href={askAdminUrl}
- variant='link'
- target='_blank'
- colorScheme='gray'
- leftIcon={<MessageCircleIcon size={18} />}
- >
- Ask Admin
- </Button>
-
- <AddToWishlist productId={product.id} />
-
- <RWebShare
- data={{
- text: 'Check out this product',
- title: `${product.name} - Indoteknik.com`,
- url: SELF_HOST + router.asPath
- }}
- >
- <Button
- variant='link'
- colorScheme='gray'
- leftIcon={<Share2Icon size={18} />}
- >
- Share
- </Button>
- </RWebShare>
- </div>
</div>
-
-
- <div className='p-4 md:p-6 md:bg-gray-50 rounded-xl w-[99%]'>
+ <div className='p-4 md:p-6 md:bg-gray-50 rounded-xl'>
<h2 className='text-h-md md:text-h-lg font-medium'>Informasi Produk</h2>
<div className='h-4' />
<div
@@ -340,7 +279,7 @@ const ProductDesktopVariant = ({
/>
</div>
</div>
- <div className='w-[35%]'>
+ <div className='w-[25%]'>
{product?.isFlashsale > 0 &&
product?.price?.discountPercentage > 0 ? (
<>
@@ -420,11 +359,24 @@ const ProductDesktopVariant = ({
Beli
</button>
</div>
+ <div className='flex mt-4'>
+ <button
+ className='flex items-center gap-x-1'
+ onClick={toggleWishlist}
+ >
+ {wishlist.data?.productTotal > 0 ? (
+ <HeartIcon className='w-6 fill-danger-500 text-danger-500' />
+ ) : (
+ <HeartIcon className='w-6' />
+ )}
+ Wishlist
+ </button>
+ </div>
<div className='border border-gray_r-6 overflow-auto mt-4'>
<div className='font-medium text-center p-4 bg-gray_r-1 border-b border-gray_r-6 sticky top-0 z-10'>
Produk Serupa
</div>
- <div className='h-full divide-y divide-gray_r-6 max-h-[500px]'>
+ <div className='h-full divide-y divide-gray_r-6 max-h-96'>
{productSimilarInBrand &&
productSimilarInBrand?.map((product) => (
<div className='py-2' key={product.id}>
diff --git a/src/lib/product/components/Product/ProductMobileVariant.jsx b/src/lib/product/components/Product/ProductMobileVariant.jsx
index ce836d5b..af9e52bb 100644
--- a/src/lib/product/components/Product/ProductMobileVariant.jsx
+++ b/src/lib/product/components/Product/ProductMobileVariant.jsx
@@ -16,14 +16,8 @@ import currencyFormat from '@/core/utils/currencyFormat';
import { gtagAddToCart } from '@/core/utils/googleTag';
import { createSlug } from '@/core/utils/slug';
import whatsappUrl from '@/core/utils/whatsappUrl';
-import Breadcrumb from '../../../../../src-migrate/modules/product-detail/components/Breadcrumb';
-import { Button } from '@chakra-ui/react'
-import { MessageCircleIcon, Share2Icon } from 'lucide-react'
-import AddToWishlist from '../../../../../src-migrate/modules/product-detail/components/AddToWishlist'
-import { RWebShare } from 'react-web-share'
-import ProductSimilar from '../ProductSimilar';
-const SELF_HOST = process.env.NEXT_PUBLIC_SELF_HOST
+import ProductSimilar from '../ProductSimilar';
const ProductMobileVariant = ({ product, wishlist, toggleWishlist }) => {
const router = useRouter();
@@ -34,7 +28,7 @@ const ProductMobileVariant = ({ product, wishlist, toggleWishlist }) => {
informationTabOptions[0].value
);
const [addCartAlert, setAddCartAlert] = useState(false);
- const [ askAdminUrl, setAskAdminUrl ] = useState()
+
const [isLoadingSLA, setIsLoadingSLA] = useState(true);
const getLowestPrice = () => {
@@ -66,20 +60,6 @@ const ProductMobileVariant = ({ product, wishlist, toggleWishlist }) => {
}
}, [selectedVariant, product]);
- useEffect(() => {
- const createdAskUrl = whatsappUrl({
- template: 'product',
- payload: {
- manufacture: product.manufacture.name,
- productName: product.name,
- url: process.env.NEXT_PUBLIC_SELF_HOST + router.asPath
- },
- fallbackUrl: router.asPath
- })
-
- setAskAdminUrl(createdAskUrl)
- }, [router.asPath, product.manufacture.name, product.name, setAskAdminUrl])
-
const validAction = () => {
let isValid = true;
if (!selectedVariant) {
@@ -140,17 +120,14 @@ const ProductMobileVariant = ({ product, wishlist, toggleWishlist }) => {
return (
<MobileView>
- <div className='p-4'>
- <Breadcrumb id={product.id} name={product.name} />
- </div>
<Image
src={product.image + '?variant=True'}
alt={product.name}
- className='h-72 object-contain mt-4 object-center w-full border-b border-gray_r-4'
+ className='h-72 object-contain object-center w-full border-b border-gray_r-4'
/>
<div className='p-4'>
- <div className='flex items-center mb-2'>
+ <div className='flex items-end mb-2'>
{product.manufacture?.name ? (
<Link
href={createSlug(
@@ -164,45 +141,15 @@ const ProductMobileVariant = ({ product, wishlist, toggleWishlist }) => {
) : (
<div>-</div>
)}
- <div className="ml-2 flex gap-x-5">
- <Button
- as={Link}
- href={askAdminUrl}
- variant='link'
- target='_blank'
- colorScheme='gray'
- leftIcon={<MessageCircleIcon size={18} />}
- >
- Ask Admin
- </Button>
-
- <AddToWishlist productId={product.id} />
-
- <RWebShare
- data={{
- text: 'Check out this product',
- title: `${product.name} - Indoteknik.com`,
- url: SELF_HOST + router.asPath
- }}
- >
- <Button
- variant='link'
- colorScheme='gray'
- leftIcon={<Share2Icon size={18} />}
- >
- Share
- </Button>
- </RWebShare>
- </div>
- {/* <button type='button' className='ml-auto' onClick={toggleWishlist}>
+ <button type='button' className='ml-auto' onClick={toggleWishlist}>
{wishlist.data?.productTotal > 0 ? (
<HeartIcon className='w-6 fill-danger-500 text-danger-500' />
) : (
<HeartIcon className='w-6' />
)}
- </button> */}
+ </button>
</div>
- <h1 className='font-medium text-h-lg leading-8 md:text-title-md md:leading-10 mb-3'>{activeVariant?.name}</h1>
+ <h1 className='leading-6 font-medium mb-3'>{activeVariant?.name}</h1>
{activeVariant.isFlashSale &&
activeVariant?.price?.discountPercentage > 0 ? (
@@ -226,11 +173,11 @@ const ProductMobileVariant = ({ product, wishlist, toggleWishlist }) => {
</div>
</>
) : (
- <h3 className='font-medium text-danger-500 text-title-md mt-1'>
+ <h3 className='text-danger-500 font-semibold mt-1'>
{activeVariant?.price?.price > 0 ? (
<>
{currencyFormat(activeVariant?.price?.price)}
- <div className='text-gray_r-9 text-base font-medium mt-1'>
+ <div className='text-gray_r-9 text-base font-normal mt-1'>
Termasuk PPN:{' '}
{currencyFormat(
activeVariant?.price.price * process.env.NEXT_PUBLIC_PPN