-
Notifications
You must be signed in to change notification settings - Fork 8
/
Product.tsx
66 lines (61 loc) · 1.68 KB
/
Product.tsx
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
import {
IonCol,
IonContent,
IonFooter,
IonGrid,
IonHeader,
IonPage,
IonRow,
IonTitle,
IonToolbar,
} from "@ionic/react";
import "./Product.css";
import Commerce from "@chec/commerce.js";
import { useEffect, useState } from "react";
import { RouteComponentProps } from "react-router";
import ProductCard from "../../components/product/listing/ProductListing";
import ProductListing from "../../components/product/listing/ProductListing";
interface ProductDetailPageProps
extends RouteComponentProps<{
id: string;
}> {}
const ProductDetail: React.FC<ProductDetailPageProps> = ({
match,
location: { state },
}) => {
const [product, setProduct] = useState((state && state["product"]) || null);
useEffect(() => {
const commerce = new Commerce(process.env.REACT_APP_CHEC_PUBLIC_KEY);
commerce.products
.retrieve(match.params.id)
.then((product) => setProduct(product))
.catch((e) => console.error(e));
}, []);
return (
<IonPage>
<IonHeader>
<IonToolbar>
<IonTitle>
<img src="assets/chopchop.svg" height="28px" width="144px" />
</IonTitle>
</IonToolbar>
</IonHeader>
<IonContent fullscreen>
<IonHeader collapse="condense">
<IonToolbar>
<IonTitle size="large">
<img src="assets/chopchop.svg" height="28px" />
</IonTitle>
</IonToolbar>
</IonHeader>
{product && <ProductListing product={product} />}
</IonContent>
<IonFooter>
<IonToolbar>
<IonTitle>Powered By Commerce.JS</IonTitle>
</IonToolbar>
</IonFooter>
</IonPage>
);
};
export default ProductDetail;