|
1 | 1 | import Link from 'next/link';
|
2 | 2 | import { v4 as uuidv4 } from 'uuid';
|
3 | 3 |
|
4 |
| -import { filteredVariantPrice } from 'utils/functions/functions'; |
| 4 | +import { filteredVariantPrice, paddedPrice } from 'utils/functions/functions'; |
5 | 5 |
|
6 | 6 | /**
|
7 | 7 | * Displays all of the products as long as length is defined.
|
8 | 8 | * Does a map() over the props array and utilizes uuidv4 for unique key values.
|
9 | 9 | * @param {Object} products
|
10 | 10 | */
|
11 |
| -const IndexProducts = ({ products }) => ( |
12 |
| - <section className="container mx-auto bg-white"> |
13 |
| - <div id="product-container" className="flex flex-wrap items-center"> |
14 |
| - {products ? ( |
15 |
| - products.map( |
16 |
| - ({ |
17 |
| - databaseId, |
18 |
| - name, |
19 |
| - price, |
20 |
| - regularPrice, |
21 |
| - salePrice, |
22 |
| - onSale, |
23 |
| - slug, |
24 |
| - image, |
25 |
| - variations, |
26 |
| - }) => ( |
27 |
| - <div key={uuidv4()} className="flex flex-col p-6 md:w-1/2 xl:w-1/4"> |
28 |
| - <Link |
29 |
| - href={`/produkt/${encodeURIComponent( |
30 |
| - slug |
31 |
| - )}?id=${encodeURIComponent(databaseId)}`} |
| 11 | +const IndexProducts = ({ products }) => { |
| 12 | + return ( |
| 13 | + <section className="container mx-auto bg-white"> |
| 14 | + <div id="product-container" className="flex flex-wrap items-center"> |
| 15 | + {products ? ( |
| 16 | + products.map( |
| 17 | + ({ |
| 18 | + databaseId, |
| 19 | + name, |
| 20 | + price, |
| 21 | + regularPrice, |
| 22 | + salePrice, |
| 23 | + onSale, |
| 24 | + slug, |
| 25 | + image, |
| 26 | + variations, |
| 27 | + }) => ( |
| 28 | + <div |
| 29 | + key={uuidv4()} |
| 30 | + className="flex flex-col p-6 md:w-1/2 xl:w-1/4" |
32 | 31 | >
|
33 |
| - <a> |
34 |
| - {image ? ( |
35 |
| - <img |
36 |
| - id="product-image" |
37 |
| - className="transition duration-500 ease-in-out transform cursor-pointer hover:grow hover:shadow-lg hover:scale-105" |
38 |
| - alt={name} |
39 |
| - src={image.sourceUrl} |
40 |
| - /> |
41 |
| - ) : ( |
42 |
| - <img |
43 |
| - id="product-image" |
44 |
| - className="transition duration-500 ease-in-out transform cursor-pointer hover:grow hover:shadow-lg hover:scale-105" |
45 |
| - alt={name} |
46 |
| - src={process.env.NEXT_PUBLIC_PLACEHOLDER_SMALL_IMAGE_URL} |
47 |
| - /> |
48 |
| - )} |
49 |
| - </a> |
50 |
| - </Link> |
| 32 | + <Link |
| 33 | + href={`/produkt/${encodeURIComponent( |
| 34 | + slug |
| 35 | + )}?id=${encodeURIComponent(databaseId)}`} |
| 36 | + > |
| 37 | + <a> |
| 38 | + {image ? ( |
| 39 | + <img |
| 40 | + id="product-image" |
| 41 | + className="transition duration-500 ease-in-out transform cursor-pointer hover:grow hover:shadow-lg hover:scale-105" |
| 42 | + alt={name} |
| 43 | + src={image.sourceUrl} |
| 44 | + /> |
| 45 | + ) : ( |
| 46 | + <img |
| 47 | + id="product-image" |
| 48 | + className="transition duration-500 ease-in-out transform cursor-pointer hover:grow hover:shadow-lg hover:scale-105" |
| 49 | + alt={name} |
| 50 | + src={ |
| 51 | + process.env.NEXT_PUBLIC_PLACEHOLDER_SMALL_IMAGE_URL |
| 52 | + } |
| 53 | + /> |
| 54 | + )} |
| 55 | + </a> |
| 56 | + </Link> |
51 | 57 |
|
52 |
| - <Link |
53 |
| - href={`/produkt/${encodeURIComponent( |
54 |
| - slug |
55 |
| - )}?id=${encodeURIComponent(databaseId)}`} |
56 |
| - > |
57 |
| - <a> |
58 |
| - <div className="flex justify-center pt-3"> |
59 |
| - <p className="font-bold text-center cursor-pointer"> |
60 |
| - {name} |
61 |
| - </p> |
62 |
| - </div> |
63 |
| - </a> |
64 |
| - </Link> |
65 |
| - {/* Display sale price when on sale */} |
66 |
| - {onSale && ( |
67 |
| - <div className="flex justify-center"> |
68 |
| - <div className="pt-1 text-gray-900"> |
69 |
| - {variations && filteredVariantPrice(price)} |
70 |
| - {!variations && salePrice} |
71 |
| - </div> |
72 |
| - <div className="pt-1 ml-2 text-gray-900 line-through"> |
73 |
| - {variations && filteredVariantPrice(price, 'right')} |
74 |
| - {!variations && regularPrice} |
| 58 | + <Link |
| 59 | + href={`/produkt/${encodeURIComponent( |
| 60 | + slug |
| 61 | + )}?id=${encodeURIComponent(databaseId)}`} |
| 62 | + > |
| 63 | + <a> |
| 64 | + <div className="flex justify-center pt-3"> |
| 65 | + <p className="font-bold text-center cursor-pointer"> |
| 66 | + {name} |
| 67 | + </p> |
| 68 | + </div> |
| 69 | + </a> |
| 70 | + </Link> |
| 71 | + {/* Display sale price when on sale */} |
| 72 | + {onSale && ( |
| 73 | + <div className="flex justify-center"> |
| 74 | + <div className="pt-1 text-gray-900"> |
| 75 | + {variations && filteredVariantPrice(price)} |
| 76 | + {!variations && paddedPrice(salePrice)} |
| 77 | + </div> |
| 78 | + <div className="pt-1 ml-2 text-gray-900 line-through"> |
| 79 | + {variations && filteredVariantPrice(price, 'right')} |
| 80 | + {!variations && paddedPrice(regularPrice)} |
| 81 | + </div> |
75 | 82 | </div>
|
76 |
| - </div> |
77 |
| - )} |
78 |
| - {/* Display regular price when not on sale */} |
79 |
| - {!onSale && ( |
80 |
| - <p className="pt-1 text-center text-gray-900"> {price}</p> |
81 |
| - )} |
82 |
| - </div> |
| 83 | + )} |
| 84 | + {/* Display regular price when not on sale */} |
| 85 | + {!onSale && ( |
| 86 | + <p className="pt-1 text-center text-gray-900"> |
| 87 | + {paddedPrice(price)} |
| 88 | + </p> |
| 89 | + )} |
| 90 | + </div> |
| 91 | + ) |
83 | 92 | )
|
84 |
| - ) |
85 |
| - ) : ( |
86 |
| - <div className="mx-auto text-xl font-bold text-center text-gray-800 no-underline uppercase"> |
87 |
| - Ingen produkter funnet |
88 |
| - </div> |
89 |
| - )} |
90 |
| - </div> |
91 |
| - </section> |
92 |
| -); |
| 93 | + ) : ( |
| 94 | + <div className="mx-auto text-xl font-bold text-center text-gray-800 no-underline uppercase"> |
| 95 | + Ingen produkter funnet |
| 96 | + </div> |
| 97 | + )} |
| 98 | + </div> |
| 99 | + </section> |
| 100 | + ); |
| 101 | +}; |
93 | 102 |
|
94 | 103 | export default IndexProducts;
|
0 commit comments