• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

atlp-rwanda / champs-ec-fe / 13ba735d-90f9-49d3-9acb-f5a6c957f324

18 Jun 2024 10:20PM UTC coverage: 58.852% (-28.3%) from 87.175%
13ba735d-90f9-49d3-9acb-f5a6c957f324

Pull #13

circleci

k3lly003
Merge pull request #26 from atlp-rwanda/ft-disable-users-#187300202

Ft disable users #187300202
Pull Request #13: feat(ProductView): ProductView (all/one) according to there user's role #187300196

70 of 95 branches covered (73.68%)

Branch coverage included in aggregate %.

84 of 626 new or added lines in 24 files covered. (13.42%)

219 existing lines in 7 files now uncovered.

1366 of 2345 relevant lines covered (58.25%)

2.27 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/app/products/[id]/page.tsx
NEW
1
// BuyerProductView
×
NEW
2
'use client';
×
NEW
3
import React, { useState } from 'react';
×
NEW
4
import { Swiper, SwiperSlide } from 'swiper/react';
×
NEW
5
import 'swiper/css';
×
NEW
6
import 'swiper/css/free-mode';
×
NEW
7
import 'swiper/css/navigation';
×
NEW
8
import 'swiper/css/thumbs';
×
NEW
9
import { FreeMode, Navigation, Thumbs } from 'swiper/modules';
×
NEW
10
import Image from 'next/image';
×
NEW
11
import { MdOutlineShoppingCart } from 'react-icons/md';
×
NEW
12
import { FaRegHeart } from 'react-icons/fa6';
×
NEW
13
import { useParams } from 'next/navigation';
×
NEW
14
import { Product } from '@/utils/requests';
×
NEW
15
import { ProductObj, ProductType, ReviewType, imageType } from '@/types/Product';
×
NEW
16
import Card from '@/components/Card';
×
NEW
17
import Review from '@/components/ReviewProduct';
×
NEW
18
import Header from '@/components/Header';
×
NEW
19
import Footer from '@/components/Footer'; 
×
NEW
20
import image from '../../../../public/product.png';
×
NEW
21
import { useQuery } from '@tanstack/react-query';
×
NEW
22

×
NEW
23
function Page() {
×
NEW
24
  const [thumbsSwiper, setThumbsSwiper] = useState(null);
×
NEW
25
  const { id } = useParams();
×
NEW
26
  
×
NEW
27
  const _id: string = id.toLocaleString();
×
NEW
28
  const { data, isLoading, error } = useQuery<any>({
×
NEW
29
    queryKey: ['product', id],
×
NEW
30
    queryFn: async () => {
×
NEW
31
      try {
×
NEW
32
        const response: ProductType = (await Product.single(_id)) as ProductType;
×
NEW
33
        
×
NEW
34
        return response;
×
NEW
35
      } catch (error) {
×
NEW
36
        throw new Error('Error fetching product data');
×
NEW
37
      }
×
NEW
38
    },
×
NEW
39
  });
×
NEW
40
  if (isLoading) return <span>Loading...</span>;
×
NEW
41

×
NEW
42
  if (error) return <span>Error: {error.message}</span>;
×
NEW
43

×
NEW
44
  const {
×
NEW
45
    productThumbnail,
×
NEW
46
    productPictures,
×
NEW
47
    productName,
×
NEW
48
    productPrice,
×
NEW
49
    productDescription,
×
NEW
50
    reviews,
×
NEW
51
  } = data.product;
×
NEW
52

×
NEW
53
  const { relatedProducts } = data;
×
NEW
54
  
×
NEW
55
  return (
×
NEW
56
    <div>
×
NEW
57
      <Header />
×
NEW
58
      <div className="w-full mb-5 mt-5 flex flex-col justify-center items-center">
×
NEW
59
        <div className="w-2/3 flex flex-col justify-center items-center gap-5">
×
NEW
60
          <div className="w-full flex">
×
NEW
61
            <div className="w-1/2">
×
NEW
62
              <div className="flex justify-center py-2">
×
NEW
63
                {productPictures && productPictures.length > 0 ? (
×
NEW
64
                  <Swiper
×
NEW
65
                    spaceBetween={10}
×
NEW
66
                    navigation={true}
×
NEW
67
                    thumbs={{ swiper: thumbsSwiper }}
×
NEW
68
                    modules={[FreeMode, Navigation, Thumbs]}
×
NEW
69
                    className="mySwiper2"
×
NEW
70
                  >
×
NEW
71
                    {productPictures.map((image:imageType) => {
×
NEW
72
                      return (
×
NEW
73
                        <SwiperSlide key={image.imgId}>
×
NEW
74
                          <img src={image.URL} />
×
NEW
75
                        </SwiperSlide>
×
NEW
76
                      );
×
NEW
77
                    })}
×
NEW
78
                  </Swiper>
×
NEW
79
                ) : (
×
NEW
80
                  <Image src={image} alt={'no image found'} />
×
NEW
81
                )}
×
NEW
82
              </div>
×
NEW
83
              <div className="w-full flex space-x-4 justify-start mt-3">
×
NEW
84
                {productPictures && productPictures.length > 0 ? (
×
NEW
85
                  <div className="w-[500px] h-[15em] overflow-hidden">
×
NEW
86
                    <Swiper
×
NEW
87
                      onSwiper={setThumbsSwiper}
×
NEW
88
                      spaceBetween={10}
×
NEW
89
                      slidesPerView={4}
×
NEW
90
                      freeMode={true}
×
NEW
91
                      watchSlidesProgress={true}
×
NEW
92
                      modules={[FreeMode, Navigation, Thumbs]}
×
NEW
93
                      className="mySwiper mycss"
×
NEW
94
                    >
×
NEW
95
                      {productPictures.map((image:imageType) => {
×
NEW
96
                        return (
×
NEW
97
                          <SwiperSlide key={image.imgId}>
×
NEW
98
                            <img src={image.URL} />
×
NEW
99
                          </SwiperSlide>
×
NEW
100
                        );
×
NEW
101
                      })}
×
NEW
102
                    </Swiper>
×
NEW
103
                  </div>
×
NEW
104
                ) : (
×
NEW
105
                  <p className="text-red-500">no image found!</p>
×
NEW
106
                )}
×
NEW
107
              </div>
×
NEW
108
            </div>
×
NEW
109
            <div className="w-1/2 flex flex-col ml-10">
×
NEW
110
              <div>
×
NEW
111
                <h1 className="font-medium text-2xl">{productName}</h1>
×
NEW
112
              </div>
×
NEW
113
              <div className="flex flex-col gap-2">
×
NEW
114
                <div className="flex gap-2">
×
NEW
115
                  <div className="p-3 rounded-full bg-gray-200 hover:bg-green-500 hover:text-white cursor-pointer">
×
NEW
116
                    <FaRegHeart />
×
NEW
117
                  </div>
×
NEW
118
                  <div className="p-3 rounded-full bg-gray-200 hover:bg-green-500 hover:text-white cursor-pointer">
×
NEW
119
                    <MdOutlineShoppingCart />
×
NEW
120
                  </div>
×
NEW
121
                </div>
×
NEW
122
                <span className="font-medium text-2xl text-blue-300">
×
NEW
123
                  ${productPrice}
×
NEW
124
                </span>
×
NEW
125
              </div>
×
NEW
126
              <div className="flex flex-col gap-2">
×
NEW
127
                <h2 className="font-medium text-2xl">Description:</h2>
×
NEW
128
                <p className="w-full text-1xl">{productDescription}</p>
×
NEW
129
              </div>
×
NEW
130
            </div>
×
NEW
131
          </div>
×
NEW
132
          <div className="w-full flex flex-col">
×
NEW
133
            <h2 className="font-medium text-2xl">Related products:</h2>
×
NEW
134
            <div className="w-full max-w-[100%]">
×
NEW
135
              <div className="product-grid flex justify-evenly mt-5">
×
NEW
136
                {relatedProducts && relatedProducts.length > 0 ? (
×
NEW
137
                  relatedProducts.map((product:ProductType) => (
×
NEW
138
                    <Card
×
NEW
139
                      key={product.id}
×
NEW
140
                      id={product.id}
×
NEW
141
                      productPrice={product.productPrice}
×
NEW
142
                      productThumbnail={product.productThumbnail}
×
NEW
143
                      productDescription={product.productDescription}
×
NEW
144
                    />
×
NEW
145
                  ))
×
NEW
146
                ) : (
×
NEW
147
                  <p className="text-red-500 w-full flex self-center">
×
NEW
148
                    No related products available.
×
NEW
149
                  </p>
×
NEW
150
                )}
×
NEW
151
              </div>
×
NEW
152
            </div>
×
NEW
153
          </div>
×
NEW
154
          <div className="w-full flex flex-col mt-10">
×
NEW
155
            <h2 className="font-medium text-2xl">Reviews:</h2>
×
NEW
156
            <div className="my-10">
×
NEW
157
              {reviews && reviews.length > 0 ? (
×
NEW
158
                reviews.map((review: ReviewType) => (
×
NEW
159
                  <Review
×
NEW
160
                    rating={review.rating}
×
NEW
161
                    feedback={review.feedback}
×
NEW
162
                  />
×
NEW
163
                ))
×
NEW
164
              ) : (
×
NEW
165
                <p className="text-red-500">No ratings yet.</p>
×
NEW
166
              )}
×
NEW
167
            </div>
×
NEW
168
          </div>
×
NEW
169
        </div>
×
NEW
170
      </div>
×
NEW
171
      <Footer />
×
NEW
172
    </div>
×
NEW
173
  );
×
NEW
174
}
×
NEW
175

×
NEW
176
export default Page;
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc