fix bug cart
This commit is contained in:
@@ -9,6 +9,7 @@ import MobileBottomMenu from "@/components/MobileBottomMenu";
|
|||||||
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
|
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
|
||||||
import { viewport } from './viewport'
|
import { viewport } from './viewport'
|
||||||
import { SHOP_CONFIG } from "@/config/const";
|
import { SHOP_CONFIG } from "@/config/const";
|
||||||
|
import ManageData from "@/components/ManageData";
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
title: `${SHOP_CONFIG.fullName} | ${SHOP_CONFIG.englishName}`,
|
title: `${SHOP_CONFIG.fullName} | ${SHOP_CONFIG.englishName}`,
|
||||||
@@ -33,6 +34,7 @@ export default function RootLayout({
|
|||||||
<ToastContainer />
|
<ToastContainer />
|
||||||
<MobileBottomMenu />
|
<MobileBottomMenu />
|
||||||
<ReactQueryDevtools initialIsOpen={false} />
|
<ReactQueryDevtools initialIsOpen={false} />
|
||||||
|
<ManageData />
|
||||||
</QueryProvider>
|
</QueryProvider>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -41,7 +41,13 @@ const OnlineCart: React.FC<OnlineCartProps> = ({ variantId }) => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Check API cart for logged in users
|
// Check API cart for logged in users
|
||||||
|
console.log('cart', cart);
|
||||||
|
console.log('variantId', variantId);
|
||||||
|
|
||||||
const item = cart?.results?.cart?.items?.find(item => item.variant?._id === variantId)
|
const item = cart?.results?.cart?.items?.find(item => item.variant?._id === variantId)
|
||||||
|
|
||||||
|
console.log('item', item);
|
||||||
|
|
||||||
if (item) {
|
if (item) {
|
||||||
setIsInCart(true)
|
setIsInCart(true)
|
||||||
setQuantity(item.quantity)
|
setQuantity(item.quantity)
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import { Button } from '@/components/ui/button'
|
|
||||||
import { Separator } from '@/components/ui/separator'
|
import { Separator } from '@/components/ui/separator'
|
||||||
import { BoxTick, I3DRotate, Messages1 } from 'iconsax-react'
|
import { BoxTick, I3DRotate } from 'iconsax-react'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { Product } from '@/types/product.types'
|
import { Product } from '@/types/product.types'
|
||||||
import Image from 'next/image'
|
import Image from 'next/image'
|
||||||
import Cart from './Cart'
|
import Cart from './Cart'
|
||||||
import { PRIMARY_COLOR } from '@/config/const'
|
import { PRIMARY_COLOR } from '@/config/const'
|
||||||
import { useRouter } from 'next/navigation'
|
|
||||||
import { useProductStore } from '../store/Store'
|
import { useProductStore } from '../store/Store'
|
||||||
|
|
||||||
interface ShopInformationProps {
|
interface ShopInformationProps {
|
||||||
@@ -15,7 +13,6 @@ interface ShopInformationProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const ShopInformation = ({ product }: ShopInformationProps) => {
|
const ShopInformation = ({ product }: ShopInformationProps) => {
|
||||||
const router = useRouter()
|
|
||||||
const { variantId } = useProductStore()
|
const { variantId } = useProductStore()
|
||||||
|
|
||||||
// پیدا کردن variant انتخابی یا استفاده از default_variant
|
// پیدا کردن variant انتخابی یا استفاده از default_variant
|
||||||
@@ -35,10 +32,10 @@ const ShopInformation = ({ product }: ShopInformationProps) => {
|
|||||||
const discountPercent = price.discount_percent
|
const discountPercent = price.discount_percent
|
||||||
const hasDiscount = discountPercent > 0
|
const hasDiscount = discountPercent > 0
|
||||||
|
|
||||||
const handleChatWithSeller = () => {
|
// const handleChatWithSeller = () => {
|
||||||
// Navigate to chat page with product and shop context
|
// // Navigate to chat page with product and shop context
|
||||||
router.push(`/profile/chat?productId=${product._id}&shopId=${shop.owner}`)
|
// router.push(`/profile/chat?productId=${product._id}&shopId=${shop.owner}`)
|
||||||
}
|
// }
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='w-full xl:w-[325px] bg-[#FAFAFA] rounded-[10px] p-4 sm:p-6 lg:p-7 border border-border h-fit xl:sticky xl:top-[170px] xl:self-start'>
|
<div className='w-full xl:w-[325px] bg-[#FAFAFA] rounded-[10px] p-4 sm:p-6 lg:p-7 border border-border h-fit xl:sticky xl:top-[170px] xl:self-start'>
|
||||||
@@ -111,13 +108,13 @@ const ShopInformation = ({ product }: ShopInformationProps) => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Cart />
|
<Cart />
|
||||||
<Button
|
{/* <Button
|
||||||
onClick={handleChatWithSeller}
|
onClick={handleChatWithSeller}
|
||||||
className='w-full mt-3 bg-[#323232] hover:bg-[#424242] flex items-center justify-center gap-2'
|
className='w-full mt-3 bg-[#323232] hover:bg-[#424242] flex items-center justify-center gap-2'
|
||||||
>
|
>
|
||||||
<Messages1 size={18} />
|
<Messages1 size={18} />
|
||||||
گفتگو با فروشنده
|
گفتگو با فروشنده
|
||||||
</Button>
|
</Button> */}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { useProductStore } from "@/app/product/store/Store";
|
||||||
|
import { usePathname } from "next/navigation";
|
||||||
|
import { useEffect } from "react";
|
||||||
|
|
||||||
|
const ManageData = () => {
|
||||||
|
|
||||||
|
const { setVariantId } = useProductStore()
|
||||||
|
const pathname = usePathname()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setVariantId('')
|
||||||
|
}, [pathname]);
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ManageData
|
||||||
Reference in New Issue
Block a user