Skip to content

Commit

Permalink
chore: added validations for card holder name (#799)
Browse files Browse the repository at this point in the history
  • Loading branch information
sakksham7 authored Nov 19, 2024
1 parent f603ab2 commit 5970224
Show file tree
Hide file tree
Showing 20 changed files with 67 additions and 12 deletions.
39 changes: 28 additions & 11 deletions src/Components/FullNamePaymentInput.res
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,38 @@ let make = (~paymentType, ~customFieldName=None, ~optionalRequiredFields=None) =
let {localeString} = Recoil.useRecoilValueFromAtom(configAtom)
let {fields} = Recoil.useRecoilValueFromAtom(optionAtom)
let loggerState = Recoil.useRecoilValueFromAtom(loggerAtom)

let (fullName, setFullName) = Recoil.useLoggedRecoilState(userFullName, "fullName", loggerState)

let showDetails = getShowDetails(~billingDetails=fields.billingDetails, ~logger=loggerState)

let validateName = (
val: string,
prev: RecoilAtomTypes.field,
localeString: LocaleStringTypes.localeStrings,
) => {
let isValid = val !== "" && %re("/^\D*$/")->RegExp.test(val)
let errorString = if val === "" {
prev.errorString
} else if isValid {
""
} else {
localeString.invalidCardHolderNameError
}
{
...prev,
value: val,
isValid: Some(isValid),
errorString,
}
}

let changeName = ev => {
let val: string = ReactEvent.Form.target(ev)["value"]
setFullName(prev => {
value: val,
isValid: Some(val !== ""),
errorString: val !== "" ? "" : prev.errorString,
})
setFullName(prev => validateName(val, prev, localeString))
}

let onBlur = ev => {
let val: string = ReactEvent.Focus.target(ev)["value"]
setFullName(prev => {
...prev,
isValid: Some(val !== ""),
})
setFullName(prev => validateName(val, prev, localeString))
}

let (placeholder, fieldName) = switch customFieldName {
Expand All @@ -44,6 +56,11 @@ let make = (~paymentType, ~customFieldName=None, ~optionalRequiredFields=None) =
...prev,
errorString: fieldName->localeString.nameEmptyText,
})
} else if !(fullName.isValid->Option.getOr(false)) {
setFullName(prev => {
...prev,
errorString: localeString.invalidCardHolderNameError,
})
} else {
switch optionalRequiredFields {
| Some(requiredFields) =>
Expand Down
2 changes: 2 additions & 0 deletions src/LocaleStrings/ArabicLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,6 @@ let localeStrings: LocaleStringTypes.localeStrings = {
pixKeyEmptyText: `مفتاح Pix لا يمكن أن يكون فارغًا`,
pixKeyPlaceholder: `أدخل مفتاح Pix`,
pixKeyLabel: `مفتاح Pix`,
invalidCardHolderNameError: `اسم حامل البطاقة لا يمكن أن يحتوي على أرقام`,
invalidNickNameError: `لا يمكن أن يحتوي الاسم المستعار على أكثر من رقمين`,
}
2 changes: 2 additions & 0 deletions src/LocaleStrings/CatalanLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,6 @@ let localeStrings: LocaleStringTypes.localeStrings = {
pixKeyEmptyText: `La clau Pix no pot estar buida`,
pixKeyPlaceholder: `Introdueix la clau Pix`,
pixKeyLabel: `Clau Pix`,
invalidCardHolderNameError: `El nom del titular de la targeta no pot contenir dígits`,
invalidNickNameError: `El sobrenom no pot contenir més de 2 dígits`,
}
2 changes: 2 additions & 0 deletions src/LocaleStrings/ChineseLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,6 @@ let localeStrings: LocaleStringTypes.localeStrings = {
pixKeyEmptyText: `Pix 密钥不能为空`,
pixKeyPlaceholder: `输入 Pix 密钥`,
pixKeyLabel: `Pix 密钥`,
invalidCardHolderNameError: `持卡人姓名不能包含数字`,
invalidNickNameError: `昵称不能包含超过2个数字`,
}
2 changes: 2 additions & 0 deletions src/LocaleStrings/DeutschLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,6 @@ let localeStrings: LocaleStringTypes.localeStrings = {
pixKeyEmptyText: `Pix-Schlüssel darf nicht leer sein`,
pixKeyPlaceholder: `Geben Sie den Pix-Schlüssel ein`,
pixKeyLabel: `Pix-Schlüssel`,
invalidCardHolderNameError: `Der Name des Karteninhabers darf keine Ziffern enthalten`,
invalidNickNameError: `Der Spitzname darf nicht mehr als 2 Ziffern enthalten`,
}
2 changes: 2 additions & 0 deletions src/LocaleStrings/DutchLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,6 @@ let localeStrings: LocaleStringTypes.localeStrings = {
pixKeyEmptyText: `Pix-sleutel mag niet leeg zijn`,
pixKeyPlaceholder: `Voer Pix-sleutel in`,
pixKeyLabel: `Pix-sleutel`,
invalidCardHolderNameError: `De naam van de kaarthouder mag geen cijfers bevatten`,
invalidNickNameError: `De bijnaam mag niet meer dan 2 cijfers bevatten`,
}
2 changes: 2 additions & 0 deletions src/LocaleStrings/EnglishGBLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,6 @@ let localeStrings: LocaleStringTypes.localeStrings = {
pixKeyEmptyText: `Pix key cannot be empty`,
pixKeyPlaceholder: `Enter Pix key`,
pixKeyLabel: `Pix key`,
invalidCardHolderNameError: `Cardholder's name cannot contain digits`,
invalidNickNameError: `Nickname cannot have more than 2 digits`,
}
2 changes: 2 additions & 0 deletions src/LocaleStrings/EnglishLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,6 @@ let localeStrings: LocaleStringTypes.localeStrings = {
pixKeyEmptyText: `Pix key cannot be empty`,
pixKeyPlaceholder: `Enter Pix key`,
pixKeyLabel: `Pix key`,
invalidCardHolderNameError: `Card Holder's name cannot have digits`,
invalidNickNameError: `Nickname cannot have more than 2 digits`,
}
2 changes: 2 additions & 0 deletions src/LocaleStrings/FrenchBelgiumLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,6 @@ let localeStrings: LocaleStringTypes.localeStrings = {
pixKeyEmptyText: `La clé Pix ne peut pas être vide`,
pixKeyPlaceholder: `Entrez la clé Pix`,
pixKeyLabel: `Clé Pix`,
invalidCardHolderNameError: `Le nom du titulaire de la carte ne peut pas contenir de chiffres`,
invalidNickNameError: `Le surnom ne peut pas contenir plus de 2 chiffres`,
}
2 changes: 2 additions & 0 deletions src/LocaleStrings/FrenchLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,6 @@ let localeStrings: LocaleStringTypes.localeStrings = {
pixKeyEmptyText: `La clé Pix ne peut pas être vide`,
pixKeyPlaceholder: `Entrez la clé Pix`,
pixKeyLabel: `Clé Pix`,
invalidCardHolderNameError: `Le nom du titulaire de la carte ne peut pas contenir de chiffres`,
invalidNickNameError: `Le surnom ne peut pas contenir plus de 2 chiffres`,
}
2 changes: 2 additions & 0 deletions src/LocaleStrings/HebrewLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,6 @@ let localeStrings: LocaleStringTypes.localeStrings = {
pixKeyEmptyText: `מפתח Pix לא יכול להיות ריק`,
pixKeyPlaceholder: `הכנס מפתח Pix`,
pixKeyLabel: `מפתח Pix`,
invalidCardHolderNameError: `שם בעל הכרטיס לא יכול לכלול ספרות`,
invalidNickNameError: `הכינוי לא יכול לכלול יותר משתי ספרות`,
}
2 changes: 2 additions & 0 deletions src/LocaleStrings/ItalianLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,6 @@ let localeStrings: LocaleStringTypes.localeStrings = {
pixKeyEmptyText: `La chiave Pix non può essere vuota`,
pixKeyPlaceholder: `Inserisci la chiave Pix`,
pixKeyLabel: `Chiave Pix`,
invalidCardHolderNameError: `Il nome del titolare della carta non può contenere cifre`,
invalidNickNameError: `Il soprannome non può contenere più di 2 cifre`,
}
2 changes: 2 additions & 0 deletions src/LocaleStrings/JapaneseLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,6 @@ let localeStrings: LocaleStringTypes.localeStrings = {
pixKeyEmptyText: `Pixキーは空にできません`,
pixKeyPlaceholder: `Pixキーを入力`,
pixKeyLabel: `Pixキー`,
invalidCardHolderNameError: `カード所有者の名前に数字を含めることはできません`,
invalidNickNameError: `ニックネームには2つ以上の数字を含めることはできません`,
}
2 changes: 2 additions & 0 deletions src/LocaleStrings/LocaleStringTypes.res
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ type localeStrings = {
pixKeyEmptyText: string,
pixKeyLabel: string,
pixKeyPlaceholder: string,
invalidCardHolderNameError: string,
invalidNickNameError: string,
}

type constantStrings = {
Expand Down
2 changes: 2 additions & 0 deletions src/LocaleStrings/PolishLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,6 @@ let localeStrings: LocaleStringTypes.localeStrings = {
pixKeyEmptyText: `Klucz Pix nie może być pusty`,
pixKeyPlaceholder: `Wprowadź klucz Pix`,
pixKeyLabel: `Klucz Pix`,
invalidCardHolderNameError: `Imię posiadacza karty nie może zawierać cyfr`,
invalidNickNameError: `Pseudonim nie może zawierać więcej niż 2 cyfry`,
}
2 changes: 2 additions & 0 deletions src/LocaleStrings/PortugueseLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,6 @@ let localeStrings: LocaleStringTypes.localeStrings = {
pixKeyEmptyText: `A chave Pix não pode estar vazia`,
pixKeyPlaceholder: `Digite a chave Pix`,
pixKeyLabel: `Chave Pix`,
invalidCardHolderNameError: `O nome do titular do cartão não pode conter dígitos`,
invalidNickNameError: `O apelido não pode conter mais de 2 dígitos`,
}
2 changes: 2 additions & 0 deletions src/LocaleStrings/RussianLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,6 @@ let localeStrings: LocaleStringTypes.localeStrings = {
pixKeyEmptyText: `Ключ Pix не может быть пустым`,
pixKeyPlaceholder: `Введите ключ Pix`,
pixKeyLabel: `Ключ Pix`,
invalidCardHolderNameError: `Имя владельца карты не может содержать цифры`,
invalidNickNameError: `Псевдоним не может содержать более 2 цифр`,
}
2 changes: 2 additions & 0 deletions src/LocaleStrings/SpanishLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,6 @@ let localeStrings: LocaleStringTypes.localeStrings = {
pixKeyEmptyText: `La clave Pix no puede estar vacía`,
pixKeyPlaceholder: `Introduce la clave Pix`,
pixKeyLabel: `Clave Pix`,
invalidCardHolderNameError: `El nombre del titular de la tarjeta no puede contener dígitos`,
invalidNickNameError: `El apodo no puede contener más de 2 dígitos`,
}
2 changes: 2 additions & 0 deletions src/LocaleStrings/SwedishLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,6 @@ let localeStrings: LocaleStringTypes.localeStrings = {
pixKeyEmptyText: `Pix-nyckel kan inte vara tom`,
pixKeyPlaceholder: `Ange Pix-nyckel`,
pixKeyLabel: `Pix-nyckel`,
invalidCardHolderNameError: `Kortinnehavarens namn får inte innehålla siffror`,
invalidNickNameError: `Smeknamnet får inte innehålla mer än 2 siffror`,
}
4 changes: 3 additions & 1 deletion src/Utilities/DynamicFieldsUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ let useRequiredFieldsEmptyAndValid = (
acc &&
switch paymentMethodFields {
| Email => email.isValid->Option.getOr(false)
| FullName => checkIfNameIsValid(requiredFields, paymentMethodFields, fullName)
| FullName =>
checkIfNameIsValid(requiredFields, paymentMethodFields, fullName) &&
fullName.isValid->Option.getOr(false)
| Country => country !== "" || countryNames->Array.length === 0
| AddressCountry(countryArr) => country !== "" || countryArr->Array.length === 0
| BillingName => checkIfNameIsValid(requiredFields, paymentMethodFields, billingName)
Expand Down

0 comments on commit 5970224

Please sign in to comment.