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

fix: remove add bank account page from central pane mapping #50228

Merged
merged 7 commits into from
Oct 14, 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
2 changes: 1 addition & 1 deletion src/components/SettlementButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ function SettlementButton({

if (iouPaymentType === CONST.IOU.PAYMENT_TYPE.EXPENSIFY || iouPaymentType === CONST.IOU.PAYMENT_TYPE.VBBA) {
if (!isUserValidated) {
Navigation.navigate(ROUTES.SETTINGS_WALLET_VERIFY_ACCOUNT.getRoute());
Navigation.navigate(ROUTES.SETTINGS_WALLET_VERIFY_ACCOUNT.getRoute(ROUTES.SETTINGS_ADD_BANK_ACCOUNT));
return;
}
triggerKYCFlow(event, iouPaymentType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const CENTRAL_PANE_TO_RHP_MAPPING: Partial<Record<CentralPaneName, string[]>> =
SCREENS.SETTINGS.WALLET.REPORT_VIRTUAL_CARD_FRAUD,
SCREENS.SETTINGS.WALLET.CARDS_DIGITAL_DETAILS_UPDATE_ADDRESS,
SCREENS.SETTINGS.WALLET.VERIFY_ACCOUNT,
SCREENS.SETTINGS.ADD_BANK_ACCOUNT,
],
[SCREENS.SETTINGS.SECURITY]: [
SCREENS.SETTINGS.TWO_FACTOR_AUTH,
Expand Down
5 changes: 4 additions & 1 deletion src/libs/actions/BankAccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,14 @@ function setPlaidEvent(eventName: string | null) {
/**
* Open the personal bank account setup flow, with an optional exitReportID to redirect to once the flow is finished.
*/
function openPersonalBankAccountSetupView(exitReportID?: string) {
function openPersonalBankAccountSetupView(exitReportID?: string, isUserValidated = true) {
clearPlaid().then(() => {
if (exitReportID) {
Onyx.merge(ONYXKEYS.PERSONAL_BANK_ACCOUNT, {exitReportID});
}
if (!isUserValidated) {
Navigation.navigate(ROUTES.SETTINGS_WALLET_VERIFY_ACCOUNT.getRoute(ROUTES.SETTINGS_ADD_BANK_ACCOUNT));
}
Navigation.navigate(ROUTES.SETTINGS_ADD_BANK_ACCOUNT);
});
}
Expand Down
22 changes: 19 additions & 3 deletions src/pages/AddPersonalBankAccountPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import * as BankAccounts from '@userActions/BankAccounts';
import * as PaymentMethods from '@userActions/PaymentMethods';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import SCREENS from '@src/SCREENS';
import INPUT_IDS from '@src/types/form/ReimbursementAccountForm';

function AddPersonalBankAccountPage() {
Expand All @@ -25,6 +26,21 @@ function AddPersonalBankAccountPage() {
const [personalBankAccount] = useOnyx(ONYXKEYS.PERSONAL_BANK_ACCOUNT);
const [plaidData] = useOnyx(ONYXKEYS.PLAID_DATA);
const shouldShowSuccess = personalBankAccount?.shouldShowSuccess ?? false;
const topMostCentralPane = Navigation.getTopMostCentralPaneRouteFromRootState();

const goBack = useCallback(() => {
switch (topMostCentralPane?.name) {
case SCREENS.SETTINGS.WALLET.ROOT:
Navigation.goBack(ROUTES.SETTINGS_WALLET, true);
break;
case SCREENS.REPORT:
Navigation.closeRHPFlow();
break;
default:
Navigation.goBack();
break;
}
}, [topMostCentralPane]);

const submitBankAccountForm = useCallback(() => {
const bankAccounts = plaidData?.bankAccounts ?? [];
Expand All @@ -45,10 +61,10 @@ function AddPersonalBankAccountPage() {
} else if (shouldContinue && onSuccessFallbackRoute) {
PaymentMethods.continueSetup(onSuccessFallbackRoute);
} else {
Navigation.navigate(ROUTES.SETTINGS_WALLET);
goBack();
}
},
[personalBankAccount],
[personalBankAccount, goBack],
);

useEffect(() => BankAccounts.clearPersonalBankAccount, []);
Expand Down Expand Up @@ -90,7 +106,7 @@ function AddPersonalBankAccountPage() {
text={translate('walletPage.chooseAccountBody')}
plaidData={plaidData}
isDisplayedInWalletFlow
onExitPlaid={() => Navigation.navigate(ROUTES.SETTINGS_WALLET)}
onExitPlaid={goBack}
receivedRedirectURI={getPlaidOAuthReceivedRedirectURI()}
selectedPlaidAccountID={selectedPlaidAccountId}
/>
Expand Down
39 changes: 8 additions & 31 deletions src/pages/EnablePayments/AddBankAccount/AddBankAccount.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, {useCallback} from 'react';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import InteractiveStepSubHeader from '@components/InteractiveStepSubHeader';
import ScreenWrapper from '@components/ScreenWrapper';
Expand All @@ -16,26 +15,15 @@ import * as Wallet from '@userActions/Wallet';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {PersonalBankAccountForm} from '@src/types/form';
import type {PersonalBankAccount, PlaidData} from '@src/types/onyx';
import SetupMethod from './SetupMethod';
import Confirmation from './substeps/ConfirmationStep';
import Plaid from './substeps/PlaidStep';

type AddPersonalBankAccountPageWithOnyxProps = {
/** Contains plaid data */
plaidData: OnyxEntry<PlaidData>;

/** The details about the Personal bank account we are adding saved in Onyx */
personalBankAccount: OnyxEntry<PersonalBankAccount>;

/** The draft values of the bank account being setup */
personalBankAccountDraft: OnyxEntry<PersonalBankAccountForm>;
};

const plaidSubsteps: Array<React.ComponentType<SubStepProps>> = [Plaid, Confirmation];

function AddBankAccount({personalBankAccount, plaidData, personalBankAccountDraft}: AddPersonalBankAccountPageWithOnyxProps) {
function AddBankAccount() {
const [plaidData] = useOnyx(ONYXKEYS.PLAID_DATA);
const [personalBankAccount] = useOnyx(ONYXKEYS.PERSONAL_BANK_ACCOUNT);
const [personalBankAccountDraft] = useOnyx(ONYXKEYS.FORMS.PERSONAL_BANK_ACCOUNT_FORM_DRAFT);
const {translate} = useLocalize();
const styles = useThemeStyles();

Expand Down Expand Up @@ -64,7 +52,7 @@ function AddBankAccount({personalBankAccount, plaidData, personalBankAccountDraf
PaymentMethods.continueSetup(onSuccessFallbackRoute);
return;
}
Navigation.goBack();
Navigation.goBack(ROUTES.SETTINGS_WALLET, true);
};

const handleBackButtonPress = () => {
Expand All @@ -75,7 +63,7 @@ function AddBankAccount({personalBankAccount, plaidData, personalBankAccountDraf
if (screenIndex === 0) {
BankAccounts.clearPersonalBankAccount();
Wallet.updateCurrentStep(null);
Navigation.goBack(ROUTES.SETTINGS_WALLET);
Navigation.goBack(ROUTES.SETTINGS_WALLET, true);
return;
}
prevScreen();
Expand Down Expand Up @@ -118,15 +106,4 @@ function AddBankAccount({personalBankAccount, plaidData, personalBankAccountDraf

AddBankAccount.displayName = 'AddBankAccountPage';

export default withOnyx<AddPersonalBankAccountPageWithOnyxProps, AddPersonalBankAccountPageWithOnyxProps>({
plaidData: {
key: ONYXKEYS.PLAID_DATA,
},
// @ts-expect-error: ONYXKEYS.PERSONAL_BANK_ACCOUNT is conflicting with ONYXKEYS.FORMS.PERSONAL_BANK_ACCOUNT_FORM
personalBankAccount: {
key: ONYXKEYS.PERSONAL_BANK_ACCOUNT,
},
personalBankAccountDraft: {
key: ONYXKEYS.FORMS.PERSONAL_BANK_ACCOUNT_FORM_DRAFT,
},
})(AddBankAccount);
export default AddBankAccount;
2 changes: 1 addition & 1 deletion src/pages/EnablePayments/EnablePayments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function EnablePaymentsPage() {
>
<HeaderWithBackButton
title={translate('personalInfoStep.personalInfo')}
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_WALLET)}
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_WALLET, true)}
/>
<FailedKYC />
</ScreenWrapper>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/home/report/ReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ function ReportActionItem({
const popoverAnchorRef = useRef<Exclude<ReportActionContextMenu.ContextMenuAnchor, TextInput>>(null);
const downloadedPreviews = useRef<string[]>([]);
const prevDraftMessage = usePrevious(draftMessage);
const [isUserValidated] = useOnyx(ONYXKEYS.USER, {selector: (user) => !!user?.validated});
const {canUseP2PDistanceRequests} = usePermissions();

// The app would crash due to subscribing to the entire report collection if parentReportID is an empty string. So we should have a fallback ID here.
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID || -1}`);
Expand Down Expand Up @@ -606,7 +606,7 @@ function ReportActionItem({
success
style={[styles.w100, styles.requestPreviewBox]}
text={translate('bankAccount.addBankAccount')}
onPress={() => BankAccounts.openPersonalBankAccountSetupView(Navigation.getTopmostReportId() ?? linkedReport?.reportID)}
onPress={() => BankAccounts.openPersonalBankAccountSetupView(Navigation.getTopmostReportId() ?? linkedReport?.reportID, isUserValidated)}
pressOnEnter
large
/>
Expand Down
Loading