diff options
Diffstat (limited to 'frontend/components/AddToCart.js')
| -rw-r--r-- | frontend/components/AddToCart.js | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/frontend/components/AddToCart.js b/frontend/components/AddToCart.js index eead8f0..e2770cb 100644 --- a/frontend/components/AddToCart.js +++ b/frontend/components/AddToCart.js @@ -1,7 +1,7 @@ import { Component } from 'react'; -import { Mutation } from 'react-apollo'; +import { Mutation, Query } from 'react-apollo'; import PropTypes from 'prop-types'; -import { ADD_TO_CART_MUTATION, CURRENT_USER_QUERY } from 'queries'; +import { ADD_TO_CART_MUTATION, CURRENT_USER_QUERY } from '../queries/queries'; class AddToCart extends Component { static propTypes = { @@ -29,13 +29,17 @@ class AddToCart extends Component { render() { const { id } = this.props; return ( - <Mutation mutation={ADD_TO_CART_MUTATION} variables={{ id }} update={this.update}> - {(addToCart, { loading }) => ( - <button disabled={loading} onClick={addToCart}> - 🛒 Add{loading && 'ing'} To Cart - </button> + <Query query={CURRENT_USER_QUERY}> + {() => ( + <Mutation mutation={ADD_TO_CART_MUTATION} variables={{ id }} update={this.update}> + {(addToCart, { loading }) => ( + <button disabled={loading} onClick={addToCart}> + 🛒 Add{loading && 'ing'} To Cart + </button> + )} + </Mutation> )} - </Mutation> + </Query> ); } } |
