{dynamicFieldsToRenderInsideBilling
->Js.Array2.mapi((item, index) => {
@@ -442,17 +454,9 @@ let make = (
key={`inside-billing-${index->Js.Int.toString}`}
className="flex flex-col w-full place-content-between">
{switch item {
- | FullName =>
-
getCustomFieldName}
- optionalRequiredFields={Some(requiredFields)}
- />
| BillingName =>
getCustomFieldName}
- optionalRequiredFields={Some(requiredFields)}
+ paymentType optionalRequiredFields={Some(requiredFields)}
/>
| Email =>
| PhoneNumber =>
@@ -463,9 +467,18 @@ let make = (
setValue={setCity}
value=city
onChange={ev => {
+ let value = ReactEvent.Form.target(ev)["value"]
+ setCity(.prev => {
+ isValid: value !== "" ? Some(true) : Some(false),
+ value,
+ errorString: value !== "" ? "" : prev.errorString,
+ })
+ }}
+ onBlur={ev => {
+ let value = ReactEvent.Focus.target(ev)["value"]
setCity(.prev => {
...prev,
- value: ReactEvent.Form.target(ev)["value"],
+ isValid: Some(value !== ""),
})
}}
paymentType
@@ -503,7 +516,13 @@ let make = (
fieldName=localeString.postalCodeLabel
setValue={setPostalCode}
value=postalCode
- onBlur=onPostalBlur
+ onBlur={ev => {
+ let value = ReactEvent.Focus.target(ev)["value"]
+ setPostalCode(.prev => {
+ ...prev,
+ isValid: Some(value !== ""),
+ })
+ }}
onChange=onPostalChange
paymentType
type_="tel"
@@ -518,9 +537,18 @@ let make = (
setValue={setLine1}
value=line1
onChange={ev => {
+ let value = ReactEvent.Form.target(ev)["value"]
+ setLine1(.prev => {
+ isValid: value !== "" ? Some(true) : Some(false),
+ value,
+ errorString: value !== "" ? "" : prev.errorString,
+ })
+ }}
+ onBlur={ev => {
+ let value = ReactEvent.Focus.target(ev)["value"]
setLine1(.prev => {
...prev,
- value: ReactEvent.Form.target(ev)["value"],
+ isValid: Some(value !== ""),
})
}}
paymentType
@@ -535,9 +563,18 @@ let make = (
setValue={setLine2}
value=line2
onChange={ev => {
+ let value = ReactEvent.Form.target(ev)["value"]
+ setLine2(.prev => {
+ isValid: value !== "" ? Some(true) : Some(false),
+ value,
+ errorString: value !== "" ? "" : prev.errorString,
+ })
+ }}
+ onBlur={ev => {
+ let value = ReactEvent.Focus.target(ev)["value"]
setLine2(.prev => {
...prev,
- value: ReactEvent.Form.target(ev)["value"],
+ isValid: Some(value !== ""),
})
}}
paymentType
@@ -552,9 +589,18 @@ let make = (
setValue={setCity}
value=city
onChange={ev => {
+ let value = ReactEvent.Form.target(ev)["value"]
+ setCity(.prev => {
+ isValid: value !== "" ? Some(true) : Some(false),
+ value,
+ errorString: value !== "" ? "" : prev.errorString,
+ })
+ }}
+ onBlur={ev => {
+ let value = ReactEvent.Focus.target(ev)["value"]
setCity(.prev => {
...prev,
- value: ReactEvent.Form.target(ev)["value"],
+ isValid: Some(value !== ""),
})
}}
paymentType
@@ -583,7 +629,13 @@ let make = (
fieldName=localeString.postalCodeLabel
setValue={setPostalCode}
value=postalCode
- onBlur=onPostalBlur
+ onBlur={ev => {
+ let value = ReactEvent.Focus.target(ev)["value"]
+ setPostalCode(.prev => {
+ ...prev,
+ isValid: Some(value !== ""),
+ })
+ }}
onChange=onPostalChange
paymentType
type_="tel"
@@ -636,6 +688,7 @@ let make = (
| CardCvc
| CardExpiryAndCvc
| Currency(_)
+ | FullName
| None => React.null
}}
diff --git a/src/Components/EmailPaymentInput.res b/src/Components/EmailPaymentInput.res
index bd4bf42ca..a207be735 100644
--- a/src/Components/EmailPaymentInput.res
+++ b/src/Components/EmailPaymentInput.res
@@ -16,19 +16,26 @@ let make = (~paymentType) => {
let changeEmail = ev => {
let val: string = ReactEvent.Form.target(ev)["value"]
setEmail(.prev => {
- ...prev,
value: val,
+ isValid: val->Utils.isEmailValid,
+ errorString: val->Utils.isEmailValid->Belt.Option.getWithDefault(false)
+ ? ""
+ : prev.errorString,
})
}
- let onBlur = _ => {
- Utils.checkEmailValid(email, setEmail)
+ let onBlur = ev => {
+ let val = ReactEvent.Focus.target(ev)["value"]
+ setEmail(.prev => {
+ ...prev,
+ isValid: val->Utils.isEmailValid,
+ })
}
React.useEffect1(() => {
setEmail(.prev => {
...prev,
errorString: switch prev.isValid {
- | Some(val) => val ? "" : "Invalid email address"
+ | Some(val) => val ? "" : localeString.emailInvalidText
| None => ""
},
})
@@ -42,7 +49,7 @@ let make = (~paymentType) => {
if email.value == "" {
setEmail(.prev => {
...prev,
- errorString: "Email cannot be empty",
+ errorString: localeString.emailEmptyText,
})
}
}
diff --git a/src/Components/FullNamePaymentInput.res b/src/Components/FullNamePaymentInput.res
index 34c221abc..adea5cb76 100644
--- a/src/Components/FullNamePaymentInput.res
+++ b/src/Components/FullNamePaymentInput.res
@@ -15,11 +15,20 @@ let make = (~paymentType, ~customFieldName=None, ~optionalRequiredFields=None) =
let changeName = ev => {
let val: string = ReactEvent.Form.target(ev)["value"]
setFullName(.prev => {
- ...prev,
value: val,
- errorString: "",
+ isValid: Some(val !== ""),
+ errorString: val !== "" ? "" : prev.errorString,
})
}
+
+ let onBlur = ev => {
+ let val: string = ReactEvent.Focus.target(ev)["value"]
+ setFullName(.prev => {
+ ...prev,
+ isValid: Some(val !== ""),
+ })
+ }
+
let (placeholder, fieldName) = switch customFieldName {
| Some(val) => (val, val)
| None => (localeString.fullNamePlaceholder, localeString.fullNameLabel)
@@ -33,7 +42,7 @@ let make = (~paymentType, ~customFieldName=None, ~optionalRequiredFields=None) =
if fullName.value == "" {
setFullName(.prev => {
...prev,
- errorString: `Please provide your ${fieldName}`,
+ errorString: fieldName->localeString.nameEmptyText,
})
} else {
switch optionalRequiredFields {
@@ -41,7 +50,7 @@ let make = (~paymentType, ~customFieldName=None, ~optionalRequiredFields=None) =
if !DynamicFieldsUtils.checkIfNameIsValid(requiredFields, FullName, fullName) {
setFullName(.prev => {
...prev,
- errorString: `Please provide your complete ${fieldName}`,
+ errorString: fieldName->localeString.completeNameEmptyText,
})
}
| None => ()
@@ -54,9 +63,11 @@ let make = (~paymentType, ~customFieldName=None, ~optionalRequiredFields=None) =