@@ -24,6 +24,7 @@ import CompanyStep from './CompanyStep';
24
24
import RequestorStep from './RequestorStep' ;
25
25
import ValidationStep from './ValidationStep' ;
26
26
import BeneficialOwnersStep from './BeneficialOwnersStep' ;
27
+ import ROUTES from '../../ROUTES' ;
27
28
import HeaderWithCloseButton from '../../components/HeaderWithCloseButton' ;
28
29
29
30
const propTypes = {
@@ -80,7 +81,30 @@ const defaultProps = {
80
81
81
82
class ReimbursementAccountPage extends React . Component {
82
83
componentDidMount ( ) {
83
- fetchFreePlanVerifiedBankAccount ( ) ;
84
+ // We can specify a step to navigate to by using route params when the component mounts.
85
+ fetchFreePlanVerifiedBankAccount ( this . getStepToOpenFromRouteParams ( ) ) ;
86
+ }
87
+
88
+ componentDidUpdate ( prevProps ) {
89
+ const currentStep = lodashGet (
90
+ this . props ,
91
+ 'reimbursementAccount.achData.currentStep' ,
92
+ CONST . BANK_ACCOUNT . STEP . BANK_ACCOUNT ,
93
+ ) ;
94
+ const previousStep = lodashGet (
95
+ prevProps ,
96
+ 'reimbursementAccount.achData.currentStep' ,
97
+ CONST . BANK_ACCOUNT . STEP . BANK_ACCOUNT ,
98
+ ) ;
99
+
100
+ if ( currentStep === previousStep ) {
101
+ return ;
102
+ }
103
+
104
+ // When the step changes we will navigate to update the route params. This is mostly cosmetic as we only use
105
+ // the route params when the component first mounts to jump to a specific route instead of picking up where the
106
+ // user left off in the flow.
107
+ Navigation . navigate ( ROUTES . getBankAccountRoute ( this . getRouteForCurrentStep ( currentStep ) ) ) ;
84
108
}
85
109
86
110
/**
@@ -103,6 +127,26 @@ class ReimbursementAccountPage extends React.Component {
103
127
}
104
128
}
105
129
130
+ /**
131
+ * @param {String } currentStep
132
+ * @returns {String }
133
+ */
134
+ getRouteForCurrentStep ( currentStep ) {
135
+ switch ( currentStep ) {
136
+ case CONST . BANK_ACCOUNT . STEP . COMPANY :
137
+ return 'company' ;
138
+ case CONST . BANK_ACCOUNT . STEP . REQUESTOR :
139
+ return 'requestor' ;
140
+ case CONST . BANK_ACCOUNT . STEP . ACH_CONTRACT :
141
+ return 'contract' ;
142
+ case CONST . BANK_ACCOUNT . STEP . VALIDATION :
143
+ return 'validate' ;
144
+ case CONST . BANK_ACCOUNT . STEP . BANK_ACCOUNT :
145
+ default :
146
+ return 'new' ;
147
+ }
148
+ }
149
+
106
150
render ( ) {
107
151
if ( ! Permissions . canUseFreePlan ( this . props . betas ) ) {
108
152
console . debug ( 'Not showing new bank account page because user is not on free plan beta' ) ;
@@ -156,9 +200,11 @@ class ReimbursementAccountPage extends React.Component {
156
200
const error = lodashGet ( this . props , 'reimbursementAccount.error' ) ;
157
201
const maxAttemptsReached = lodashGet ( this . props , 'reimbursementAccount.maxAttemptsReached' ) ;
158
202
159
- // We grab the currentStep from the achData to determine which view to display. The SetupWithdrawalAccount flow
160
- // allows us to continue the flow from various points depending on where the user left off. We can also
161
- // specify a specific step to navigate to by using route params.
203
+ // The SetupWithdrawalAccount flow allows us to continue the flow from various points depending on where the
204
+ // user left off. This view will refer to the achData as the single source of truth to determine which route to
205
+ // display. We can also specify a specific route to navigate to via route params when the component first
206
+ // mounts which will set the achData.currentStep after the account data is fetched and overwrite the logical
207
+ // next step.
162
208
const achData = lodashGet ( this . props , 'reimbursementAccount.achData' , { } ) ;
163
209
const currentStep = achData . currentStep || CONST . BANK_ACCOUNT . STEP . BANK_ACCOUNT ;
164
210
return (
0 commit comments