summaryrefslogtreecommitdiffstats
path: root/frontend/components/AddToCart.js
blob: 9c52f837b55489a5ff7e49e7ba053977034e2e19 (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
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 () => {
    console.log(`Gonna add this item to the cart! ${this.props.id}`);
    const res = await this.props.addToCart({
      variables: {
        id: this.props.id,
      },
    });
    // this.props.currentUser.refetch();
  };

  render() {
    return <button onClick={this.handleAddToCart}>🛒 Add To Cart</button>;
  }
}

export default compose(userEnhancer, addToCartEnhancer)(AddToCart);