Skip to content

Commit

Permalink
feat: HS-181: Added support of Dynamic Fields For Bancontact (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArushKapoorJuspay authored Jan 16, 2024
1 parent 2c9228f commit 0d13e7a
Show file tree
Hide file tree
Showing 12 changed files with 1,173 additions and 669 deletions.
82 changes: 82 additions & 0 deletions src/CardUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -581,3 +581,85 @@ let postalRegex = (postalCodes: array<PostalCodeType.postalCodes>, ~country=?, (
let countryPostal = Utils.getCountryPostal(country, postalCodes)
countryPostal.regex == "" ? "" : countryPostal.regex
}

let getCardDetailsFromCardProps = cardProps => {
let defaultCardProps = (
None,
_ => (),
"",
_ => (),
_ => (),
React.useRef(Js.Nullable.null),
<> </>,
"",
_ => (),
0,
)

switch cardProps {
| Some(cardProps) => cardProps
| None => defaultCardProps
}
}

let getExpiryDetailsFromExpiryProps = expiryProps => {
let defaultExpiryProps = (
None,
_ => (),
"",
_ => (),
_ => (),
React.useRef(Js.Nullable.null),
_ => (),
"",
_ => (),
)

switch expiryProps {
| Some(expiryProps) => expiryProps
| None => defaultExpiryProps
}
}

let getCvcDetailsFromCvcProps = cvcProps => {
let defaultCvcProps = (
None,
_ => (),
"",
_ => (),
_ => (),
_ => (),
React.useRef(Js.Nullable.null),
_ => (),
"",
_ => (),
)

switch cvcProps {
| Some(cvcProps) => cvcProps
| None => defaultCvcProps
}
}

let setRightIconForCvc = (~cardEmpty, ~cardInvalid, ~color, ~cardComplete) => {
if cardEmpty {
<Icon size=28 name="cvc-empty" />
} else if cardInvalid {
<div style={ReactDOMStyle.make(~color, ())}>
<Icon size=28 name="cvc-invalid" />
</div>
} else if cardComplete {
<Icon size=28 name="cvc-complete" />
} else {
<Icon size=28 name="cvc-empty" />
}
}

let useCardDetails = (~cvcNumber, ~isCvcValidValue, ~isCVCValid) => {
React.useMemo3(() => {
let isCardDetailsEmpty = Js.String2.length(cvcNumber) == 0
let isCardDetailsValid = isCvcValidValue == "valid"
let isCardDetailsInvalid = isCvcValidValue == "invalid"
(isCardDetailsEmpty, isCardDetailsValid, isCardDetailsInvalid)
}, (cvcNumber, isCvcValidValue, isCVCValid))
}
Loading

0 comments on commit 0d13e7a

Please sign in to comment.