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: react hooks issue fix #233

Merged
merged 9 commits into from
Apr 2, 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
18 changes: 8 additions & 10 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
{
"env": {
"browser": true,
"es2021": true
"browser": true,
"es2021": true
},
"extends": [
],
"extends": [],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"react-hooks"
],
"plugins": ["react-hooks"],
"rules": {
"react-hooks/rules-of-hooks": "error"
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn"
}
}
3 changes: 3 additions & 0 deletions .github/workflows/CI-Action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,8 @@ jobs:
- name: "Build"
run: npm run build

- name: "Test React Hooks Properties"
run: npm run test:hooks

- name: npm release
run: npx semantic-release --debug;
59 changes: 0 additions & 59 deletions src/CardUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -579,65 +579,6 @@ let postalRegex = (postalCodes: array<PostalCodeType.postalCodes>, ~country=?, (
countryPostal.regex == "" ? "" : countryPostal.regex
}

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

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

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

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

let getCvcDetailsFromCvcProps = 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.getCardDetailsFromCardProps
) = switch cardProps {
| Some(cardProps) => cardProps
| None => defaultCardProps
}

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

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

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