forked from JessNah/BeeGreen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CheckoutDialog.tsx
94 lines (88 loc) · 3.12 KB
/
CheckoutDialog.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
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
import React, { Component } from 'react'
import "./CheckoutDialog.scss"
import { Tearsheet, TearsheetNarrow } from "@carbon/ibm-cloud-cognitive"
import { getCartAverageRating, getCart } from "../../stores/storesCommon"
import CheckoutCart from "./CheckoutCart/CheckoutCart"
import { productItem } from "../../utils/types"
import ItemDialogContent from "../ItemDialog/ItemDialogContent/ItemDialogContent"
import CheckoutDialogContent from "./CheckoutDialogContent/CheckoutDialogContent"
interface CheckoutDialogProps {
closeCheckoutDialog: () => void;
currentStore: string;
}
interface CheckoutDialogState {
cart: {[key:string]: any}[];
cartRank: string;
openCart: boolean;
openComparison: boolean;
currentComparisonItem?: productItem
}
class CheckoutDialog extends Component<CheckoutDialogProps, CheckoutDialogState> {
state= {
cart: [],
cartRank: undefined,
openCart: false,
openComparison: false,
currentComparisonItem: undefined
}
componentDidMount() {
const cart = getCart(this.props.currentStore);
const cartRank = getCartAverageRating(cart);
this.setState({cart: cart, cartRank: cartRank});
window.setTimeout(() => {this.setState({openCart: true})}, 500);
}
render() {
console.log(this.state.cart);
console.log(this.state);
return (
<>
<Tearsheet
open={this.state.openCart}
label={""}
title={"Take2"}
description={"Keep it up! You're shopping smarter than 73% of shoppers visiting this site."}
actions={[{
kind: 'secondary',
label: "Close",
loading: false,
onClick: () => {this.props.closeCheckoutDialog()}
}, {
kind: 'ghost',
label: "Make an impact! Donate to plant some trees and reduce the carbon footprint of your purchase!",
loading: false,
onClick: () => {window.open("https://carbonfund.org/product-category/plant-trees/")}
}]}
onClose={() => {this.props.closeCheckoutDialog()}}
influencerPosition={'right'}
influencerWidth={'wide'}
influencer={
<CheckoutCart
cart={this.state.cart}
cartRank={this.state.cartRank}
selectItem={(item) => {this.setState({openComparison: true, currentComparisonItem: item})}}
/>}
>
<CheckoutDialogContent
cart={this.state.cart}/>
</Tearsheet>
<TearsheetNarrow
open={this.state.openComparison}
label={""}
title={"Take2"}
description={"Carbon footprint comparison to other similar items"}
onClose={() => {this.setState({openComparison: false, currentComparisonItem: undefined})}}
actions={[{
kind: 'secondary',
label: "Back",
loading: false,
onClick: () => {this.setState({openComparison: false, currentComparisonItem: undefined})}
}]}
>
<ItemDialogContent
item={this.state.currentComparisonItem}/>
</TearsheetNarrow>
</>
)
}
}
export default CheckoutDialog