diff --git a/src/Components/NicknamePaymentInput.res b/src/Components/NicknamePaymentInput.res
index e0df0bdd..bb4bf762 100644
--- a/src/Components/NicknamePaymentInput.res
+++ b/src/Components/NicknamePaymentInput.res
@@ -1,19 +1,50 @@
@react.component
-let make = (~paymentType: CardThemeType.mode, ~value, ~setValue) => {
- let {config, localeString} = Recoil.useRecoilValueFromAtom(RecoilAtoms.configAtom)
+let make = (~paymentType: CardThemeType.mode) => {
+ open RecoilAtoms
+ open Utils
+
+ let (nickName, setNickName) = Recoil.useRecoilState(userCardNickName)
+ let {localeString} = Recoil.useRecoilValueFromAtom(configAtom)
+
+ let validateNickname = val => {
+ let isValid = Some(val === "" || !(val->isDigitLimitExceeded(~digit=2)))
+ let errorString =
+ val !== "" && val->isDigitLimitExceeded(~digit=2) ? localeString.invalidNickNameError : ""
+
+ (isValid, errorString)
+ }
+
+ let setNickNameState = (val, prevState: RecoilAtomTypes.field) => {
+ let (isValid, errorString) = val->validateNickname
+ {
+ ...prevState,
+ value: val,
+ isValid,
+ errorString,
+ }
+ }
let onChange = ev => {
- let val = ReactEvent.Form.target(ev)["value"]
- setValue(_ => val)
+ let val: string = ReactEvent.Form.target(ev)["value"]
+ setNickName(prev => setNickNameState(val, prev))
+ }
+
+ let onBlur = ev => {
+ let val: string = ReactEvent.Focus.target(ev)["value"]
+ setNickName(prev => setNickNameState(val, prev))
}
-
}
diff --git a/src/Payments/CardPayment.res b/src/Payments/CardPayment.res
index ee447637..2758da9e 100644
--- a/src/Payments/CardPayment.res
+++ b/src/Payments/CardPayment.res
@@ -21,7 +21,7 @@ let make = (
let loggerState = Recoil.useRecoilValueFromAtom(RecoilAtoms.loggerAtom)
let paymentMethodListValue = Recoil.useRecoilValueFromAtom(PaymentUtils.paymentMethodListValue)
- let (nickname, setNickname) = React.useState(_ => "")
+ let nickname = Recoil.useRecoilValueFromAtom(RecoilAtoms.userCardNickName)
let (
isCardValid,
@@ -145,7 +145,7 @@ let make = (
~cardHolderName="",
~cvcNumber,
~cardBrand=cardNetwork,
- ~nickname,
+ ~nickname=nickname.value,
)
let banContactBody = PaymentBody.bancontactBody()
let cardBody = if isCustomerAcceptanceRequired {
@@ -154,12 +154,17 @@ let make = (
defaultCardBody
}
if confirm.doSubmit {
- let validFormat =
- (isBancontact ||
- (isCVCValid->Option.getOr(false) &&
+ let isCardDetailsValid =
+ isCVCValid->Option.getOr(false) &&
isCardValid->Option.getOr(false) &&
isCardSupported->Option.getOr(false) &&
- isExpiryValid->Option.getOr(false))) && areRequiredFieldsValid
+ isExpiryValid->Option.getOr(false)
+
+ let isNicknameValid = nickname.value === "" || nickname.isValid->Option.getOr(false)
+
+ let validFormat =
+ (isBancontact || isCardDetailsValid) && isNicknameValid && areRequiredFieldsValid
+
if validFormat && (showFields || isBancontact) {
intent(
~bodyArr={
@@ -339,7 +344,7 @@ let make = (
-
+
diff --git a/src/Utilities/RecoilAtoms.res b/src/Utilities/RecoilAtoms.res
index 6ecce38e..5281dc20 100644
--- a/src/Utilities/RecoilAtoms.res
+++ b/src/Utilities/RecoilAtoms.res
@@ -50,6 +50,7 @@ let userPhoneNumber = Recoil.atom(
countryCode: "",
},
)
+let userCardNickName = Recoil.atom("userCardNickName", defaultFieldValues)
let isGooglePayReady = Recoil.atom("isGooglePayReady", false)
let isApplePayReady = Recoil.atom("isApplePayReady", false)
let userCountry = Recoil.atom("userCountry", "")
diff --git a/src/Utilities/Utils.res b/src/Utilities/Utils.res
index c5e82b2d..745478b0 100644
--- a/src/Utilities/Utils.res
+++ b/src/Utilities/Utils.res
@@ -1451,3 +1451,10 @@ let handleIframePostMessageForWallets = (msg, componentName, mountedIframeRef) =
mountedIframeRef->Window.iframePostMessage(msg)
}
}
+
+let isDigitLimitExceeded = (val, ~digit) => {
+ switch val->String.match(%re("/\d/g")) {
+ | Some(matches) => matches->Array.length > digit
+ | None => false
+ }
+}