diff --git a/src/app/globals.css b/src/app/globals.css index 59eea06..206609a 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -168,6 +168,9 @@ body {} opacity: 1; } +.mySwiper4 .swiper-slide-thumb-active { + opacity: 1; +} .swiper-slide img { display: block; width: 100%; diff --git a/src/app/products/[id]/page.tsx b/src/app/products/[id]/page.tsx index 97cfa6a..1c2a2d6 100644 --- a/src/app/products/[id]/page.tsx +++ b/src/app/products/[id]/page.tsx @@ -1,28 +1,22 @@ -// BuyerProductView 'use client'; import React, { useState } from 'react'; import { Swiper, SwiperSlide } from 'swiper/react'; import 'swiper/css'; import 'swiper/css/free-mode'; +import 'swiper/css/zoom'; import 'swiper/css/navigation'; import 'swiper/css/thumbs'; import { FreeMode, Navigation, Thumbs } from 'swiper/modules'; -import Image from 'next/image'; //@ts-ignore +// @ts-ignore import ReactStars from 'react-rating-stars-component'; import { MdOutlineShoppingCart } from 'react-icons/md'; import { FaRegHeart } from 'react-icons/fa6'; import { useParams } from 'next/navigation'; import { Product } from '@/utils/requests'; -import { - ProductObj, - ProductType, - ReviewType, - imageType, -} from '@/types/Product'; +import { ProductType, ReviewType, imageType } from '@/types/Product'; import Card from '@/components/Card'; import Header from '@/components/Header'; import Footer from '@/components/Footer'; -import image from '../../../../public/product.png'; import { useQuery } from '@tanstack/react-query'; import ReviewCard from '@/components/ReviewCard'; import Button from '@/components/Button'; @@ -33,7 +27,7 @@ import { handleUserAddCart } from '@/redux/slices/userCartSlice'; function Page() { const [thumbsSwiper, setThumbsSwiper] = useState(null); - const { id } :any= useParams(); + const { id } = useParams(); const handleSwiper = (swiper: any) => { setThumbsSwiper(swiper); }; @@ -45,176 +39,195 @@ function Page() { const response: ProductType = (await Product.single( _id, )) as ProductType; - return response; } catch (error) { throw new Error('Error fetching product data'); } }, }); - if (isLoading) return Loading...; - if (error) return Error: {error.message}; - const { productPictures, productName, productPrice, productDescription, reviews, - } = data.product; - console.log('this is reviews >>>>>>>>>', reviews); - console.log(' this is average reviews', productPictures); - const { relatedProducts } = data; + } = data?.product || {}; + const { relatedProducts } = data || {}; const dispatch = useAppDispatch(); const handleNewItem = () => { const productId = data.product.id; dispatch(handleUserAddCart({ productPrice, productId })); }; - return (
{/* // */}
-
-
-
-
-
- {productPictures && productPictures.length > 0 ? ( - - {productPictures.map((image: imageType) => { - return ( - - image - - ); - })} - - ) : ( - {'no - )} -
-
- {productPictures && productPictures.length > 0 ? ( -
+ <> + {isLoading ? ( +
+
+
+ ) : ( +
+
+
+
+
- {productPictures.map((image: imageType) => { - return ( - - image - - ); - })} + {[ + ...(!productPictures?.length + ? [ + { + imgId: 'fail Image', + url: '/product.png', + }, + ] + : productPictures), + ].map((image: imageType) => ( + + image + (e.currentTarget.src = '/product.png') + } + /> + + ))}
- ) : ( -

no image found!

- )} -
-
-
-
-

{productName}

-
-
-
-
- +
+ {productPictures && productPictures.length > 0 ? ( +
+ + {productPictures.map((image: imageType) => ( + + image + + ))} + +
+ ) : ( +

no image found!

+ )} +
+
+
+
+

+ {productName} +

-
- { - handleNewItem(); - }} +
+
+
+ +
+
+ { + handleNewItem(); + }} + /> +
+
+ + {productPrice}{' '} + RWF + +
+
+
+
+

Description:

+

{productDescription}

+
- - RWF {productPrice} -
-
- -
-
-

Description:

-

{productDescription}

+
+

Related products:

+
+ {relatedProducts && relatedProducts.length > 0 ? ( + relatedProducts.map((product: ProductType) => ( + + )) + ) : ( +

+ No related products available. +

+ )} +
-
-
-
-

Related products:

-
-
- {relatedProducts && relatedProducts.length > 0 ? ( - relatedProducts.map((product: ProductType) => ( - - )) - ) : ( -

- No related products available. -

- )} +
+
+

Reviews:

+ +
+
+ {reviews && reviews.length > 0 ? ( + reviews.map((review: ReviewType) => ( + + )) + ) : ( +

No ratings yet.

+ )} +
-
-
-

Reviews:

- -
-
- {reviews && reviews.length > 0 ? ( - reviews.map((review: ReviewType) => ( - - )) - ) : ( -

No ratings yet.

- )} -
-
-
-
+ )} +
); } - export default Page; diff --git a/src/app/sellers/products_/[id]/page.tsx b/src/app/sellers/products_/[id]/page.tsx index a67f407..a49fb86 100644 --- a/src/app/sellers/products_/[id]/page.tsx +++ b/src/app/sellers/products_/[id]/page.tsx @@ -1,7 +1,6 @@ // BuyerProductView 'use client'; - import React, { useState, useEffect } from "react"; import Image from 'next/image'; import { MdOutlineShoppingCart } from 'react-icons/md';