Skip to content

Commit

Permalink
fix: display error code
Browse files Browse the repository at this point in the history
  • Loading branch information
keellyp committed Dec 30, 2024
1 parent 36f12fc commit bc62272
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/pages/settings/Invoices/CreateCustomSection.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useFormik } from 'formik'
import { useRef, useState } from 'react'
import { useEffect, useRef, useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { boolean, object, string } from 'yup'

Expand All @@ -15,6 +15,7 @@ import {
PreviewCustomSectionDrawerRef,
} from '~/components/settings/invoices/PreviewCustomSectionDrawer'
import { WarningDialog, WarningDialogRef } from '~/components/WarningDialog'
import { FORM_ERRORS_ENUM } from '~/core/constants/form'
import { INVOICE_SETTINGS_ROUTE } from '~/core/router'
import { CreateInvoiceCustomSectionInput } from '~/generated/graphql'
import { useInternationalization } from '~/hooks/core/useInternationalization'
Expand All @@ -29,7 +30,8 @@ const CreateInvoiceCustomSection = () => {
const defaultCustomSectionDialogRef = useRef<DefaultCustomSectionDialogRef>(null)
const previewCustomSectionDrawerRef = useRef<PreviewCustomSectionDrawerRef>(null)

const { loading, isEdition, invoiceCustomSection, onSave } = useCreateEditInvoiceCustomSection()
const { loading, isEdition, invoiceCustomSection, onSave, errorCode } =
useCreateEditInvoiceCustomSection()

const formikProps = useFormik<CreateInvoiceCustomSectionInput>({
initialValues: {
Expand Down Expand Up @@ -74,6 +76,17 @@ const CreateInvoiceCustomSection = () => {
}
}

useEffect(() => {
if (errorCode === FORM_ERRORS_ENUM.existingCode) {
formikProps.setFieldError('code', 'text_632a2d437e341dcc76817556')
const rootElement = document.getElementById('root')

if (!rootElement) return
rootElement.scrollTo({ top: 0 })
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [errorCode])

return (
<>
<CenteredPage.Wrapper>
Expand Down

0 comments on commit bc62272

Please sign in to comment.