@@ -2,7 +2,9 @@ import { useState, useContext, useEffect } from 'react';
2
2
import { useQuery , useMutation } from '@apollo/react-hooks' ;
3
3
4
4
import { GET_CART } from 'utils/const/GQL_QUERIES' ;
5
+ import { CHECKOUT_MUTATION } from 'utils/const/GQL_MUTATIONS' ;
5
6
import { INITIAL_STATE } from 'utils/const/INITIAL_STATE' ;
7
+
6
8
import { AppContext } from 'utils/context/AppContext' ;
7
9
8
10
import { getFormattedCart } from 'utils/functions/functions' ;
@@ -13,6 +15,24 @@ const CheckoutForm = () => {
13
15
const [ orderData , setOrderData ] = useState ( null ) ;
14
16
const [ requestError , setRequestError ] = useState ( null ) ;
15
17
18
+ // Checkout GraphQL mutation
19
+ const [
20
+ checkout ,
21
+ { data : checkoutResponse , loading : checkoutLoading , error : checkoutError } ,
22
+ ] = useMutation ( CHECKOUT_MUTATION , {
23
+ variables : {
24
+ input : orderData ,
25
+ } ,
26
+ onCompleted : ( ) => {
27
+ refetch ( ) ;
28
+ } ,
29
+ onError : ( error ) => {
30
+ if ( error ) {
31
+ setRequestError ( error ) ;
32
+ }
33
+ } ,
34
+ } ) ;
35
+
16
36
// Get Cart Data.
17
37
const { loading, error, data, refetch } = useQuery ( GET_CART , {
18
38
notifyOnNetworkStatusChange : true ,
@@ -46,8 +66,8 @@ const CheckoutForm = () => {
46
66
47
67
useEffect ( ( ) => {
48
68
if ( null !== orderData ) {
49
- // Do checkout mutation when the value for orderData changes.
50
- // checkout();
69
+ // Perform checkout mutation when the value for orderData changes.
70
+ checkout ( ) ;
51
71
}
52
72
} , [ orderData ] ) ;
53
73
0 commit comments