Skip to content

Commit

Permalink
Merge pull request #28305 from dukenv0307/fix/25996
Browse files Browse the repository at this point in the history
Trim the value when going back on connect bank account
  • Loading branch information
flodnv authored Oct 13, 2023
2 parents 873a250 + 26e9552 commit c9ccae3
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/libs/actions/BankAccounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ function clearOnfidoToken() {

/**
* Helper method to build the Onyx data required during setup of a Verified Business Bank Account
*
* @param {String | undefined} currentStep The name of the bank account setup step for which we will update the draft value when we receive the response from the API.
* @returns {Object}
*/
function getVBBADataForOnyx() {
function getVBBADataForOnyx(currentStep = undefined) {
return {
optimisticData: [
{
Expand All @@ -79,6 +79,12 @@ function getVBBADataForOnyx() {
value: {
isLoading: false,
errors: null,
// When setting up a bank account, we save the draft form values in Onyx.
// When we update the information for a step, the value of some fields that are returned from the API
// can be different from the value that we stored as the draft in Onyx (i.e. the phone number is formatted).
// This is why we store the current step used to call the API in order to update the corresponding draft data in Onyx.
// If currentStep is undefined that means this step don't need to update the data of the draft in Onyx.
draftStep: currentStep,
},
},
],
Expand Down Expand Up @@ -222,7 +228,7 @@ function deletePaymentBankAccount(bankAccountID) {
* @param {Boolean} [params.isOnfidoSetupComplete]
*/
function updatePersonalInformationForBankAccount(params) {
API.write('UpdatePersonalInformationForBankAccount', params, getVBBADataForOnyx());
API.write('UpdatePersonalInformationForBankAccount', params, getVBBADataForOnyx(CONST.BANK_ACCOUNT.STEP.REQUESTOR));
}

/**
Expand Down Expand Up @@ -339,7 +345,7 @@ function openReimbursementAccountPage(stepToOpen, subStep, localCurrentStep) {
* @param {String} policyID
*/
function updateCompanyInformationForBankAccount(bankAccount, policyID) {
API.write('UpdateCompanyInformationForBankAccount', {...bankAccount, policyID}, getVBBADataForOnyx());
API.write('UpdateCompanyInformationForBankAccount', {...bankAccount, policyID}, getVBBADataForOnyx(CONST.BANK_ACCOUNT.STEP.COMPANY));
}

/**
Expand Down Expand Up @@ -376,7 +382,7 @@ function connectBankAccountManually(bankAccountID, accountNumber, routingNumber,
routingNumber,
plaidMask,
},
getVBBADataForOnyx(),
getVBBADataForOnyx(CONST.BANK_ACCOUNT.STEP.BANK_ACCOUNT),
);
}

Expand Down
1 change: 1 addition & 0 deletions src/libs/actions/ReimbursementAccount/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function setWorkspaceIDForReimbursementAccount(workspaceID) {
*/
function updateReimbursementAccountDraft(bankAccountData) {
Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT_DRAFT, bankAccountData);
Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {draftStep: undefined});
}

/**
Expand Down
42 changes: 42 additions & 0 deletions src/pages/ReimbursementAccount/ReimbursementAccountPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ class ReimbursementAccountPage extends React.Component {
return;
}

// Update the data that is returned from back-end to draft value
const draftStep = this.props.reimbursementAccount.draftStep;
if (draftStep) {
BankAccounts.updateReimbursementAccountDraft(this.getBankAccountFields(this.getFieldsForStep(draftStep)));
}

const currentStepRouteParam = this.getStepToOpenFromRouteParams();
if (currentStepRouteParam === currentStep) {
// The route is showing the correct step, no need to update the route param or clear errors.
Expand All @@ -177,6 +183,42 @@ class ReimbursementAccountPage extends React.Component {
Navigation.navigate(ROUTES.BANK_ACCOUNT_WITH_STEP_TO_OPEN.getRoute(this.getRouteForCurrentStep(currentStep), policyId, backTo));
}

getFieldsForStep(step) {
switch (step) {
case CONST.BANK_ACCOUNT.STEP.BANK_ACCOUNT:
return ['routingNumber', 'accountNumber', 'bankName', 'plaidAccountID', 'plaidAccessToken', 'isSavings'];
case CONST.BANK_ACCOUNT.STEP.COMPANY:
return [
'companyName',
'addressStreet',
'addressZipCode',
'addressCity',
'addressState',
'companyPhone',
'website',
'companyTaxID',
'incorporationType',
'incorporationDate',
'incorporationState',
];
case CONST.BANK_ACCOUNT.STEP.REQUESTOR:
return ['firstName', 'lastName', 'dob', 'ssnLast4', 'requestorAddressStreet', 'requestorAddressCity', 'requestorAddressState', 'requestorAddressZipCode'];
default:
return [];
}
}

/**
* @param {Array} fieldNames
*
* @returns {*}
*/
getBankAccountFields(fieldNames) {
return {
..._.pick(lodashGet(this.props.reimbursementAccount, 'achData'), ...fieldNames),
};
}

/*
* Calculates the state used to show the "Continue with setup" view. If a bank account setup is already in progress and
* no specific further step was passed in the url we'll show the workspace bank account reset modal if the user wishes to start over
Expand Down

0 comments on commit c9ccae3

Please sign in to comment.