@@ -12,11 +12,15 @@ const PaymentMethodCardsSection: FC<PaymentMethodCardsSectionProps> = ({ formik
|
||||
const cards = formik.values.cards ?? []
|
||||
const cardsError = formik.touched.cards && typeof formik.errors.cards === 'string' ? formik.errors.cards : ''
|
||||
const cardErrors = Array.isArray(formik.errors.cards) ? formik.errors.cards : []
|
||||
const touchedCards = Array.isArray(formik.touched.cards) ? formik.touched.cards : []
|
||||
|
||||
const getFieldError = (index: number, field: 'cardNumber' | 'owner') => {
|
||||
const fieldErrors = cardErrors[index]
|
||||
const touchedCard = touchedCards[index]
|
||||
if (
|
||||
!formik.touched.cards?.[index]?.[field] ||
|
||||
!touchedCard ||
|
||||
typeof touchedCard !== 'object' ||
|
||||
!touchedCard[field] ||
|
||||
!fieldErrors ||
|
||||
typeof fieldErrors !== 'object' ||
|
||||
!(field in fieldErrors)
|
||||
|
||||
@@ -12,9 +12,10 @@ const PhonesSection: FC<PhonesSectionProps> = ({ formik }) => {
|
||||
const phones = formik.values.phones ?? []
|
||||
const phonesError = formik.touched.phones && typeof formik.errors.phones === 'string' ? formik.errors.phones : ''
|
||||
const phoneErrors = Array.isArray(formik.errors.phones) ? formik.errors.phones : []
|
||||
const touchedPhones = Array.isArray(formik.touched.phones) ? formik.touched.phones : []
|
||||
|
||||
const getFieldError = (index: number) => {
|
||||
if (!formik.touched.phones?.[index] || !phoneErrors[index]) {
|
||||
if (!touchedPhones[index] || !phoneErrors[index]) {
|
||||
return ''
|
||||
}
|
||||
return String(phoneErrors[index])
|
||||
|
||||
Reference in New Issue
Block a user