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 hook errors #225

Merged
merged 5 commits into from
Mar 14, 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
2 changes: 1 addition & 1 deletion src/Components/AddressPaymentInput.res
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ let make = (~paymentType, ~className="") => {
}
}
}, (line1, line2, country, state, city, postalCode))
submitPaymentData(submitCallback)
useSubmitPaymentData(submitCallback)

let hasDefaulltValues =
line2.value !== "" || city.value !== "" || postalCode.value !== "" || state.value !== ""
Expand Down
2 changes: 1 addition & 1 deletion src/Components/BillingNamePaymentInput.res
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ let make = (~paymentType, ~customFieldName=None, ~requiredFields as optionalRequ
}
}
}, [billingName])
submitPaymentData(submitCallback)
useSubmitPaymentData(submitCallback)

<RenderIf condition={showDetails.name == Auto}>
<PaymentField
Expand Down
2 changes: 1 addition & 1 deletion src/Components/BlikCodePaymentInput.res
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ let make = () => {
}
}
}, [blikCode])
submitPaymentData(submitCallback)
useSubmitPaymentData(submitCallback)

<RenderIf condition={true}>
<PaymentField
Expand Down
2 changes: 1 addition & 1 deletion src/Components/DynamicFields.res
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ let make = (
)

let submitCallback = DynamicFieldsUtils.useSubmitCallback()
Utils.submitPaymentData(submitCallback)
Utils.useSubmitPaymentData(submitCallback)

let bottomElement = <InfoElement />

Expand Down
2 changes: 1 addition & 1 deletion src/Components/EmailPaymentInput.res
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ let make = (~paymentType) => {
}
}
}, [email])
submitPaymentData(submitCallback)
useSubmitPaymentData(submitCallback)

<RenderIf condition={showDetails.email == Auto}>
<PaymentField
Expand Down
2 changes: 1 addition & 1 deletion src/Components/FullNamePaymentInput.res
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ let make = (~paymentType, ~customFieldName=None, ~optionalRequiredFields=None) =
}
}
}, [fullName])
submitPaymentData(submitCallback)
useSubmitPaymentData(submitCallback)

<RenderIf condition={showDetails.name == Auto}>
<PaymentField
Expand Down
2 changes: 1 addition & 1 deletion src/Components/SavedMethods.res
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ let make = (
}
}
}, (areRequiredFieldsValid, requiredFieldsBody, empty, complete))
submitPaymentData(submitCallback)
useSubmitPaymentData(submitCallback)

<>
<div className="flex flex-col overflow-auto h-auto no-scrollbar animate-slowShow">
Expand Down
21 changes: 16 additions & 5 deletions src/Components/Surcharge.res
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ let make = (

let paymentMethodTypes = paymentMethodType->getPaymentMethodTypes

let getOneClickWalletsMessage = SurchargeUtils.useOneClickWalletsMessageGetter(~list)
let getSurchargeUtilsMessage = SurchargeUtils.useMessageGetter()

let getSurchargeMessage = () => {
if isForWallets {
SurchargeUtils.getOneClickWalletsMessage(~list)
getOneClickWalletsMessage()
} else {
switch paymentMethodTypes.surcharge_details {
| Some(surchargeDetails) => SurchargeUtils.getMessage(~paymentMethod, ~surchargeDetails, ~list)
| Some(surchargeDetails) => getSurchargeUtilsMessage(~paymentMethod, ~surchargeDetails, ~list)
| None =>
if paymentMethod === "card" {
let creditPaymentMethodTypes = getPaymentMethodTypes("credit")
Expand All @@ -44,13 +47,21 @@ let make = (
let debitCardSurcharge = debitSurchargeDetails.displayTotalSurchargeAmount

if creditCardSurcharge >= debitCardSurcharge {
SurchargeUtils.getMessage(~paymentMethod, ~surchargeDetails={creditSurchargeDetails}, ~list)
getSurchargeUtilsMessage(
~paymentMethod,
~surchargeDetails={creditSurchargeDetails},
~list,
)
} else {
SurchargeUtils.getMessage(~paymentMethod, ~surchargeDetails={debitSurchargeDetails}, ~list)
getSurchargeUtilsMessage(
~paymentMethod,
~surchargeDetails={debitSurchargeDetails},
~list,
)
}
| (None, Some(surchargeDetails))
| (Some(surchargeDetails), None) =>
SurchargeUtils.getMessage(~paymentMethod, ~surchargeDetails, ~list)
getSurchargeUtilsMessage(~paymentMethod, ~surchargeDetails, ~list)
| (None, None) => None
}
} else {
Expand Down
158 changes: 82 additions & 76 deletions src/Components/SurchargeUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -13,101 +13,107 @@ type walletSurchargeDetails = {
surchargeDetails: PaymentMethodsRecord.surchargeDetails,
}

let getSurchargeDetailsForOneClickWallets = (~list) => {
let useSurchargeDetailsForOneClickWallets = (~list) => {
let areOneClickWalletsRendered = Recoil.useRecoilValueFromAtom(
RecoilAtoms.areOneClickWalletsRendered,
)

oneClickWallets->Js.Array2.reduce((acc, wallet) => {
let isWalletBtnRendered = switch wallet.paymentMethodType {
| "apple_pay" => areOneClickWalletsRendered.isApplePay
| "paypal" => areOneClickWalletsRendered.isPaypal
| "google_pay" => areOneClickWalletsRendered.isGooglePay
| _ => false
}
if isWalletBtnRendered {
let paymentMethodType =
PaymentMethodsRecord.getPaymentMethodTypeFromList(
~list,
~paymentMethod="wallet",
~paymentMethodType=wallet.paymentMethodType,
)->Belt.Option.getWithDefault(PaymentMethodsRecord.defaultPaymentMethodType)
switch paymentMethodType.surcharge_details {
| Some(surchargDetails) =>
acc->Js.Array2.concat([
{
name: wallet.displayName,
surchargeDetails: surchargDetails,
},
])
| None => acc
React.useMemo2(() => {
oneClickWallets->Js.Array2.reduce((acc, wallet) => {
let isWalletBtnRendered = switch wallet.paymentMethodType {
| "apple_pay" => areOneClickWalletsRendered.isApplePay
| "paypal" => areOneClickWalletsRendered.isPaypal
| "google_pay" => areOneClickWalletsRendered.isGooglePay
| _ => false
}
} else {
acc
}
}, [])
if isWalletBtnRendered {
let paymentMethodType =
PaymentMethodsRecord.getPaymentMethodTypeFromList(
~list,
~paymentMethod="wallet",
~paymentMethodType=wallet.paymentMethodType,
)->Belt.Option.getWithDefault(PaymentMethodsRecord.defaultPaymentMethodType)
switch paymentMethodType.surcharge_details {
| Some(surchargDetails) =>
acc->Js.Array2.concat([
{
name: wallet.displayName,
surchargeDetails: surchargDetails,
},
])
| None => acc
}
} else {
acc
}
}, [])
}, (areOneClickWalletsRendered, list))
}

let getMessage = (
~surchargeDetails: PaymentMethodsRecord.surchargeDetails,
~paymentMethod,
~list: PaymentMethodsRecord.list,
) => {
let useMessageGetter = () => {
let {localeString} = Recoil.useRecoilValueFromAtom(RecoilAtoms.configAtom)
let surchargeValue = surchargeDetails.displayTotalSurchargeAmount->Js.Float.toString

let getLocaleStrForSurcharge = (cardLocale, altPaymentLocale) => {
paymentMethod === "card"
? cardLocale(list.currency, surchargeValue)
: altPaymentLocale(list.currency, surchargeValue)
let getMessage = (
~surchargeDetails: PaymentMethodsRecord.surchargeDetails,
~paymentMethod,
~list: PaymentMethodsRecord.list,
) => {
let surchargeValue = surchargeDetails.displayTotalSurchargeAmount->Js.Float.toString

let localeStrForSurcharge = if paymentMethod === "card" {
localeString.surchargeMsgAmountForCard(list.currency, surchargeValue)
} else {
localeString.surchargeMsgAmount(list.currency, surchargeValue)
}

Some(localeStrForSurcharge)
}

Some(
getLocaleStrForSurcharge(
localeString.surchargeMsgAmountForCard,
localeString.surchargeMsgAmount,
),
)
getMessage
}

let getOneClickWalletsMessage = (~list) => {
let useOneClickWalletsMessageGetter = (~list) => {
let {localeString} = Recoil.useRecoilValueFromAtom(RecoilAtoms.configAtom)

let oneClickWalletsArr = getSurchargeDetailsForOneClickWallets(~list)
let oneClickWalletsArr = useSurchargeDetailsForOneClickWallets(~list)

if oneClickWalletsArr->Js.Array2.length !== 0 {
let msg = oneClickWalletsArr->Js.Array2.reducei((acc, wallet, index) => {
let amount = wallet.surchargeDetails.displayTotalSurchargeAmount->Js.Float.toString
let myMsg =
<>
<strong> {React.string(`${list.currency} ${amount}`)} </strong>
{React.string(`${Utils.nbsp}${localeString.on} ${wallet.name}`)}
</>
let msgToConcat = if index === 0 {
myMsg
} else if index === oneClickWalletsArr->Belt.Array.length - 1 {
let getOneClickWalletsMessage = () => {
if oneClickWalletsArr->Js.Array2.length !== 0 {
let msg = oneClickWalletsArr->Js.Array2.reducei((acc, wallet, index) => {
let amount = wallet.surchargeDetails.displayTotalSurchargeAmount->Js.Float.toString
let myMsg =
<>
<strong> {React.string(`${list.currency} ${amount}`)} </strong>
{React.string(`${Utils.nbsp}${localeString.on} ${wallet.name}`)}
</>
let msgToConcat = if index === 0 {
myMsg
} else if index === oneClickWalletsArr->Belt.Array.length - 1 {
<>
{React.string(`${Utils.nbsp}${localeString.\"and"}${Utils.nbsp}`)}
{myMsg}
</>
} else {
<>
{React.string(`,${Utils.nbsp}`)}
{myMsg}
</>
}
<>
{React.string(`${Utils.nbsp}${localeString.\"and"}${Utils.nbsp}`)}
{myMsg}
{acc}
{msgToConcat}
</>
} else {
}, React.null)
let finalElement =
<>
{React.string(`,${Utils.nbsp}`)}
{myMsg}
{React.string(`${localeString.surchargeMsgAmountForOneClickWallets}:${Utils.nbsp}`)}
{msg}
</>
}
<>
{acc}
{msgToConcat}
</>
}, React.null)
let finalElement =
<>
{React.string(`${localeString.surchargeMsgAmountForOneClickWallets}:${Utils.nbsp}`)}
{msg}
</>
Some(finalElement)
} else {
None
Some(finalElement)
} else {
None
}
}

getOneClickWalletsMessage
}
2 changes: 1 addition & 1 deletion src/PaymentElement.res
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ let make = (
)
}
}, [selectedOption])
Utils.submitPaymentData(submitCallback)
Utils.useSubmitPaymentData(submitCallback)
React.useEffect4(() => {
setSelectedOption(.prev =>
selectedOption !== ""
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/ACHBankDebit.res
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ let make = (~paymentType: CardThemeType.mode, ~list: PaymentMethodsRecord.list)
}
}
}, (email, modalData, fullName))
submitPaymentData(submitCallback)
useSubmitPaymentData(submitCallback)

<div
className="flex flex-col animate-slowShow"
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/ACHBankTransfer.res
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ let make = (~paymentType: CardThemeType.mode, ~list: PaymentMethodsRecord.list)
}
}
}, [email])
submitPaymentData(submitCallback)
useSubmitPaymentData(submitCallback)

<div
className="flex flex-col animate-slowShow"
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/ApplePay.res
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ let make = (
}
}
})
submitPaymentData(submitCallback)
useSubmitPaymentData(submitCallback)

{
isWallet
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/BacsBankDebit.res
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ let make = (~paymentType: CardThemeType.mode, ~list: PaymentMethodsRecord.list)
}
}
})
submitPaymentData(submitCallback)
useSubmitPaymentData(submitCallback)

let changeSortCode = ev => {
let val = ReactEvent.Form.target(ev)["value"]
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/BacsBankTransfer.res
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ let default = (props: props) => {
}
}
}, [email, fullName])
submitPaymentData(submitCallback)
useSubmitPaymentData(submitCallback)

<div
className="flex flex-col animate-slowShow"
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/BecsBankDebit.res
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ let make = (~paymentType: CardThemeType.mode, ~list: PaymentMethodsRecord.list)
}
}
}, (email, fullName, modalData))
submitPaymentData(submitCallback)
useSubmitPaymentData(submitCallback)

<div
className="flex flex-col animate-slowShow"
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/Boleto.res
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ let make = (~paymentType: CardThemeType.mode, ~list: PaymentMethodsRecord.list)
}
}
}, [socialSecurityNumber])
submitPaymentData(submitCallback)
useSubmitPaymentData(submitCallback)

let changeSocialSecurityNumber = ev => {
let val = ReactEvent.Form.target(ev)["value"]
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/CardPayment.res
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ let make = (
isCustomerAcceptanceRequired,
nickname,
))
submitPaymentData(submitCallback)
useSubmitPaymentData(submitCallback)

let paymentMethod = isBancontact ? "bank_redirect" : "card"
let paymentMethodType = isBancontact ? "bancontact_card" : "debit"
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/GPay.res
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ let make = (
}
}
})
submitPaymentData(submitCallback)
useSubmitPaymentData(submitCallback)

{
isWallet
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/KlarnaPayment.res
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ let make = (~paymentType, ~countryProps, ~list: PaymentMethodsRecord.list) => {
}
}
}, (email, fullName, country))
submitPaymentData(submitCallback)
useSubmitPaymentData(submitCallback)

<div
className="flex flex-col animate-slowShow"
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/KlarnaSDK.res
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ let make = (~sessionObj: SessionsType.token, ~list: PaymentMethodsRecord.list) =
)
}
})
submitPaymentData(submitCallback)
useSubmitPaymentData(submitCallback)

React.useEffect1(() => {
if status == "ready" {
Expand Down
Loading
Loading