-
Notifications
You must be signed in to change notification settings - Fork 609
Expand file tree
/
Copy path{ProductsJson.title}.tsx
More file actions
123 lines (118 loc) · 4.1 KB
/
{ProductsJson.title}.tsx
File metadata and controls
123 lines (118 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import * as React from "react"
import {graphql, PageProps} from "gatsby"
import Layout from "@/components/Layout"
import {Header} from "@/components/ga4/EnhancedEcommerce/header";
import {Footer} from "@/components/ga4/EnhancedEcommerce/footer";
import {AddToCart} from "@/components/ga4/EnhancedEcommerce/add-to-cart"
import {NumericInput} from "@/components/ga4/EnhancedEcommerce/numeric-input"
import {GatsbyImage, GatsbyImageProps, IGatsbyImageData} from "gatsby-plugin-image";
import {
productBox,
container,
header,
productImageWrapper,
priceValue,
addToCartStyle,
productDescription,
} from "./product-page.module.css"
import {ChangeEvent} from 'react';
type ImageInfo = GatsbyImageProps & {
childImageSharp: {gatsbyImageData: IGatsbyImageData};
}
type Props = {
location: { pathname: string },
productsJson: {
id: number
brand: string
category: string
price: string,
title: string,
description: string,
image: ImageInfo
}
}
export default (props: PageProps<Props>) => {
const {
price,
title,
description,
image,
} = props.data.productsJson
const initialVariant = 'M'
// TODO: Implement variant selection functionality, which will use setVariant.
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [variant, setVariant] = React.useState(initialVariant)
const productVariant = variant;
const [quantity, setQuantity] = React.useState(1)
return (
<Layout
title="Enhanced Ecommerce Demo"
pathname={props.location.pathname}
description=""
>
<Header/>
<div className={container}>
<div className={productBox}>
<div className={productImageWrapper}>
<div
aria-label="gallery"
aria-describedby="instructions"
>
<GatsbyImage objectFit="contain"
alt={title}
image={image!.childImageSharp!.gatsbyImageData}/>
</div>
</div>
<div>
<h1 className={header}>{title}</h1>
<p className={productDescription}>{description}</p>
<h2 className={priceValue}>
<span>${price}</span>
</h2>
<div className={addToCartStyle}>
<NumericInput
aria-label="Quantity"
onIncrement={() => setQuantity((q) => Math.min(q + 1, 20))}
onDecrement={() => setQuantity((q) => Math.max(1, q - 1))}
onChange={(event: ChangeEvent<HTMLInputElement>) => setQuantity(parseInt(event.currentTarget.value))}
value={quantity}
disabled={false}
min="1"
max="20"
/>
<AddToCart
variantId={productVariant}
quantity={quantity}
product={props.data.productsJson}
/>
</div>
</div>
</div>
</div>
<Footer/>
</Layout>
)
}
export const query = graphql`
query($id: String!) {
productsJson(id: { eq: $id }) {
id
title
price
brand
category
description
image {
childImageSharp {
gatsbyImageData(width: 640)
}
}
thumbnail:
image {
childImageSharp {
gatsbyImageData(width: 100)
}
}
}
}
`