-
Notifications
You must be signed in to change notification settings - Fork 3.2k
feat: BankInfo step #31121
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
Merged
mountiny
merged 17 commits into
Expensify:vit-tieredBankAccountFlow
from
MrMuzyk:michal/bank-info-screen
Nov 17, 2023
Merged
feat: BankInfo step #31121
Changes from 3 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
02f287e
feat: BankInfo step
MrMuzyk 88b7cee
Merge branch 'vit-tieredBankAccountFlow' of https://github.com/Expens…
MrMuzyk a1348cb
fix: remove console logs
MrMuzyk 25496b4
feat: cr fixes
MrMuzyk 07ff1f2
feat: more fixes
MrMuzyk 2d5e60c
feat: revert podfile change
MrMuzyk 0e3fbe3
Merge branch 'vit-tieredBankAccountFlow' of https://github.com/Expens…
MrMuzyk 6bc3c42
fix: linter fix
MrMuzyk 97b5227
fix: cr fixes
MrMuzyk 48c9996
fix: change to input mode
MrMuzyk 0f3ef94
feat: accessibility changes
MrMuzyk 048dfdc
Merge branch 'vit-tieredBankAccountFlow' of https://github.com/Expens…
MrMuzyk a066221
feat: update util function
MrMuzyk bf43cc4
fix: fixed edge cases
MrMuzyk 1088c04
feat: add text for plaid
MrMuzyk 3ae88d7
Merge branch 'vit-tieredBankAccountFlow' of https://github.com/Expens…
MrMuzyk 42ae28e
fix: prettier fix
MrMuzyk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import lodashGet from 'lodash/get'; | ||
import PropTypes from 'prop-types'; | ||
import React, {useCallback, useMemo} from 'react'; | ||
import {View} from 'react-native'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import HeaderWithBackButton from '@components/HeaderWithBackButton'; | ||
import InteractiveStepSubHeader from '@components/InteractiveStepSubHeader'; | ||
import ScreenWrapper from '@components/ScreenWrapper'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import useSubStep from '@hooks/useSubStep'; | ||
import getPlaidOAuthReceivedRedirectURI from '@libs/getPlaidOAuthReceivedRedirectURI'; | ||
import reimbursementAccountDraftPropTypes from '@pages/ReimbursementAccount/ReimbursementAccountDraftPropTypes'; | ||
import {reimbursementAccountPropTypes} from '@pages/ReimbursementAccount/reimbursementAccountPropTypes'; | ||
import * as ReimbursementAccountProps from '@pages/ReimbursementAccount/reimbursementAccountPropTypes'; | ||
import getDefaultValueForReimbursementAccountField from '@pages/ReimbursementAccount/utils/getDefaultValueForReimbursementAccountField'; | ||
import getInitialSubstepForBankInfo from '@pages/ReimbursementAccount/utils/getInitialSubstepForBankInfo'; | ||
import getSubstepValues from '@pages/ReimbursementAccount/utils/getSubstepValues'; | ||
import styles from '@styles/styles'; | ||
import * as BankAccounts from '@userActions/BankAccounts'; | ||
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import Confirmation from './substeps/Confirmation'; | ||
import Manual from './substeps/Manual'; | ||
import Plaid from './substeps/Plaid'; | ||
|
||
const propTypes = { | ||
/** Plaid SDK token to use to initialize the widget */ | ||
plaidLinkToken: PropTypes.string, | ||
|
||
/** Reimbursement account from ONYX */ | ||
reimbursementAccount: reimbursementAccountPropTypes, | ||
|
||
/** The draft values of the bank account being setup */ | ||
reimbursementAccountDraft: reimbursementAccountDraftPropTypes, | ||
}; | ||
|
||
const defaultProps = { | ||
plaidLinkToken: '', | ||
reimbursementAccount: ReimbursementAccountProps.reimbursementAccountDefaultProps, | ||
reimbursementAccountDraft: {}, | ||
}; | ||
|
||
const STEPS_HEADER_HEIGHT = 40; | ||
// TODO Will most likely come from different place | ||
const STEP_NAMES = ['1', '2', '3', '4', '5']; | ||
|
||
const bankInfoStepKeys = CONST.BANK_ACCOUNT.BANK_INFO_STEP.INPUT_KEY; | ||
const manualSubsteps = [Manual, Confirmation]; | ||
const plaidSubsteps = [Plaid, Confirmation]; | ||
const receivedRedirectURI = getPlaidOAuthReceivedRedirectURI(); | ||
|
||
function BankInfo({reimbursementAccount, reimbursementAccountDraft, plaidLinkToken}) { | ||
const {translate} = useLocalize(); | ||
|
||
const values = useMemo(() => getSubstepValues(bankInfoStepKeys, reimbursementAccountDraft, reimbursementAccount), [reimbursementAccount, reimbursementAccountDraft]); | ||
|
||
let setupType = getDefaultValueForReimbursementAccountField(reimbursementAccount, 'subStep'); | ||
|
||
const shouldReinitializePlaidLink = plaidLinkToken && receivedRedirectURI && setupType !== CONST.BANK_ACCOUNT.SUBSTEP.MANUAL; | ||
if (shouldReinitializePlaidLink) { | ||
setupType = CONST.BANK_ACCOUNT.SETUP_TYPE.PLAID; | ||
} | ||
|
||
const startFrom = useMemo(() => getInitialSubstepForBankInfo(values, setupType), [setupType, values]); | ||
|
||
const submit = useCallback(() => { | ||
if (setupType === CONST.BANK_ACCOUNT.SETUP_TYPE.MANUAL) { | ||
BankAccounts.connectBankAccountManually( | ||
lodashGet(reimbursementAccount, 'achData', bankInfoStepKeys.BANK_ACCOUNT_ID) || 0, | ||
MrMuzyk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
values[bankInfoStepKeys.ACCOUNT_NUMBER], | ||
values[bankInfoStepKeys.ROUTING_NUMBER], | ||
values[bankInfoStepKeys.PLAID_MASK], | ||
); | ||
} else if (setupType === CONST.BANK_ACCOUNT.SETUP_TYPE.PLAID) { | ||
const bankAccountID = lodashGet(reimbursementAccount, 'achData.bankAccountID') || 0; | ||
MrMuzyk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
BankAccounts.connectBankAccountWithPlaid(bankAccountID, { | ||
[bankInfoStepKeys.ROUTING_NUMBER]: values[bankInfoStepKeys.ROUTING_NUMBER], | ||
[bankInfoStepKeys.ACCOUNT_NUMBER]: values[bankInfoStepKeys.ACCOUNT_NUMBER], | ||
[bankInfoStepKeys.PLAID_MASK]: values[bankInfoStepKeys.PLAID_MASK], | ||
[bankInfoStepKeys.IS_SAVINGS]: values[bankInfoStepKeys.IS_SAVINGS], | ||
[bankInfoStepKeys.BANK_NAME]: values[bankInfoStepKeys.BANK_NAME], | ||
[bankInfoStepKeys.PLAID_ACCOUNT_ID]: values[bankInfoStepKeys.PLAID_ACCOUNT_ID], | ||
[bankInfoStepKeys.PLAID_ACCESS_TOKEN]: values[bankInfoStepKeys.PLAID_ACCESS_TOKEN], | ||
}); | ||
} | ||
}, [reimbursementAccount, setupType, values]); | ||
|
||
const bodyContent = setupType === CONST.BANK_ACCOUNT.SETUP_TYPE.PLAID ? plaidSubsteps : manualSubsteps; | ||
const {componentToRender: SubStep, isEditing, screenIndex, nextScreen, prevScreen, moveTo} = useSubStep({bodyContent, startFrom, onFinished: submit}); | ||
|
||
const handleBackButtonPress = () => { | ||
if (screenIndex === 0) { | ||
// TODO replace it with navigation to ReimbursementAccountPage once base is updated | ||
BankAccounts.setBankAccountSubStep(null); | ||
} else { | ||
prevScreen(); | ||
} | ||
}; | ||
|
||
return ( | ||
<ScreenWrapper testID={BankInfo.displayName}> | ||
<HeaderWithBackButton | ||
shouldShowBackButton={!(setupType === CONST.BANK_ACCOUNT.SETUP_TYPE.PLAID && screenIndex === 0)} | ||
onBackButtonPress={handleBackButtonPress} | ||
title={translate('personalInfoStep.personalInfo')} | ||
/> | ||
<View style={[styles.ph5, styles.mv3, {height: STEPS_HEADER_HEIGHT}]}> | ||
<InteractiveStepSubHeader | ||
onStepSelected={() => {}} | ||
// TODO Will be replaced with proper values | ||
startStep={0} | ||
stepNames={STEP_NAMES} | ||
/> | ||
</View> | ||
<SubStep | ||
isEditing={isEditing} | ||
onNext={nextScreen} | ||
onMove={moveTo} | ||
/> | ||
</ScreenWrapper> | ||
); | ||
} | ||
|
||
BankInfo.propTypes = propTypes; | ||
BankInfo.defaultProps = defaultProps; | ||
BankInfo.displayName = 'BankInfo'; | ||
|
||
export default withOnyx({ | ||
reimbursementAccount: { | ||
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT, | ||
}, | ||
reimbursementAccountDraft: { | ||
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT_DRAFT, | ||
}, | ||
plaidLinkToken: { | ||
key: ONYXKEYS.PLAID_LINK_TOKEN, | ||
}, | ||
})(BankInfo); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.