blob: 22cfe02570d76eb3e33edebc44fcba3048618c8f (
plain)
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
|
import { Component } from 'react';
import { graphql, compose } from 'react-apollo';
import styled from 'styled-components';
import PropTypes from 'prop-types';
import { removeFromCartEnhancer, userEnhancer, addToCartEnhancer, singleItemEnhancer } from '../enhancers/enhancers';
class AddToCart extends Component {
static propTypes = {
currentUser: PropTypes.object.isRequired,
};
componentDidMount() {
this.props.currentUser.refetch();
}
handleAddToCart = async () => {
const res = await this.props.addToCart({
variables: {
id: this.props.id,
},
});
};
render() {
return <button onClick={this.handleAddToCart}>🛒 Add To Cart</button>;
}
}
AddToCart.propTypes = {
currentUser: PropTypes.object.isRequired,
addToCart: PropTypes.func.isRequired,
id: PropTypes.string.isRequired,
};
export default compose(userEnhancer, addToCartEnhancer)(AddToCart);
export { AddToCart };
|