Skip to content

Commit

Permalink
chore: remove default values of hooks and using directly
Browse files Browse the repository at this point in the history
  • Loading branch information
Pritish Budhiraja committed Mar 20, 2024
1 parent 32d3717 commit abf4589
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 65 deletions.
59 changes: 0 additions & 59 deletions src/CardUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -578,65 +578,6 @@ let postalRegex = (postalCodes: array<PostalCodeType.postalCodes>, ~country=?, (
countryPostal.regex == "" ? "" : countryPostal.regex
}

let useGetCardDetailsFromCardProps = cardProps => {
let defaultCardProps = (
None,
_ => (),
"",
_ => (),
_ => (),
React.useRef(Nullable.null),
React.null,
"",
_ => (),
0,
)

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

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

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

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

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

let setRightIconForCvc = (~cardEmpty, ~cardInvalid, ~color, ~cardComplete) => {
if cardEmpty {
<Icon size=Utils.brandIconSize name="cvc-empty" />
Expand Down
56 changes: 50 additions & 6 deletions src/Components/DynamicFields.res
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,44 @@ let make = (
let (selectedBank, setSelectedBank) = Recoil.useRecoilState(userBank)
let (country, setCountry) = Recoil.useRecoilState(userCountry)

let defaultCardProps = (
None,
_ => (),
"",
_ => (),
_ => (),
React.useRef(Nullable.null),
React.null,
"",
_ => (),
0,
)

let defaultExpiryProps = (
None,
_ => (),
"",
_ => (),
_ => (),
React.useRef(Nullable.null),
_ => (),
"",
_ => (),
)

let defaultCvcProps = (
None,
_ => (),
"",
_ => (),
_ => (),
_ => (),
React.useRef(Nullable.null),
_ => (),
"",
_ => (),
)

let (stateJson, setStatesJson) = React.useState(_ => None)

let bankNames =
Expand Down Expand Up @@ -112,8 +150,10 @@ let make = (
cardError,
_,
maxCardLength,
) =
cardProps->CardUtils.useGetCardDetailsFromCardProps
) = switch cardProps {
| Some(cardProps) => cardProps
| None => defaultCardProps
}

let (
isExpiryValid,
Expand All @@ -125,8 +165,10 @@ let make = (
_,
expiryError,
_,
) =
expiryProps->CardUtils.useGetExpiryDetailsFromExpiryProps
) = switch expiryProps {
| Some(expiryProps) => expiryProps
| None => defaultExpiryProps
}

let (
isCVCValid,
Expand All @@ -139,8 +181,10 @@ let make = (
_,
cvcError,
_,
) =
cvcProps->CardUtils.useGetCvcDetailsFromCvcProps
) = switch cvcProps {
| Some(cvcProps) => cvcProps
| None => defaultCvcProps
}

let isCvcValidValue = CardUtils.getBoolOptionVal(isCVCValid)
let (cardEmpty, cardComplete, cardInvalid) = CardUtils.useCardDetails(
Expand Down

0 comments on commit abf4589

Please sign in to comment.