Skip to content

Commit

Permalink
chore: rest react useeffect 1 to 7 changes to useEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
Pritish Budhiraja committed Mar 18, 2024
1 parent 1a1bfb7 commit f971327
Show file tree
Hide file tree
Showing 37 changed files with 72 additions and 72 deletions.
2 changes: 1 addition & 1 deletion src/App.res
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let make = () => {
log
})

React.useEffect1(() => {
React.useEffect(() => {
setLoggerState(_ => logger)
None
}, [logger])
Expand Down
4 changes: 2 additions & 2 deletions src/Components/AddressPaymentInput.res
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ let make = (~paymentType, ~className="") => {
}
}

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

React.useEffect1(() => {
React.useEffect(() => {
setState(prev => {
...prev,
value: "",
Expand Down
2 changes: 1 addition & 1 deletion src/Components/BlikCodePaymentInput.res
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let make = () => {
})
}

React.useEffect1(() => {
React.useEffect(() => {
setblikCode(prev => {
...prev,
errorString: switch prev.isValid {
Expand Down
2 changes: 1 addition & 1 deletion src/Components/DynamicFields.res
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let make = (
~cvcProps=None,
~isBancontact=false,
) => {
React.useEffect1(() => {
React.useEffect(() => {
setRequiredFieldsBody(_ => Dict.make())
None
}, [paymentMethodType])
Expand Down
2 changes: 1 addition & 1 deletion src/Components/EmailPaymentInput.res
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let make = (~paymentType) => {
})
}

React.useEffect1(() => {
React.useEffect(() => {
setEmail(prev => {
...prev,
errorString: switch prev.isValid {
Expand Down
4 changes: 2 additions & 2 deletions src/Components/InputField.res
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ let make = (
onBlur(ev)
Utils.handleOnBlurPostMessage(~targetOrigin=parentURL, ())
}
React.useEffect2(() => {
React.useEffect(() => {
if value->String.length > 0 {
setValidClasses()
}
Expand Down Expand Up @@ -105,7 +105,7 @@ let make = (

let concatString = Array.joinWith([cardEmpty, cardComplete, cardInvalid, cardFocused], "")

React.useEffect5(() => {
React.useEffect(() => {
Utils.handlePostMessage([
("id", iframeId->JSON.Encode.string),
("concatedString", concatString->JSON.Encode.string),
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Modal.res
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ let make = (
}, 450)->ignore
}

React.useEffect1(() => {
React.useEffect(() => {
loader ? setOpenModal(_ => false) : setOpenModal(_ => true)
None
}, [loader])
Expand Down
2 changes: 1 addition & 1 deletion src/Components/PayNowButton.res
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ let make = (

let buttonText = sdkHandleConfirmPayment.buttonText->Option.getOr(localeString.payNowButton)

React.useEffect5(() => {
React.useEffect(() => {
if showFields {
if selectedOption === Card {
setIsDisabled(_ => !validFormat)
Expand Down
2 changes: 1 addition & 1 deletion src/Components/PaymentDropDownField.res
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ let make = (
}
}
}
React.useEffect1(() => {
React.useEffect(() => {
let initialValue = options->Array.get(0)->Option.getOr("")
if (
value.value === "" ||
Expand Down
2 changes: 1 addition & 1 deletion src/Components/SavedCardItem.res
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ let make = (
| None => ()
}
}
React.useEffect1(() => {
React.useEffect(() => {
isActive ? focusCVC() : ()
None
}, [isActive])
Expand Down
2 changes: 1 addition & 1 deletion src/Hooks/CommonHooks.res
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ external dictToObj: Dict.t<'a> => {..} = "%identity"

let useScript = (src: string) => {
let (status, setStatus) = React.useState(_ => src != "" ? "loading" : "idle")
React.useEffect1(() => {
React.useEffect(() => {
if src == "" {
setStatus(_ => "idle")
}
Expand Down
2 changes: 1 addition & 1 deletion src/Hooks/Fetcher.res
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type url = {pathname: pathname}
let useFetcher = fileName => {
let _url = RescriptReactRouter.useUrl()
let (optionalJson, setJson) = React.useState(() => None)
React.useEffect1(() => {
React.useEffect(() => {
open Promise
Fetch.get(`${hostname}/json/${fileName}.json`)
->then(Fetch.Response.json)
Expand Down
4 changes: 2 additions & 2 deletions src/Hooks/OutsideClick.res
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let useOutsideClick = (
) => {
let useEvent0 = callback => {
let callbackRef = React.useRef(callback)
React.useEffect1(() => {
React.useEffect(() => {
callbackRef.current = callback

None
Expand All @@ -26,7 +26,7 @@ let useOutsideClick = (
})
}
let eventCallback = useEvent0(callback)
React.useEffect1(() => {
React.useEffect(() => {
if isActive {
let handleClick = (e: ReactEvent.Mouse.t) => {
let targ = e->ReactEvent.Mouse.target
Expand Down
8 changes: 4 additions & 4 deletions src/LoaderController.res
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger) => {
},
)
}, [])
React.useEffect1(() => {
React.useEffect(() => {
switch paymentlist {
| SemiLoaded => ()
| Loaded(_val) => handlePostMessage([("ready", true->JSON.Encode.bool)])
Expand All @@ -160,7 +160,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger) => {
None
}, [paymentlist])

React.useEffect1(() => {
React.useEffect(() => {
CardUtils.genreateFontsLink(config.fonts)
let dict = config.appearance.rules->getDictFromJson
if dict->Dict.toArray->Array.length > 0 {
Expand All @@ -187,7 +187,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger) => {
None
}, [config])

React.useEffect2(() => {
React.useEffect(() => {
open Promise
let handleFun = (ev: Window.event) => {
let json = try {
Expand Down Expand Up @@ -394,7 +394,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger) => {
| None => ()
}

React.useEffect2(() => {
React.useEffect(() => {
Utils.handlePostMessage([
("iframeHeight", (divH +. 1.0)->JSON.Encode.float),
("iframeId", iframeId->JSON.Encode.string),
Expand Down
12 changes: 6 additions & 6 deletions src/Payment.res
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ let make = (~paymentMode, ~integrateError, ~logger) => {

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

React.useEffect2(() => {
React.useEffect(() => {
let obj = getobjFromCardPattern(cardBrand)
let cvcLength = obj.maxCVCLenth
if (
Expand Down Expand Up @@ -211,7 +211,7 @@ let make = (~paymentMode, ~integrateError, ~logger) => {
let submitAPICall = (body, confirmParam) => {
intent(~bodyArr=body, ~confirmParam, ~handleUserError=false, ())
}
React.useEffect2(() => {
React.useEffect(() => {
setCvcNumber(_ => "")
setIsCVCValid(_ => None)
setCvcError(_ => "")
Expand Down Expand Up @@ -326,7 +326,7 @@ let make = (~paymentMode, ~integrateError, ~logger) => {
Utils.handleMessage(handleFun, "Error in parsing sent Data")
}, [])

React.useEffect6(() => {
React.useEffect(() => {
let handleDoSubmit = (ev: Window.event) => {
let json = ev.data->JSON.parseExn
let jsonDict = json->Utils.getDictFromJson
Expand All @@ -340,7 +340,7 @@ let make = (~paymentMode, ~integrateError, ~logger) => {

let cardBrandIcon = getCardBrandIcon(cardBrand->cardType, paymentMode->getPaymentMode)

React.useEffect1(() => {
React.useEffect(() => {
setCardError(_ =>
switch isCardValid {
| Some(val) => val ? "" : localeString.inValidCardErrorText
Expand All @@ -350,7 +350,7 @@ let make = (~paymentMode, ~integrateError, ~logger) => {
None
}, [isCardValid])

React.useEffect1(() => {
React.useEffect(() => {
setCvcError(_ =>
switch isCVCValid {
| Some(val) => val ? "" : localeString.inCompleteCVCErrorText
Expand All @@ -360,7 +360,7 @@ let make = (~paymentMode, ~integrateError, ~logger) => {
None
}, [isCVCValid])

React.useEffect2(() => {
React.useEffect(() => {
setExpiryError(_ =>
switch (isExpiryValid, isExipryComplete(cardExpiry)) {
| (Some(true), true) => ""
Expand Down
16 changes: 8 additions & 8 deletions src/PaymentElement.res
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ let make = (
setLoadSavedCards: (PaymentType.savedCardsLoadState => PaymentType.savedCardsLoadState) => unit,
) = React.useState(_ => PaymentType.LoadingSavedCards)

React.useEffect2(() => {
React.useEffect(() => {
switch (displaySavedPaymentMethods, customerPaymentMethods) {
| (false, _) => {
setShowFields(_ => true)
Expand Down Expand Up @@ -87,7 +87,7 @@ let make = (
None
}, (customerPaymentMethods, displaySavedPaymentMethods))

React.useEffect1(() => {
React.useEffect(() => {
let defaultPaymentMethod =
savedMethods->Array.find(savedMethod => savedMethod.defaultPaymentMethodSet)

Expand Down Expand Up @@ -152,7 +152,7 @@ let make = (
areAllApplePayRequiredFieldsPrefilled,
))

React.useEffect4(() => {
React.useEffect(() => {
switch methodslist {
| Loaded(paymentlist) =>
let plist = paymentlist->Utils.getDictFromJson->PaymentMethodsRecord.itemToObjMapper
Expand Down Expand Up @@ -191,14 +191,14 @@ let make = (
}
None
}, (methodslist, walletList, paymentOptionsList, actualList))
React.useEffect1(() => {
React.useEffect(() => {
switch sessionsObj {
| Loaded(ssn) => setSessions(_ => ssn)
| _ => ()
}
None
}, [sessionsObj])
React.useEffect2(() => {
React.useEffect(() => {
let cardsCount: int = cardsToRender(cardsContainerWidth)
let cardOpts = Array.slice(~start=0, ~end=cardsCount, paymentOptions)
let dropOpts = paymentOptions->Array.sliceToEnd(~start=cardsCount)
Expand Down Expand Up @@ -227,7 +227,7 @@ let make = (
}
}, [selectedOption])
Utils.useSubmitPaymentData(submitCallback)
React.useEffect4(() => {
React.useEffect(() => {
setSelectedOption(prev =>
selectedOption !== ""
? prev
Expand All @@ -246,7 +246,7 @@ let make = (
)
None
}, (layoutClass.defaultCollapsed, paymentOptions, methodslist, selectedOption))
React.useEffect1(() => {
React.useEffect(() => {
if layoutClass.\"type" == Tabs {
let isCard: bool = cardOptions->Array.includes(selectedOption)
if !isCard {
Expand Down Expand Up @@ -388,7 +388,7 @@ let make = (
</ErrorBoundary>
}

React.useEffect1(() => {
React.useEffect(() => {
setShowFields(_ => !displaySavedPaymentMethods)
None
}, [displaySavedPaymentMethods])
Expand Down
4 changes: 2 additions & 2 deletions src/PaymentOptions.res
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ let make = (
let (selectedOption, setSelectedOption) = Recoil.useRecoilState(selectedOptionAtom)
let (moreIconIndex, setMoreIconIndex) = React.useState(_ => 0)
let (toggleIconElement, setToggleIconElement) = React.useState(_ => false)
React.useEffect2(() => {
React.useEffect(() => {
let width = switch payOptionsRef.current->Nullable.toOption {
| Some(ref) => ref->Window.Element.clientWidth
| None => 0
Expand All @@ -81,7 +81,7 @@ let make = (
->Array.find(item => item.paymentMethodName == selectedOption)
->Option.getOr(PaymentMethodsRecord.defaultPaymentMethodFields)

React.useEffect1(() => {
React.useEffect(() => {
let intervalId = setInterval(() => {
if dropDownOptionsDetails->Array.length > 1 {
setMoreIconIndex(prev => mod(prev + 1, dropDownOptionsDetails->Array.length))
Expand Down
4 changes: 2 additions & 2 deletions src/Payments/ACHBankDebit.res
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ let make = (~paymentType: CardThemeType.mode, ~list: PaymentMethodsRecord.list)
(),
)

React.useEffect1(() => {
React.useEffect(() => {
if modalData->Option.isSome {
setBankError(_ => "")
}
Expand All @@ -50,7 +50,7 @@ let make = (~paymentType: CardThemeType.mode, ~list: PaymentMethodsRecord.list)
modalData->Option.isSome
let empty = email.value == "" || fullName.value != ""

React.useEffect2(() => {
React.useEffect(() => {
handlePostMessageEvents(~complete, ~empty, ~paymentType="ach_bank_debit", ~loggerState)
None
}, (empty, complete))
Expand Down
4 changes: 2 additions & 2 deletions src/Payments/ACHBankTransfer.res
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ let make = (~paymentType: CardThemeType.mode, ~list: PaymentMethodsRecord.list)
let complete = email.value != "" && email.isValid->Option.getOr(false)
let empty = email.value == ""

React.useEffect2(() => {
React.useEffect(() => {
handlePostMessageEvents(~complete, ~empty, ~paymentType="bank_transfer", ~loggerState)
None
}, (empty, complete))

React.useEffect1(() => {
React.useEffect(() => {
setComplete(_ => complete)
None
}, [complete])
Expand Down
4 changes: 2 additions & 2 deletions src/Payments/ApplePay.res
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ let make = (
->ignore
}

React.useEffect4(() => {
React.useEffect(() => {
let handleApplePayMessages = (ev: Window.event) => {
let json = try {
ev.data->JSON.parseExn
Expand Down Expand Up @@ -317,7 +317,7 @@ let make = (
)
}, (isInvokeSDKFlow, requiredFieldsBody, isWallet, processPayment))

React.useEffect4(() => {
React.useEffect(() => {
if (
(isInvokeSDKFlow || paymentExperience == PaymentMethodsRecord.RedirectToURL) &&
isApplePayReady &&
Expand Down
4 changes: 2 additions & 2 deletions src/Payments/BacsBankDebit.res
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ let make = (~paymentType: CardThemeType.mode, ~list: PaymentMethodsRecord.list)
country.value == "" ||
state.value == ""

React.useEffect2(() => {
React.useEffect(() => {
handlePostMessageEvents(~complete, ~empty, ~paymentType="bacs_bank_debit", ~loggerState)
None
}, (empty, complete))

React.useEffect1(() => {
React.useEffect(() => {
setComplete(_ => complete)
None
}, [complete])
Expand Down
Loading

0 comments on commit f971327

Please sign in to comment.