1
1
import { useState , useContext , useEffect } from 'react' ;
2
2
import { useQuery , useMutation } from '@apollo/react-hooks' ;
3
3
4
+ import Billing from './Billing.component' ;
5
+
4
6
import { GET_CART } from 'utils/const/GQL_QUERIES' ;
5
7
import { CHECKOUT_MUTATION } from 'utils/const/GQL_MUTATIONS' ;
6
8
import { INITIAL_STATE } from 'utils/const/INITIAL_STATE' ;
@@ -64,6 +66,23 @@ const CheckoutForm = () => {
64
66
setRequestError ( null ) ;
65
67
} ;
66
68
69
+ /*
70
+ * Handle onChange input.
71
+ *
72
+ * @param {Object } event Event Object.
73
+ *
74
+ * @return {void }
75
+ */
76
+ const handleOnChange = ( event ) => {
77
+ if ( 'createAccount' === event . target . name ) {
78
+ const newState = { ...input , [ event . target . name ] : ! input . createAccount } ;
79
+ setInput ( newState ) ;
80
+ } else {
81
+ const newState = { ...input , [ event . target . name ] : event . target . value } ;
82
+ setInput ( newState ) ;
83
+ }
84
+ } ;
85
+
67
86
useEffect ( ( ) => {
68
87
if ( null !== orderData ) {
69
88
// Perform checkout mutation when the value for orderData changes.
@@ -74,9 +93,23 @@ const CheckoutForm = () => {
74
93
return (
75
94
< >
76
95
{ cart ? (
77
- < form onSubmit = { handleFormSubmit } className = "woo-next-checkout-form" >
78
- < div className = "row" > Skjema kommer her</ div >
79
- </ form >
96
+ < div className = "container mx-auto" >
97
+ < form onSubmit = { handleFormSubmit } className = "" >
98
+ < div className = "" >
99
+ { /*Payment Details*/ }
100
+ < div className = "" >
101
+ < h2 className = "" > Betalingsdetaljer</ h2 >
102
+ < Billing input = { input } handleOnChange = { handleOnChange } />
103
+ </ div >
104
+
105
+ { /* Checkout Loading*/ }
106
+ { checkoutLoading && < p > Behandler ordre ...</ p > }
107
+ { requestError && (
108
+ < p > Feilmelding: { requestError } :( Vennligst prøv igjen.</ p >
109
+ ) }
110
+ </ div >
111
+ </ form >
112
+ </ div >
80
113
) : (
81
114
''
82
115
) }
0 commit comments