1- import React , { useCallback , useEffect } from 'react' ;
1+ import React , { useCallback , useState } from 'react' ;
22import CheckboxWithLabel from '@components/CheckboxWithLabel' ;
33import FormProvider from '@components/Form/FormProvider' ;
44import InputWrapper from '@components/Form/InputWrapper' ;
@@ -13,9 +13,8 @@ import useNetwork from '@hooks/useNetwork';
1313import useOnyx from '@hooks/useOnyx' ;
1414import useThemeStyles from '@hooks/useThemeStyles' ;
1515import { getCurrencySymbol } from '@libs/CurrencyUtils' ;
16- import { getLatestErrorMessage } from '@libs/ErrorUtils' ;
1716import type CustomSubStepProps from '@pages/settings/Wallet/InternationalDepositAccount/types' ;
18- import { clearReimbursementAccountBankCreation , createCorpayBankAccountForWalletFlow } from '@userActions/BankAccounts' ;
17+ import { createCorpayBankAccountForWalletFlow } from '@userActions/BankAccounts' ;
1918import CONST from '@src/CONST' ;
2019import type { TranslationPaths } from '@src/languages/types' ;
2120import ONYXKEYS from '@src/ONYXKEYS' ;
@@ -45,8 +44,9 @@ function TermsAndConditionsLabel() {
4544function Confirmation ( { onNext, onMove, formValues, fieldsMap} : CustomSubStepProps ) {
4645 const { translate} = useLocalize ( ) ;
4746 const styles = useThemeStyles ( ) ;
47+ const [ isSubmitting , setIsSubmitting ] = useState ( false ) ;
48+ const [ error , setError ] = useState ( '' ) ;
4849 const [ corpayFields ] = useOnyx ( ONYXKEYS . CORPAY_FIELDS , { canBeMissing : false } ) ;
49- const [ reimbursementAccount ] = useOnyx ( ONYXKEYS . REIMBURSEMENT_ACCOUNT , { canBeMissing : false } ) ;
5050 const { isOffline} = useNetwork ( ) ;
5151
5252 const getTitle = ( field : CorpayFormField , fieldName : string ) => {
@@ -62,20 +62,25 @@ function Confirmation({onNext, onMove, formValues, fieldsMap}: CustomSubStepProp
6262 } ;
6363
6464 const getDataAndGoToNextStep = ( values : FormOnyxValues < typeof ONYXKEYS . FORMS . INTERNATIONAL_BANK_ACCOUNT_FORM > ) => {
65- createCorpayBankAccountForWalletFlow ( { ...formValues , ...values } , corpayFields ?. classification ?? '' , corpayFields ?. destinationCountry ?? '' , corpayFields ?. preferredMethod ?? '' ) ;
65+ setError ( '' ) ;
66+ setIsSubmitting ( true ) ;
67+ createCorpayBankAccountForWalletFlow (
68+ { ...formValues , ...values } ,
69+ corpayFields ?. classification ?? '' ,
70+ corpayFields ?. destinationCountry ?? '' ,
71+ corpayFields ?. preferredMethod ?? '' ,
72+ ) . then ( ( response ) => {
73+ setIsSubmitting ( false ) ;
74+ if ( response ?. jsonCode ) {
75+ if ( response . jsonCode === CONST . JSON_CODE . SUCCESS ) {
76+ onNext ( ) ;
77+ } else {
78+ setError ( response . message ?? '' ) ;
79+ }
80+ }
81+ } ) ;
6682 } ;
6783
68- useEffect ( ( ) => {
69- if ( reimbursementAccount ?. isLoading === true || ! ! reimbursementAccount ?. errors ) {
70- return ;
71- }
72-
73- if ( reimbursementAccount ?. isSuccess === true ) {
74- onNext ( ) ;
75- clearReimbursementAccountBankCreation ( ) ;
76- }
77- } , [ reimbursementAccount ?. isLoading , reimbursementAccount ?. isSuccess , reimbursementAccount ?. errors , onNext ] ) ;
78-
7984 const summaryItems : MenuItemProps [ ] = [
8085 {
8186 description : translate ( 'common.country' ) ,
@@ -157,8 +162,6 @@ function Confirmation({onNext, onMove, formValues, fieldsMap}: CustomSubStepProp
157162 [ translate ] ,
158163 ) ;
159164
160- const errorMessage = getLatestErrorMessage ( reimbursementAccount ) ;
161-
162165 return (
163166 < ScrollView contentContainerStyle = { styles . flexGrow1 } >
164167 < Text style = { [ styles . textHeadlineLineHeightXXL , styles . ph5 , styles . mb3 ] } > { translate ( 'addPersonalBankAccount.confirmationStepHeader' ) } </ Text >
@@ -182,7 +185,7 @@ function Confirmation({onNext, onMove, formValues, fieldsMap}: CustomSubStepProp
182185 submitButtonText = { translate ( 'common.confirm' ) }
183186 style = { [ styles . mh5 , styles . flexGrow1 ] }
184187 enabledWhenOffline = { false }
185- isLoading = { reimbursementAccount ?. isLoading }
188+ isLoading = { isSubmitting }
186189 shouldHideFixErrorsAlert
187190 >
188191 < InputWrapper
@@ -193,13 +196,11 @@ function Confirmation({onNext, onMove, formValues, fieldsMap}: CustomSubStepProp
193196 style = { [ styles . mt3 ] }
194197 shouldSaveDraft
195198 />
196- { ! ! errorMessage && (
197- < FormHelpMessage
198- style = { [ styles . mt3 , styles . mbn1 ] }
199- isError
200- message = { errorMessage }
201- />
202- ) }
199+ < FormHelpMessage
200+ style = { [ styles . mt3 , styles . mbn1 ] }
201+ isError
202+ message = { error }
203+ />
203204 </ FormProvider >
204205 </ ScrollView >
205206 ) ;
0 commit comments