Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove postal code check #412

Merged
merged 2 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 6 additions & 30 deletions src/Components/AddressPaymentInput.res
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ let make = (~paymentType, ~className="") => {
let cityRef = React.useRef(Nullable.null)
let postalRef = React.useRef(Nullable.null)

let (postalCodes, setPostalCodes) = React.useState(_ => [PostalCodeType.defaultPostalCode])
let (stateJson, setStatesJson) = React.useState(_ => None)
let (showOtherFileds, setShowOtherFields) = React.useState(_ => false)

Expand All @@ -68,17 +67,14 @@ let make = (~paymentType, ~className="") => {
let checkPostalValidity = (
postal: RecoilAtomTypes.field,
setPostal: (RecoilAtomTypes.field => RecoilAtomTypes.field) => unit,
regex,
) => {
if RegExp.test(regex->RegExp.fromString, postal.value) && postal.value !== "" && regex !== "" {
if postal.value !== "" {
setPostal(prev => {
...prev,
isValid: Some(true),
errorString: "",
})
} else if (
regex !== "" && !RegExp.test(regex->RegExp.fromString, postal.value) && postal.value !== ""
) {
} else {
setPostal(prev => {
...prev,
isValid: Some(false),
Expand All @@ -89,17 +85,6 @@ let make = (~paymentType, ~className="") => {

React.useEffect0(() => {
open Promise
// Dynamically import/download Postal codes and states JSON
PostalCodeType.importPostalCode("./../PostalCodes.bs.js")
->then(res => {
setPostalCodes(_ => res.default)
resolve()
})
->catch(_ => {
setPostalCodes(_ => [PostalCodeType.defaultPostalCode])
resolve()
})
->ignore
importStates("./../States.json")
->then(res => {
setStatesJson(_ => Some(res.states))
Expand All @@ -114,12 +99,6 @@ let make = (~paymentType, ~className="") => {
None
})

let regex = CardUtils.postalRegex(
postalCodes,
~country={getCountryCode(country.value).isoAlpha2},
(),
)

let onPostalChange = ev => {
let val = ReactEvent.Form.target(ev)["value"]

Expand All @@ -128,20 +107,17 @@ let make = (~paymentType, ~className="") => {
value: val,
errorString: "",
})
if regex !== "" && RegExp.test(regex->RegExp.fromString, val) {
CardUtils.blurRef(postalRef)
}
}

let onPostalBlur = ev => {
let val = ReactEvent.Focus.target(ev)["value"]
if regex !== "" && RegExp.test(regex->RegExp.fromString, val) && val !== "" {
if val !== "" {
setPostalCode(prev => {
...prev,
isValid: Some(true),
errorString: "",
})
} else if regex !== "" && !RegExp.test(regex->RegExp.fromString, val) && val !== "" {
} else {
setPostalCode(prev => {
...prev,
isValid: Some(false),
Expand All @@ -151,9 +127,9 @@ let make = (~paymentType, ~className="") => {
}

React.useEffect(() => {
checkPostalValidity(postalCode, setPostalCode, regex)
checkPostalValidity(postalCode, setPostalCode)
None
}, (regex, country.value))
}, country.value)

React.useEffect(() => {
setState(prev => {
Expand Down
15 changes: 1 addition & 14 deletions src/Components/DynamicFields.res
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ let make = (
"postal_code",
logger,
)
let (postalCodes, setPostalCodes) = React.useState(_ => [PostalCodeType.defaultPostalCode])

let (currency, setCurrency) = Recoil.useLoggedRecoilState(userCurrency, "currency", logger)
let line1Ref = React.useRef(Nullable.null)
let line2Ref = React.useRef(Nullable.null)
Expand Down Expand Up @@ -215,17 +215,6 @@ let make = (

React.useEffect0(() => {
open Promise
// Dynamically import/download Postal codes and states JSON
PostalCodeType.importPostalCode("./../PostalCodes.bs.js")
->then(res => {
setPostalCodes(_ => res.default)
resolve()
})
->catch(_ => {
setPostalCodes(_ => [PostalCodeType.defaultPostalCode])
resolve()
})
->ignore
AddressPaymentInput.importStates("./../States.json")
->then(res => {
setStatesJson(_ => Some(res.states))
Expand All @@ -240,8 +229,6 @@ let make = (
None
})

let _regex = CardUtils.postalRegex(postalCodes, ~country={getCountryCode(country).isoAlpha2}, ())

let onPostalChange = ev => {
let val = ReactEvent.Form.target(ev)["value"]

Expand Down
32 changes: 3 additions & 29 deletions src/Payment.res
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ let make = (~paymentMode, ~integrateError, ~logger) => {
cardBrand->getCardType
}, [cardBrand])

let (postalCodes, setPostalCodes) = React.useState(_ => [PostalCodeType.defaultPostalCode])

React.useEffect(() => {
let obj = getobjFromCardPattern(cardBrand)
let cvcLength = obj.maxCVCLenth
Expand All @@ -111,23 +109,6 @@ let make = (~paymentMode, ~integrateError, ~logger) => {
None
}, (cvcNumber, cardNumber))

React.useEffect0(() => {
open Promise
if paymentMode->getPaymentMode == Card {
PostalCodeType.importPostalCode("./PostalCodes.bs.js")
->then(res => {
setPostalCodes(_ => res.default)
resolve()
})
->catch(_ => {
setPostalCodes(_ => [PostalCodeType.defaultPostalCode])
resolve()
})
->ignore
}
None
})

let changeCardNumber = ev => {
let val = ReactEvent.Form.target(ev)["value"]
logInputChangeInfo("cardNumber", logger)
Expand Down Expand Up @@ -175,10 +156,6 @@ let make = (~paymentMode, ~integrateError, ~logger) => {
let changeZipCode = ev => {
let val = ReactEvent.Form.target(ev)["value"]
logInputChangeInfo("zipCode", logger)
let regex = postalRegex(postalCodes, ())
if regex !== "" && RegExp.test(regex->RegExp.fromString, val) {
blurRef(zipRef)
}
setZipCode(_ => val)
}

Expand Down Expand Up @@ -235,13 +212,10 @@ let make = (~paymentMode, ~integrateError, ~logger) => {

let handleZipBlur = ev => {
let zipCode = ReactEvent.Focus.target(ev)["value"]
let regex = postalRegex(postalCodes, ())
if RegExp.test(regex->RegExp.fromString, zipCode) || regex == "" {
setIsZipValid(_ => Some(true))
} else if zipCode->String.length == 0 {
setIsZipValid(_ => None)
} else {
if zipCode === "" {
setIsZipValid(_ => Some(false))
} else {
setIsZipValid(_ => Some(true))
}
}

Expand Down
Loading
Loading