Skip to content
Draft
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
24 changes: 22 additions & 2 deletions src/pages/ReimbursementAccount/USD/BankInfo/BankInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import React, {useEffect, useRef} from 'react';
import {View} from 'react-native';
import ActivityIndicator from '@components/ActivityIndicator';
import InteractiveStepWrapper from '@components/InteractiveStepWrapper';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import useReimbursementAccountSubmitCallback from '@hooks/useReimbursementAccountSubmitCallback';
import useThemeStyles from '@hooks/useThemeStyles';
import getPlaidOAuthReceivedRedirectURI from '@libs/getPlaidOAuthReceivedRedirectURI';
import {getBankAccountIDAsNumber} from '@libs/ReimbursementAccountUtils';
import getSubStepValues from '@pages/ReimbursementAccount/utils/getSubStepValues';
Expand Down Expand Up @@ -30,6 +33,7 @@ const BANK_INFO_STEP_KEYS = INPUT_IDS.BANK_INFO_STEP;
const receivedRedirectURI = getPlaidOAuthReceivedRedirectURI();

function BankInfo({onBackButtonPress, onSubmit, policyID}: BankInfoProps) {
const styles = useThemeStyles();
const [reimbursementAccount] = useOnyx(ONYXKEYS.REIMBURSEMENT_ACCOUNT);
const [reimbursementAccountDraft] = useOnyx(ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM_DRAFT);
const [plaidLinkToken] = useOnyx(ONYXKEYS.RAM_ONLY_PLAID_LINK_TOKEN);
Expand Down Expand Up @@ -87,7 +91,23 @@ function BankInfo({onBackButtonPress, onSubmit, policyID}: BankInfoProps) {
markSubmitting();
};

const BankInfoPage = setupType === CONST.BANK_ACCOUNT.SETUP_TYPE.PLAID ? Plaid : Manual;
const renderBankInfo = () => {
switch (setupType) {
case CONST.BANK_ACCOUNT.SETUP_TYPE.PLAID:
return <Plaid onNext={submit} />;
case CONST.BANK_ACCOUNT.SETUP_TYPE.MANUAL:
return <Manual onNext={submit} />;
default:
return (
<View style={[styles.flex1, styles.alignItemsCenter, styles.justifyContentCenter]}>
<ActivityIndicator
size={CONST.ACTIVITY_INDICATOR_SIZE.LARGE}
reasonAttributes={{context: 'BankInfo'}}
/>
</View>
);
}
};

// Some services user connects to via Plaid return dummy account numbers and routing numbers e.g. Chase
// In this case we need to redirect user to manual flow to enter real account number and routing number
Expand Down Expand Up @@ -115,7 +135,7 @@ function BankInfo({onBackButtonPress, onSubmit, policyID}: BankInfoProps) {
startStepIndex={1}
stepNames={CONST.BANK_ACCOUNT.STEP_NAMES}
>
<BankInfoPage onNext={submit} />
{renderBankInfo()}
</InteractiveStepWrapper>
);
}
Expand Down
13 changes: 12 additions & 1 deletion src/pages/ReimbursementAccount/USD/BankInfo/subSteps/Plaid.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useIsFocused} from '@react-navigation/native';
import {useIsFocused, useRoute} from '@react-navigation/native';
import React, {useCallback, useEffect} from 'react';
import AddPlaidBankAccount from '@components/AddPlaidBankAccount';
import FormProvider from '@components/Form/FormProvider';
Expand All @@ -7,20 +7,30 @@ import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import usePrevious from '@hooks/usePrevious';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types';
import type {ReimbursementAccountNavigatorParamList} from '@libs/Navigation/types';
import {getBankAccountIDAsNumber} from '@libs/ReimbursementAccountUtils';
import type BankInfoSubStepProps from '@pages/ReimbursementAccount/USD/BankInfo/types';
import {setBankAccountSubStep, validatePlaidSelection} from '@userActions/BankAccounts';
import {updateReimbursementAccountDraft} from '@userActions/ReimbursementAccount';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import INPUT_IDS from '@src/types/form/ReimbursementAccountForm';

type ReimbursementAccountNavigatorRoute = PlatformStackRouteProp<ReimbursementAccountNavigatorParamList, typeof SCREENS.REIMBURSEMENT_ACCOUNT_USD>;

const BANK_INFO_STEP_KEYS = INPUT_IDS.BANK_INFO_STEP;

function Plaid({onNext}: BankInfoSubStepProps) {
const [reimbursementAccount] = useOnyx(ONYXKEYS.REIMBURSEMENT_ACCOUNT);
const [reimbursementAccountDraft] = useOnyx(ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM_DRAFT);
const [plaidData] = useOnyx(ONYXKEYS.PLAID_DATA);

const route = useRoute<ReimbursementAccountNavigatorRoute>();
const {policyID, backTo} = route?.params ?? {};

const {translate} = useLocalize();
const styles = useThemeStyles();
const isFocused = useIsFocused();
Expand Down Expand Up @@ -61,6 +71,7 @@ function Plaid({onNext}: BankInfoSubStepProps) {

const handlePlaidExit = () => {
setBankAccountSubStep(null);
Navigation.goBack(ROUTES.BANK_ACCOUNT_WITH_STEP_TO_OPEN.getRoute({policyID, backTo}));
};

return (
Expand Down
Loading