diff --git a/src/pages/paymentMethods/components/PaymentMethodCardsSection.tsx b/src/pages/paymentMethods/components/PaymentMethodCardsSection.tsx index 60da7ab..b19b790 100644 --- a/src/pages/paymentMethods/components/PaymentMethodCardsSection.tsx +++ b/src/pages/paymentMethods/components/PaymentMethodCardsSection.tsx @@ -12,11 +12,15 @@ const PaymentMethodCardsSection: FC = ({ 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) diff --git a/src/pages/settings/components/PhonesSection.tsx b/src/pages/settings/components/PhonesSection.tsx index c57b224..4fe7e08 100644 --- a/src/pages/settings/components/PhonesSection.tsx +++ b/src/pages/settings/components/PhonesSection.tsx @@ -12,9 +12,10 @@ const PhonesSection: FC = ({ 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])