Skip to content

Commit

Permalink
feat: HS-181: Added support of Dynamic Fields For Bancontact
Browse files Browse the repository at this point in the history
  • Loading branch information
ArushKapoorJuspay committed Jan 12, 2024
1 parent 2c9228f commit 143dabd
Show file tree
Hide file tree
Showing 9 changed files with 1,186 additions and 647 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 getCardDetailsHook = (~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 143dabd

Please sign in to comment.