-
Notifications
You must be signed in to change notification settings - Fork 215
Expand file tree
/
Copy pathProductOverview.js
More file actions
99 lines (93 loc) · 3.2 KB
/
ProductOverview.js
File metadata and controls
99 lines (93 loc) · 3.2 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
import React, { Component } from 'react'
import styles from './stylesheets/productOverview.module.sass'
import { Button } from 'react-bootstrap'
import Header from '../../components/header/headerContainer'
import Variants from './components/Variants'
import mergeProductAndVariants from './utils/mergeProductAndVariants'
import jumpTo from '../../modules/Navigation'
export default class ProductOverview extends Component {
constructor(props) {
super(props);
this.state = {
color: '',
size: '',
pic: '',
selectedSize: '',
id: ''
}
}
componentDidMount() {
this.props.getProduct(this.props.location.pathname.split("/").slice(-1)[0])
this.props.getVariantsByProductId(this.props.location.pathname.split("/").slice(-1)[0])
}
handleClick = (variant) => {
this.setState({
color: variant.color,
size: variant.size,
pic: variant.imagePath,
selectedSize: '',
id: variant._id
})
}
clickSize = (s) => {
this.setState({
selectedSize: s
})
}
addToBag = () => {
this.props.postCart(
this.state.id || this.props.location.pathname.split("/").slice(-1)[0]
).then(res => {
jumpTo('/bag')
})
}
render() {
return (
<div className={styles.outbox}>
<Header />
{this.props.product &&
<div className={styles.content_box}>
<div className={styles.content}>
{/* left image */}
<div className={styles.image}>
<img src={this.state.pic || this.props.product.imagePath} alt="" />
</div>
{/* right content box */}
<div className={styles.context_outbox}>
<div className={styles.context}>
{/* top descriptions */}
<div className={styles.title}>
{this.props.product.title}
</div>
<div className={styles.description}>
{this.props.product.description}
</div>
<div className={styles.price}>
${this.props.product.price} CAD
</div>
{/* dotted border */}
<div className={styles.border}></div>
{/* bottom descriptions */}
<div className={styles.variants}>
<Variants
color={this.state.color || this.props.product.color}
size={this.state.size || this.props.product.size}
selectedSize={this.state.selectedSize}
variants={mergeProductAndVariants(this.props.product, this.props.variants)}
handleClick={this.handleClick}
clickSize={this.clickSize}
/>
</div>
<div className={styles.btns}>
<Button className={styles.btn} onClick={this.addToBag} variant="outline-primary">Agregar a la bolsa</Button>
<Button className={styles.btn} variant="outline-danger">Comprar Ahora</Button>
</div>
</div>
</div>
</div>
</div>
}
</div>
)
}
}