Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
ecommerce-maven
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ascend
ecommerce-maven
Commits
822c5594
Commit
822c5594
authored
May 10, 2021
by
Kyle Muldoon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
forms: parent - child 2 way binding for capturing input fields
parent
438195a5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
112 additions
and
20 deletions
+112
-20
PaymentMethod.js
ecom-web/src/components/checkout/PaymentMethod.js
+18
-5
ShippingAddress.js
ecom-web/src/components/checkout/ShippingAddress.js
+29
-12
checkout.js
ecom-web/src/components/checkout/checkout.js
+65
-3
No files found.
ecom-web/src/components/checkout/PaymentMethod.js
View file @
822c5594
import
React
,
{
useState
,
useEffect
}
from
'react'
import
React
,
{
useState
,
useEffect
}
from
'react'
export
default
function
PaymentMethod
()
{
export
default
function
PaymentMethod
(
props
)
{
return
(
return
(
<
div
id
=
"PaymentInput"
>
<
div
id
=
"PaymentInput"
>
...
@@ -9,19 +9,32 @@ export default function PaymentMethod() {
...
@@ -9,19 +9,32 @@ export default function PaymentMethod() {
<
/div
>
<
/div
>
<
div
className
=
"shippingInfoInput"
id
=
"cardNumberInput"
>
<
div
className
=
"shippingInfoInput"
id
=
"cardNumberInput"
>
<
input
placeholder
=
"Card Number"
><
/input
>
<
input
placeholder
=
"Card Number"
type
=
"text"
onChange
=
{(
e
)
=>
props
.
captureCardNumber
(
e
.
target
.
value
)}
><
/input
>
<
/div
>
<
/div
>
<
div
className
=
"shippingInfoInput"
id
=
"cardholderNameInput"
>
<
div
className
=
"shippingInfoInput"
id
=
"cardholderNameInput"
>
<
input
placeholder
=
"Cardholder Name"
><
/input
>
<
input
placeholder
=
"Cardholder Name"
type
=
"text"
onChange
=
{(
e
)
=>
props
.
captureCardHolderName
(
e
.
target
.
value
)}
><
/input
>
<
/div
>
<
/div
>
<
div
className
=
"shippingInfoInput"
id
=
"expirationDateInput"
>
<
div
className
=
"shippingInfoInput"
id
=
"expirationDateInput"
>
<
input
placeholder
=
"Expiration Date"
><
/input
>
<
input
placeholder
=
"Expiration Date"
type
=
"text"
onChange
=
{(
e
)
=>
props
.
captureExpirationDate
(
e
.
target
.
value
)}
><
/input
>
<
/div
>
<
/div
>
<
div
className
=
"shippingInfoInput"
id
=
"cvvCodeInput"
>
<
div
className
=
"shippingInfoInput"
id
=
"cvvCodeInput"
>
<
input
placeholder
=
"CVV"
><
/input
>
<
input
placeholder
=
"CVV"
type
=
"text"
onChange
=
{(
e
)
=>
props
.
captureCVV
(
e
.
target
.
value
)}
><
/input
>
<
/div
>
<
/div
>
...
...
ecom-web/src/components/checkout/ShippingAddress.js
View file @
822c5594
import
React
,
{
useState
,
useEffect
}
from
'react'
import
React
,
{
useState
,
useEffect
}
from
'react'
export
default
function
ShippingAddress
()
{
export
default
function
ShippingAddress
(
props
)
{
return
(
return
(
<
div
id
=
"shippingInput"
>
<
div
id
=
"shippingInput"
>
...
@@ -9,35 +9,52 @@ export default function ShippingAddress() {
...
@@ -9,35 +9,52 @@ export default function ShippingAddress() {
<
/div
>
<
/div
>
<
div
className
=
"shippingInfoInput"
id
=
"firstNameInput"
>
<
div
className
=
"shippingInfoInput"
id
=
"firstNameInput"
>
<
input
placeholder
=
"First Name"
><
/input
>
<
input
placeholder
=
"First Name"
type
=
"text"
onChange
=
{(
e
)
=>
props
.
captureFirstName
(
e
.
target
.
value
)}
><
/input
>
<
/div
>
<
/div
>
<
div
className
=
"shippingInfoInput"
id
=
"lastNameInput"
>
<
div
className
=
"shippingInfoInput"
id
=
"lastNameInput"
>
<
input
placeholder
=
"Last Name"
><
/input
>
<
input
placeholder
=
"Last Name"
type
=
"text"
onChange
=
{(
e
)
=>
props
.
captureLastName
(
e
.
target
.
value
)}
><
/input
>
<
/div
>
<
/div
>
<
div
className
=
"shippingInfoInput"
id
=
"addressInput"
>
<
div
className
=
"shippingInfoInput"
id
=
"addressInput"
>
<
input
placeholder
=
"Shipping Address"
><
/input
>
<
input
placeholder
=
"Shipping Address"
type
=
"text"
onChange
=
{(
e
)
=>
props
.
captureShippingAddress
(
e
.
target
.
value
)}
><
/input
>
<
/div
>
<
/div
>
<
div
className
=
"shippingInfoInput"
id
=
"aptSuiteInput"
>
<
div
className
=
"shippingInfoInput"
id
=
"aptSuiteInput"
>
<
input
placeholder
=
"Apt. / Suite no"
><
/input
>
<
input
placeholder
=
"Apt. / Suite no"
type
=
"text"
onChange
=
{(
e
)
=>
props
.
captureAptSuiteNo
(
e
.
target
.
value
)}
><
/input
>
<
/div
>
<
/div
>
<
div
className
=
"shippingInfoInput"
id
=
"cityInput"
>
<
div
className
=
"shippingInfoInput"
id
=
"cityInput"
>
<
input
placeholder
=
"City"
><
/input
>
<
input
placeholder
=
"City"
type
=
"text"
onChange
=
{(
e
)
=>
props
.
captureCity
(
e
.
target
.
value
)}
><
/input
>
<
/div
>
<
/div
>
<
div
className
=
"shippingInfoInput"
id
=
"stateInput"
>
<
div
className
=
"shippingInfoInput"
id
=
"stateInput"
>
<
input
placeholder
=
"State"
><
/input
>
<
input
placeholder
=
"State"
type
=
"text"
onChange
=
{(
e
)
=>
props
.
captureState
(
e
.
target
.
value
)}
><
/input
>
<
/div
>
<
/div
>
<
div
className
=
"shippingInfoInput"
id
=
"zipCodeInput"
>
<
div
className
=
"shippingInfoInput"
id
=
"zipCodeInput"
>
<
input
placeholder
=
"Postal Code"
><
/input
>
<
input
placeholder
=
"Postal Code"
<
/div
>
type
=
"text"
onChange
=
{(
e
)
=>
props
.
captureZipCode
(
e
.
target
.
value
)}
<
div
className
=
"shippingInfoInput"
id
=
"ShippingPriorityInput"
>
><
/input
>
<
input
placeholder
=
"Shipping Priority"
><
/input
>
<
/div
>
<
/div
>
<
/div
>
<
/div
>
)
)
...
...
ecom-web/src/components/checkout/checkout.js
View file @
822c5594
import
React
,
{
useState
,
useEffect
}
from
'react'
import
React
,
{
useState
,
useEffect
}
from
'react'
import
ShippingAddress
from
'./ShippingAddress.js'
import
ShippingAddress
from
'./ShippingAddress.js'
import
PaymentMethod
from
'./PaymentMethod.js'
import
PaymentMethod
from
'./PaymentMethod.js'
import
ReviewOrder
from
'./ReviewOrder.js'
import
ReviewOrder
from
'./ReviewOrder.js'
import
SubmitOrder
from
'./SubmitOrder.js'
import
SubmitOrder
from
'./SubmitOrder.js'
export
default
function
checkout
()
{
export
default
function
Checkout
()
{
///////////////////////
// Shipping Info State
///////////////////////
const
[
firstName
,
setFirstName
]
=
useState
([])
const
[
lastName
,
setLastName
]
=
useState
([])
const
[
shippingAddress
,
setShippingAddress
]
=
useState
([])
const
[
aptSuiteNo
,
setAptSuiteNo
]
=
useState
([])
const
[
city
,
setCity
]
=
useState
([])
const
[
state
,
setState
]
=
useState
([])
const
[
zipCode
,
setZipCode
]
=
useState
([])
///////////////////////
// Billing Info State
///////////////////////
const
[
cardNumber
,
setCardNumber
]
=
useState
([])
const
[
cardHolderName
,
setCardHolderName
]
=
useState
([])
const
[
expirationDate
,
setExpirationDate
]
=
useState
([])
const
[
cvv
,
setCVV
]
=
useState
([])
// This watches for changes on any shipping input field and prints the current states on any change
useEffect
(
()
=>
{
console
.
log
(
"======================================"
)
console
.
log
(
"First Name: "
+
firstName
)
console
.
log
(
"Last Name: "
+
lastName
)
console
.
log
(
"Shipping Address: "
+
shippingAddress
)
console
.
log
(
"Apt Suite No: "
+
aptSuiteNo
)
console
.
log
(
"City: "
+
city
)
console
.
log
(
"State: "
+
state
)
console
.
log
(
"Zip: "
+
zipCode
)
},
[
firstName
,
lastName
,
shippingAddress
,
aptSuiteNo
,
city
,
state
,
zipCode
])
useEffect
(
()
=>
{
console
.
log
(
"======================================"
)
console
.
log
(
"Card Number: "
+
cardNumber
)
console
.
log
(
"Card Holder Name: "
+
cardHolderName
)
console
.
log
(
"Expiration Date: "
+
expirationDate
)
console
.
log
(
"CVV: "
+
cvv
)
},
[
cardNumber
,
cardHolderName
,
expirationDate
,
cvv
])
return
(
return
(
<
div
id
=
"checkout-container"
>
<
div
id
=
"checkout-container"
>
<
ShippingAddress
/>
{
/* Collects User's shipping info */
}
<
ShippingAddress
captureFirstName
=
{
setFirstName
}
captureLastName
=
{
setLastName
}
captureShippingAddress
=
{
setShippingAddress
}
captureAptSuiteNo
=
{
setAptSuiteNo
}
captureCity
=
{
setCity
}
captureState
=
{
setState
}
captureZipCode
=
{
setZipCode
}
/
>
<
PaymentMethod
/>
{
/* Collects User's payment info */
}
<
PaymentMethod
captureCardNumber
=
{
setCardNumber
}
captureCardHolderName
=
{
setCardHolderName
}
captureExpirationDate
=
{
setExpirationDate
}
captureCVV
=
{
setCVV
}
/
>
{
/* Displays info about order. Calculates price with tax / shipping applied */
}
<
ReviewOrder
/>
<
ReviewOrder
/>
{
/* Request to submit happens here, initiates input validation and sends if success */
}
<
SubmitOrder
/>
<
SubmitOrder
/>
<
/div
>
<
/div
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment