Skip to content

Commit

Permalink
chore(form): use error returned form BE if available (#6313)
Browse files Browse the repository at this point in the history
  • Loading branch information
mperdomo-bc committed Mar 5, 2024
1 parent 421e39e commit 4a6e8f9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Header } from '../Header'
import { WIRE_BANK_FORM } from './constants'
import { FinalStatusWrapper } from './StepsStyles'

const Failure = ({ alreadyLinked }: { alreadyLinked: boolean }) => {
const Failure = ({ message, title }: { message?: string; title?: string }) => {
const dispatch = useDispatch()
const openModals = useSelector(getModals)

Expand All @@ -32,12 +32,11 @@ const Failure = ({ alreadyLinked }: { alreadyLinked: boolean }) => {
<Header />
<Icon color='error' name='close-circle' size='3rem' />
<Text size='20px' weight={600} color='grey900'>
Unable to add bank account
{title ?? 'Unable to add bank account'}
</Text>
<Text size='16px' weight={500} color='grey600'>
{alreadyLinked
? 'This account number is already linked. Please try linking another account'
: 'There was a problem adding your bank account details. Please try to again or add a different payment method.'}
{message ??
'There was a problem adding your bank account details. Please try to again or add a different payment method.'}
</Text>
</FinalStatusWrapper>
<FlyoutFooter collapsed>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const AddWireBank = () => {
data: { api }
} = useSelector(getDomains)

const alreadyLinked = useRef(false)
const errorInfo = useRef<{ message?: string; title?: string }>({})

const resetForm = () => {
dispatch(destroy(WIRE_BANK_FORM))
Expand Down Expand Up @@ -99,8 +99,8 @@ const AddWireBank = () => {
})
setStep('SUCCESS')
dispatch(custodial.fetchCustodialBeneficiaries({ currency: fiatCurrency }))
} catch (error) {
alreadyLinked.current = error.dataFields.description.includes('already exists')
} catch ({ message, title }) {
errorInfo.current = { message, title }
setStep('FAILURE')
}
}
Expand All @@ -124,7 +124,7 @@ const AddWireBank = () => {
case 'SUCCESS':
return <Success bankName={formValues?.bankName ?? ''} fiatCurrency={fiatCurrency} />
case 'FAILURE':
return <Failure alreadyLinked={alreadyLinked.current} />
return <Failure title={errorInfo.current.title} message={errorInfo.current.message} />
case 'USER_INFO':
default: {
const nextStep =
Expand Down

0 comments on commit 4a6e8f9

Please sign in to comment.