From b47a9570aa6ac9a05026743e2f46b0ceed9faf0e Mon Sep 17 00:00:00 2001 From: w3bdesign <45217974+w3bdesign@users.noreply.github.com> Date: Fri, 13 Sep 2024 07:55:11 +0200 Subject: [PATCH 01/12] Design product --- .../Product/SingleProduct.component.tsx | 77 +++++++++---------- src/components/UI/Button.component.tsx | 14 ++-- 2 files changed, 44 insertions(+), 47 deletions(-) diff --git a/src/components/Product/SingleProduct.component.tsx b/src/components/Product/SingleProduct.component.tsx index 3be084f35..6cea2e69c 100644 --- a/src/components/Product/SingleProduct.component.tsx +++ b/src/components/Product/SingleProduct.component.tsx @@ -48,7 +48,7 @@ const SingleProduct = ({ product }: IProductRootObject) => { } return ( -
+
{/* Show loading spinner while loading, and hide content while loading */} {isLoading ? (
@@ -57,38 +57,41 @@ const SingleProduct = ({ product }: IProductRootObject) => {
) : ( -
-
+
+
{image && ( - {name} +
+ {name} +
)} {!image && ( - {name} +
+ {name} +
)} -
-

{name}

-
+
+

{name}

{/* Display sale price when on sale */} {onSale && ( -
-

+

+

{product.variations && filteredVariantPrice(price, '')} {!product.variations && salePrice}

-

+

{product.variations && filteredVariantPrice(price, 'right')} {!product.variations && regularPrice}

@@ -96,27 +99,21 @@ const SingleProduct = ({ product }: IProductRootObject) => { )} {/* Display regular price when not on sale */} {!onSale && ( -

{price}

+

{price}

)} -
-

- {DESCRIPTION_WITHOUT_HTML} -

+

{DESCRIPTION_WITHOUT_HTML}

{Boolean(product.stockQuantity) && ( -

+

{product.stockQuantity} på lager

)} {product.variations && ( -

- Varianter +

+ -

+
)} -
- { - // Display default AddToCart button if we do not have variations. - // If we do, send the variationId to AddToCart button - } +
{product.variations && ( void; @@ -14,7 +14,7 @@ interface IButtonProps { * @function PageTitle * @param {void} handleButtonClick - Handle button click * @param {boolean?} buttonDisabled - Is button disabled? - * @param {color?} TButtonColors - Color for button, either red or blue + * @param {color?} TButtonColors - Color for button, either red, blue, or yellow * @param {ReactNode} children - Children for button * @returns {JSX.Element} - Rendered component */ @@ -27,11 +27,15 @@ const Button = ({ +
+ {product.variations ? ( + + ) : ( + + )} +
From 188683f54c03096974139f6431b4a54a04fc25d0 Mon Sep 17 00:00:00 2001 From: w3bdesign <45217974+w3bdesign@users.noreply.github.com> Date: Fri, 13 Sep 2024 08:23:57 +0200 Subject: [PATCH 07/12] Update SingleProduct.component.tsx --- .../Product/SingleProduct.component.tsx | 143 ++++++++---------- 1 file changed, 65 insertions(+), 78 deletions(-) diff --git a/src/components/Product/SingleProduct.component.tsx b/src/components/Product/SingleProduct.component.tsx index 21dfd0ef8..147f871ff 100644 --- a/src/components/Product/SingleProduct.component.tsx +++ b/src/components/Product/SingleProduct.component.tsx @@ -1,18 +1,17 @@ import React, { useState, useEffect } from 'react'; import { filteredVariantPrice, paddedPrice } from '@/utils/functions/functions'; -import AddToCart, { IProduct, IProductRootObject } from './AddToCart.component'; +import AddToCart, { IProductRootObject } from './AddToCart.component'; import LoadingSpinner from '@/components/LoadingSpinner/LoadingSpinner.component'; import Button from '@/components/UI/Button.component'; -interface SingleProductProps { - product: IProduct; -} - -const SingleProduct: React.FC = ({ product }) => { +const SingleProduct: React.FC = ({ + product, + variationId: initialVariationId, +}) => { const [isLoading, setIsLoading] = useState(true); const [selectedVariation, setSelectedVariation] = useState< number | undefined - >(); + >(initialVariationId); const placeholderFallBack = 'https://via.placeholder.com/600'; @@ -20,11 +19,11 @@ const SingleProduct: React.FC = ({ product }) => { useEffect(() => { setIsLoading(false); - if (product.variations) { + if (product.variations && !selectedVariation) { const firstVariant = product.variations.nodes[0].databaseId; setSelectedVariation(firstVariant); } - }, [product.variations]); + }, [product.variations, selectedVariation]); let { description, image, name, onSale, price, regularPrice, salePrice } = product; @@ -40,8 +39,7 @@ const SingleProduct: React.FC = ({ product }) => { } const handleBuy = () => { - // Implement buy functionality here - console.log('Buy button clicked'); + console.log('Buy now clicked'); }; return ( @@ -75,79 +73,68 @@ const SingleProduct: React.FC = ({ product }) => { /> )}
-
-

- {name} -

-
- {onSale ? ( -
-

- {product.variations - ? filteredVariantPrice(price, '') - : salePrice} -

-

- {product.variations - ? filteredVariantPrice(price, 'right') - : regularPrice} -

+
+

{name}

+
+ {onSale &&

Før {regularPrice}

} +

+ {product.variations + ? filteredVariantPrice(price, '') + : onSale + ? salePrice + : price} +

+

+ Tilbudet gjelder til 19/09 eller så lenge lageret rekker. +

+
+
+ + + {product.variations && ( +
+ +
- ) : ( -

{price}

)}
-

- {DESCRIPTION_WITHOUT_HTML} -

{Boolean(product.stockQuantity) && ( -

- {product.stockQuantity} på lager +

+ + {product.stockQuantity}+ stk. på lager

)} - {product.variations && ( -
- - -
- )} -
- -
- {product.variations ? ( - - ) : ( - - )} -
+
+

+ Produktbeskrivelse +

+

{DESCRIPTION_WITHOUT_HTML}

From dcb45d96d85d1ec9983d5af192e1b9e50b4dd724 Mon Sep 17 00:00:00 2001 From: w3bdesign <45217974+w3bdesign@users.noreply.github.com> Date: Fri, 13 Sep 2024 08:27:43 +0200 Subject: [PATCH 08/12] Update SingleProduct.component.tsx --- src/components/Product/SingleProduct.component.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/components/Product/SingleProduct.component.tsx b/src/components/Product/SingleProduct.component.tsx index 147f871ff..c74992230 100644 --- a/src/components/Product/SingleProduct.component.tsx +++ b/src/components/Product/SingleProduct.component.tsx @@ -90,9 +90,7 @@ const SingleProduct: React.FC = ({
- + {product.variations && (
) : (
-
-
- {image ? ( - {name} - ) : ( - {name} - )} -
-
-

{name}

-
- {onSale &&

Før {regularPrice}

} -

- {product.variations - ? filteredVariantPrice(price, '') - : onSale - ? salePrice - : price} -

-

- Tilbudet gjelder til 19/09 eller så lenge lageret rekker. -

+
+ {/* First row: Product info, price, and purchase options */} +
+
+ {image ? ( + {name} + ) : ( + {name} + )}
-
- +
+

{name}

+
+ {onSale &&

Før {regularPrice}

} +

+ {product.variations + ? filteredVariantPrice(price, '') + : onSale + ? salePrice + : price} +

+

+ Tilbudet gjelder til 19/09 eller så lenge lageret rekker. +

+
+
+ - {product.variations && ( -
- - -
+ {product.variations && ( +
+ + +
+ )} +
+ {Boolean(product.stockQuantity) && ( +

+ + {product.stockQuantity}+ stk. på lager +

)}
- {Boolean(product.stockQuantity) && ( -

- - {product.stockQuantity}+ stk. på lager -

- )} -
-

- Produktbeskrivelse -

-

{DESCRIPTION_WITHOUT_HTML}

-
+
+ + {/* Second row: Product description */} +
+

+ Produktbeskrivelse +

+

{DESCRIPTION_WITHOUT_HTML}

From e70a52fb2f42cbcdc48ecf033fcf7e5a7c258fb8 Mon Sep 17 00:00:00 2001 From: w3bdesign <45217974+w3bdesign@users.noreply.github.com> Date: Fri, 13 Sep 2024 08:35:48 +0200 Subject: [PATCH 12/12] Update SingleProduct.component.tsx --- src/components/Product/SingleProduct.component.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/components/Product/SingleProduct.component.tsx b/src/components/Product/SingleProduct.component.tsx index 3d9843a18..5d45efdce 100644 --- a/src/components/Product/SingleProduct.component.tsx +++ b/src/components/Product/SingleProduct.component.tsx @@ -37,9 +37,7 @@ const SingleProduct: React.FC = ({ .textContent || ''; } - const handleBuy = () => { - console.log('Buy now clicked'); - }; + return (