-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Refactor bank account creation logic and remove side-effect command #65081
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
Changes from all commits
e3c0146
6edb0dc
7333357
3cbbad0
9533d39
af02aa0
fddfd9f
62b1efc
c477980
99ae8ce
ac26bbd
4e25ccb
b24b2c6
6f2d18f
f8e834d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import React, {useCallback, useState} from 'react'; | ||
| import React, {useCallback, useEffect} from 'react'; | ||
| import CheckboxWithLabel from '@components/CheckboxWithLabel'; | ||
| import FormProvider from '@components/Form/FormProvider'; | ||
| import InputWrapper from '@components/Form/InputWrapper'; | ||
|
|
@@ -13,8 +13,9 @@ import useNetwork from '@hooks/useNetwork'; | |
| import useOnyx from '@hooks/useOnyx'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import {getCurrencySymbol} from '@libs/CurrencyUtils'; | ||
| import {getLatestErrorMessage} from '@libs/ErrorUtils'; | ||
| import type CustomSubStepProps from '@pages/settings/Wallet/InternationalDepositAccount/types'; | ||
| import {createCorpayBankAccountForWalletFlow} from '@userActions/BankAccounts'; | ||
| import {clearReimbursementAccountBankCreation, createCorpayBankAccountForWalletFlow} from '@userActions/BankAccounts'; | ||
| import CONST from '@src/CONST'; | ||
| import type {TranslationPaths} from '@src/languages/types'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
|
|
@@ -44,9 +45,8 @@ function TermsAndConditionsLabel() { | |
| function Confirmation({onNext, onMove, formValues, fieldsMap}: CustomSubStepProps) { | ||
| const {translate} = useLocalize(); | ||
| const styles = useThemeStyles(); | ||
| const [isSubmitting, setIsSubmitting] = useState(false); | ||
| const [error, setError] = useState(''); | ||
| const [corpayFields] = useOnyx(ONYXKEYS.CORPAY_FIELDS, {canBeMissing: false}); | ||
| const [reimbursementAccount] = useOnyx(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {canBeMissing: false}); | ||
| const {isOffline} = useNetwork(); | ||
|
|
||
| const getTitle = (field: CorpayFormField, fieldName: string) => { | ||
|
|
@@ -62,25 +62,20 @@ function Confirmation({onNext, onMove, formValues, fieldsMap}: CustomSubStepProp | |
| }; | ||
|
|
||
| const getDataAndGoToNextStep = (values: FormOnyxValues<typeof ONYXKEYS.FORMS.INTERNATIONAL_BANK_ACCOUNT_FORM>) => { | ||
| setError(''); | ||
| setIsSubmitting(true); | ||
| createCorpayBankAccountForWalletFlow( | ||
| {...formValues, ...values}, | ||
| corpayFields?.classification ?? '', | ||
| corpayFields?.destinationCountry ?? '', | ||
| corpayFields?.preferredMethod ?? '', | ||
| ).then((response) => { | ||
| setIsSubmitting(false); | ||
| if (response?.jsonCode) { | ||
| if (response.jsonCode === CONST.JSON_CODE.SUCCESS) { | ||
| onNext(); | ||
| } else { | ||
| setError(response.message ?? ''); | ||
| } | ||
| } | ||
| }); | ||
| createCorpayBankAccountForWalletFlow({...formValues, ...values}, corpayFields?.classification ?? '', corpayFields?.destinationCountry ?? '', corpayFields?.preferredMethod ?? ''); | ||
| }; | ||
|
|
||
| useEffect(() => { | ||
| if (reimbursementAccount?.isLoading === true || !!reimbursementAccount?.errors) { | ||
| return; | ||
| } | ||
|
|
||
| if (reimbursementAccount?.isSuccess === true) { | ||
| onNext(); | ||
| clearReimbursementAccountBankCreation(); | ||
| } | ||
| }, [reimbursementAccount?.isLoading, reimbursementAccount?.isSuccess, reimbursementAccount?.errors, onNext]); | ||
|
|
||
| const summaryItems: MenuItemProps[] = [ | ||
| { | ||
| description: translate('common.country'), | ||
|
|
@@ -162,6 +157,8 @@ function Confirmation({onNext, onMove, formValues, fieldsMap}: CustomSubStepProp | |
| [translate], | ||
| ); | ||
|
|
||
| const errorMessage = getLatestErrorMessage(reimbursementAccount); | ||
|
|
||
| return ( | ||
| <ScrollView contentContainerStyle={styles.flexGrow1}> | ||
| <Text style={[styles.textHeadlineLineHeightXXL, styles.ph5, styles.mb3]}>{translate('addPersonalBankAccount.confirmationStepHeader')}</Text> | ||
|
|
@@ -185,7 +182,7 @@ function Confirmation({onNext, onMove, formValues, fieldsMap}: CustomSubStepProp | |
| submitButtonText={translate('common.confirm')} | ||
| style={[styles.mh5, styles.flexGrow1]} | ||
| enabledWhenOffline={false} | ||
| isLoading={isSubmitting} | ||
| isLoading={reimbursementAccount?.isLoading} | ||
| shouldHideFixErrorsAlert | ||
| > | ||
| <InputWrapper | ||
|
|
@@ -196,11 +193,13 @@ function Confirmation({onNext, onMove, formValues, fieldsMap}: CustomSubStepProp | |
| style={[styles.mt3]} | ||
| shouldSaveDraft | ||
| /> | ||
| <FormHelpMessage | ||
| style={[styles.mt3, styles.mbn1]} | ||
| isError | ||
| message={error} | ||
| /> | ||
|
Comment on lines
-199
to
-203
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you remove this component? Don't we need to handle error?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| {!!errorMessage && ( | ||
| <FormHelpMessage | ||
| style={[styles.mt3, styles.mbn1]} | ||
| isError | ||
| message={errorMessage} | ||
| /> | ||
| )} | ||
| </FormProvider> | ||
| </ScrollView> | ||
| ); | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add errors field in failureData?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, errors should come from the API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pasyukevich I mean a general error, such as
getMicroSecondOnyxErrorWithTranslationKey('walletPage.addBankAccountFailure'), in case the API doesn't work properly, it will serve as a backup error.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated