Skip to content

Commit

Permalink
fix: support errors
Browse files Browse the repository at this point in the history
  • Loading branch information
keellyp committed Jan 24, 2025
1 parent d1dc4cf commit 8d65fbe
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/pages/CreatePayment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { gql } from '@apollo/client'
import { InputAdornment } from '@mui/material'
import { useFormik } from 'formik'
import { DateTime } from 'luxon'
import { useCallback, useMemo, useRef } from 'react'
import { useCallback, useEffect, useMemo, useRef } from 'react'
import { generatePath, useNavigate, useParams } from 'react-router-dom'
import { date, object, string } from 'yup'

Expand Down Expand Up @@ -106,7 +106,7 @@ const CreatePayment = () => {

const currency = invoice?.currency ?? CurrencyEnum.Usd

const [createPayment] = useCreatePaymentMutation({
const [createPayment, { error: createError }] = useCreatePaymentMutation({
context: { silentErrorCodes: [LagoApiError.UnprocessableEntity] },
onCompleted({ createPayment: createdPayment }) {
if (!!createdPayment) {
Expand All @@ -120,6 +120,17 @@ const CreatePayment = () => {
},
})

useEffect(() => {
if (createError) {
const errorCode = createError.graphQLErrors[0].extensions?.details

formikProps.setErrors({
...formikProps.errors,
...(errorCode ?? {}),
})
}
}, [createError])

const maxAmount = useCallback(
(value: string) => {
const amount = Number(value)
Expand Down

0 comments on commit 8d65fbe

Please sign in to comment.