@@ -15,26 +15,19 @@ import { getFormattedCart } from 'utils/functions/functions';
1515/**
1616 * Display and process product object when we click on the Add To Cart button
1717 * Adds product to shopping cart
18- * @param {Object } props
18+ * @param {Object } product
1919 */
20- const AddToCartButton = ( props ) => {
20+ const AddToCartButton = ( { product } ) => {
2121 const [ cart , setCart ] = useContext ( AppContext ) ;
2222 const [ requestError , setRequestError ] = useState ( null ) ;
2323 const [ showViewCart , setShowViewCart ] = useState ( false ) ;
2424 const [ showAddToCart , setshowAddToCart ] = useState ( false ) ;
2525
26- const product = props . product ;
27-
2826 const productId = product . productId ? product . productId : product ;
2927
30- console . log ( "Props from Addtocart" ) ;
31- console . log ( props ) ;
32-
3328 const productQueryInput = {
3429 clientMutationId : uuidv4 ( ) , // Generate a unique id.
35- //productId: product.productId,
36- //productId: product
37- productId : productId
30+ productId : productId ,
3831 } ;
3932
4033 // Get Cart Data.
@@ -59,8 +52,7 @@ const AddToCartButton = (props) => {
5952 onCompleted : ( data ) => {
6053 // If error.
6154 if ( addToCartError ) {
62- console . log ( 'Add to cart error' ) ;
63- //setRequestError(addToCartError.graphQLErrors[0].message);
55+ setRequestError ( addToCartError . graphQLErrors [ 0 ] . message ) ;
6456 }
6557 // Update the cart with new values in React context.
6658 refetch ( ) ;
@@ -70,9 +62,7 @@ const AddToCartButton = (props) => {
7062 } ,
7163 onError : ( error ) => {
7264 if ( error ) {
73- console . log ( 'Error inside add to cart' ) ;
7465 setRequestError ( error ) ;
75- console . log ( error ) ;
7666 }
7767 } ,
7868 } ) ;
0 commit comments