Skip to content

Commit 7b0ebee

Browse files
committed
Revert "Merge pull request Expensify#65081 from callstack-internal/fix/remove-confirmation-sideEffect"
This reverts commit 65a490e, reversing changes made to 6284b90.
1 parent cb64fbb commit 7b0ebee

3 files changed

Lines changed: 32 additions & 72 deletions

File tree

src/libs/API/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,7 @@ const SIDE_EFFECT_REQUEST_COMMANDS = {
11591159
DISCONNECT_AS_DELEGATE: 'DisconnectAsDelegate',
11601160
COMPLETE_HYBRID_APP_ONBOARDING: 'CompleteHybridAppOnboarding',
11611161
CONNECT_POLICY_TO_QUICKBOOKS_DESKTOP: 'ConnectPolicyToQuickbooksDesktop',
1162+
BANK_ACCOUNT_CREATE_CORPAY: 'BankAccount_CreateCorpay',
11621163
MERGE_INTO_ACCOUNT_AND_LOGIN: 'MergeIntoAccountAndLogIn',
11631164

11641165
// PayMoneyRequestOnSearch only works online (pattern C) and we need to play the success sound only when the request is successful
@@ -1183,6 +1184,7 @@ type SideEffectRequestCommandParameters = {
11831184
[SIDE_EFFECT_REQUEST_COMMANDS.DISCONNECT_AS_DELEGATE]: EmptyObject;
11841185
[SIDE_EFFECT_REQUEST_COMMANDS.COMPLETE_HYBRID_APP_ONBOARDING]: EmptyObject;
11851186
[SIDE_EFFECT_REQUEST_COMMANDS.CONNECT_POLICY_TO_QUICKBOOKS_DESKTOP]: Parameters.ConnectPolicyToQuickBooksDesktopParams;
1187+
[SIDE_EFFECT_REQUEST_COMMANDS.BANK_ACCOUNT_CREATE_CORPAY]: Parameters.BankAccountCreateCorpayParams;
11861188
[SIDE_EFFECT_REQUEST_COMMANDS.PAY_MONEY_REQUEST_ON_SEARCH]: Parameters.PayMoneyRequestOnSearchParams;
11871189
[SIDE_EFFECT_REQUEST_COMMANDS.MERGE_INTO_ACCOUNT_AND_LOGIN]: Parameters.MergeIntoAccountAndLogInParams;
11881190
[SIDE_EFFECT_REQUEST_COMMANDS.LOG_OUT]: Parameters.LogOutParams;

src/libs/actions/BankAccounts.ts

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import type {
1616
} from '@libs/API/parameters';
1717
import type {SaveCorpayOnboardingCompanyDetails} from '@libs/API/parameters/SaveCorpayOnboardingCompanyDetailsParams';
1818
import type SaveCorpayOnboardingDirectorInformationParams from '@libs/API/parameters/SaveCorpayOnboardingDirectorInformationParams';
19-
import {READ_COMMANDS, WRITE_COMMANDS} from '@libs/API/types';
19+
import {READ_COMMANDS, SIDE_EFFECT_REQUEST_COMMANDS, WRITE_COMMANDS} from '@libs/API/types';
2020
import {getMicroSecondOnyxErrorWithTranslationKey} from '@libs/ErrorUtils';
2121
import {translateLocal} from '@libs/Localize';
2222
import Navigation from '@libs/Navigation/Navigation';
@@ -916,51 +916,8 @@ function createCorpayBankAccountForWalletFlow(data: InternationalBankAccountForm
916916
country: data.bankCountry,
917917
currency: data.bankCurrency,
918918
};
919-
920-
const parameters = {
921-
isWithdrawal: false,
922-
isSavings: true,
923-
inputs: JSON.stringify(inputData),
924-
};
925-
926-
const onyxData: OnyxData = {
927-
optimisticData: [
928-
{
929-
onyxMethod: Onyx.METHOD.MERGE,
930-
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
931-
value: {
932-
isLoading: true,
933-
isCreateCorpayBankAccount: true,
934-
},
935-
},
936-
],
937-
successData: [
938-
{
939-
onyxMethod: Onyx.METHOD.MERGE,
940-
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
941-
value: {
942-
isLoading: false,
943-
isCreateCorpayBankAccount: false,
944-
errors: null,
945-
isSuccess: true,
946-
},
947-
},
948-
],
949-
failureData: [
950-
{
951-
onyxMethod: Onyx.METHOD.MERGE,
952-
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
953-
value: {
954-
isLoading: false,
955-
isCreateCorpayBankAccount: false,
956-
isSuccess: false,
957-
errors: getMicroSecondOnyxErrorWithTranslationKey('walletPage.addBankAccountFailure'),
958-
},
959-
},
960-
],
961-
};
962-
963-
return API.write(WRITE_COMMANDS.BANK_ACCOUNT_CREATE_CORPAY, parameters, onyxData);
919+
// eslint-disable-next-line rulesdir/no-api-side-effects-method
920+
return API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.BANK_ACCOUNT_CREATE_CORPAY, {isWithdrawal: false, isSavings: true, inputs: JSON.stringify(inputData)});
964921
}
965922

966923
export {

src/pages/settings/Wallet/InternationalDepositAccount/substeps/Confirmation.tsx

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {useCallback, useEffect} from 'react';
1+
import React, {useCallback, useState} from 'react';
22
import CheckboxWithLabel from '@components/CheckboxWithLabel';
33
import FormProvider from '@components/Form/FormProvider';
44
import InputWrapper from '@components/Form/InputWrapper';
@@ -13,9 +13,8 @@ import useNetwork from '@hooks/useNetwork';
1313
import useOnyx from '@hooks/useOnyx';
1414
import useThemeStyles from '@hooks/useThemeStyles';
1515
import {getCurrencySymbol} from '@libs/CurrencyUtils';
16-
import {getLatestErrorMessage} from '@libs/ErrorUtils';
1716
import type CustomSubStepProps from '@pages/settings/Wallet/InternationalDepositAccount/types';
18-
import {clearReimbursementAccountBankCreation, createCorpayBankAccountForWalletFlow} from '@userActions/BankAccounts';
17+
import {createCorpayBankAccountForWalletFlow} from '@userActions/BankAccounts';
1918
import CONST from '@src/CONST';
2019
import type {TranslationPaths} from '@src/languages/types';
2120
import ONYXKEYS from '@src/ONYXKEYS';
@@ -45,8 +44,9 @@ function TermsAndConditionsLabel() {
4544
function 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

Comments
 (0)