From 890d91eec71a65cdf7ade8da57f02c560ba59be8 Mon Sep 17 00:00:00 2001 From: Samantha Kellow Date: Thu, 27 Jul 2023 17:26:39 +0100 Subject: [PATCH] dynamic product description comonents --- app/product/[handle]/page.tsx | 10 +++-- components/grid/three-items.tsx | 4 +- components/product/description-content.tsx | 52 ++++++++++++++++++++++ components/product/product-description.tsx | 18 +++----- components/product/sustainability-info.tsx | 21 +++++++++ 5 files changed, 88 insertions(+), 17 deletions(-) create mode 100644 components/product/description-content.tsx create mode 100644 components/product/sustainability-info.tsx diff --git a/app/product/[handle]/page.tsx b/app/product/[handle]/page.tsx index 63b205c92..a5351a8fb 100644 --- a/app/product/[handle]/page.tsx +++ b/app/product/[handle]/page.tsx @@ -83,7 +83,7 @@ export default async function ProductPage({ params }: { params: { handle: string />
-
+
({ src: image.url, @@ -91,9 +91,11 @@ export default async function ProductPage({ params }: { params: { handle: string }))} />
- -
- + +
+
+ +
diff --git a/components/grid/three-items.tsx b/components/grid/three-items.tsx index 51461dcce..3e9252e56 100644 --- a/components/grid/three-items.tsx +++ b/components/grid/three-items.tsx @@ -38,8 +38,8 @@ export async function ThreeItemGrid() { const [firstProduct, secondProduct, thirdProduct] = homepageItems; return ( -
- {firstProduct && } +
+ {firstProduct && } {secondProduct && } {thirdProduct && }
diff --git a/components/product/description-content.tsx b/components/product/description-content.tsx new file mode 100644 index 000000000..a109ebc6b --- /dev/null +++ b/components/product/description-content.tsx @@ -0,0 +1,52 @@ +import { SCAPE } from 'constants/brand'; +import { productTypes } from 'constants/item-details'; +import { credentials, credentialsKeys } from 'constants/sustainability'; +import { Product } from 'lib/shopify/types'; + +export function DescriptionContent({ product }: { product: Product }) { + const productTypeKeys = Object.keys(productTypes); + const checkProductType = () => { + return product.tags.find(tag => productTypeKeys.includes(tag)); + } + const productType = checkProductType() as keyof typeof productTypes & string; + + const getCertificationId = (toFind: string) => credentialsKeys.find(key => key === toFind); + + if (!productType) { + return null; + } + + const itemDetails = productTypes[productType]; + + if (!itemDetails) { + return null; + } + + const certificationLink = (credType: keyof typeof credentials) => { + return {credentials[credType].title} certified + } + + return ( + <> +
+

{product.title}, an exclusive artwork by {SCAPE}

+
+

Details:

+
    +
  • + {itemDetails.content}, + {certificationLink('gots')} +
  • +
  • + {itemDetails.print}, + {certificationLink('oekoEco')} +
  • +
  • {itemDetails.weight.feel} weight, {itemDetails.weight.gsm} GSM
  • +
  • {itemDetails.fit} fit
  • +
  • {itemDetails.style}
  • +
+
+
+ + ) +}; diff --git a/components/product/product-description.tsx b/components/product/product-description.tsx index a81a6b02c..f568f7495 100644 --- a/components/product/product-description.tsx +++ b/components/product/product-description.tsx @@ -1,15 +1,16 @@ import { AddToCart } from 'components/cart/add-to-cart'; import Price from 'components/price'; -import Prose from 'components/prose'; import { Product } from 'lib/shopify/types'; +import { DescriptionContent } from './description-content'; +import { SustainabilityInfo } from './sustainability-info'; import { VariantSelector } from './variant-selector'; export function ProductDescription({ product }: { product: Product }) { return ( <>
-

{product.title}

-
+

{product.title}

+
- - {product.descriptionHtml ? ( - - ) : null} - + + + ); } diff --git a/components/product/sustainability-info.tsx b/components/product/sustainability-info.tsx new file mode 100644 index 000000000..46c1a78b3 --- /dev/null +++ b/components/product/sustainability-info.tsx @@ -0,0 +1,21 @@ +import { credentials, credentialsKeys } from "constants/sustainability"; + +export function SustainabilityInfo() { + return ( + <> +
+

Credentials:

+
    + {credentialsKeys.map(credential => ( +
  • + {credentials[credential as keyof typeof credentials].title} +
  • + ))} +
+
+ + ) +};