Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(form): use error returned form BE if available #6313

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading