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

Trim the value when going back on connect bank account #28305

Merged
merged 33 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
183e3fe
Trim the value when going back on connect bank account
dukenv0307 Sep 27, 2023
99477df
use draft if the default value is empty
dukenv0307 Sep 27, 2023
04e7887
fix typo
dukenv0307 Sep 27, 2023
161abe5
save value to draft after updating data successfully
dukenv0307 Sep 27, 2023
15ef37f
fix merge main
dukenv0307 Sep 27, 2023
883db65
fix jest
dukenv0307 Sep 27, 2023
10f72f8
fix lint
dukenv0307 Sep 27, 2023
0fa5251
Merge branch 'main' into fix/25996
dukenv0307 Sep 27, 2023
4532a36
add comment
dukenv0307 Sep 27, 2023
3c4be81
create a const for fields of the step
dukenv0307 Sep 27, 2023
936289c
fix lint
dukenv0307 Sep 27, 2023
88fc114
Merge branch 'fix/25996' of https://github.com/dukenv0307/App into fi…
dukenv0307 Sep 27, 2023
25c2366
reuse the const
dukenv0307 Sep 27, 2023
6caa796
revert const
dukenv0307 Sep 28, 2023
270eddf
fix jest
dukenv0307 Sep 28, 2023
12f5f05
fix lint
dukenv0307 Sep 28, 2023
a58a10e
fix no update when clicking on go back
dukenv0307 Sep 29, 2023
f2b02f1
don't call update when unnecessary
dukenv0307 Sep 29, 2023
6139ff2
Merge branch 'main' into fix/25996
dukenv0307 Oct 3, 2023
96bf07d
Merge branch 'fix/25996' of https://github.com/dukenv0307/App into fi…
dukenv0307 Oct 3, 2023
0de5e86
add default value for param
dukenv0307 Oct 3, 2023
b4bfd76
add check for shouldUpdateDataToDraft
dukenv0307 Oct 3, 2023
1c1dd14
rename variable
dukenv0307 Oct 3, 2023
401e05d
fix lint
dukenv0307 Oct 3, 2023
cc35473
remove unuse field
dukenv0307 Oct 3, 2023
0314480
Update src/pages/ReimbursementAccount/ReimbursementAccountPage.js
dukenv0307 Oct 3, 2023
abb6b20
add description
dukenv0307 Oct 4, 2023
bec41b8
add more detail description
dukenv0307 Oct 4, 2023
4e75345
fix typo
dukenv0307 Oct 4, 2023
c0e74b9
Update src/libs/actions/BankAccounts.js
dukenv0307 Oct 6, 2023
0f48962
rename the variable
dukenv0307 Oct 6, 2023
8d692b0
Update src/pages/ReimbursementAccount/ReimbursementAccountPage.js
dukenv0307 Oct 9, 2023
26e9552
fix lint
dukenv0307 Oct 9, 2023
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
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'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels like we could be repeating ourselves a bit here, as if someone wanted to add/remove a field they would have to update this list too. Is there any way we could reference the fields in one place?

Copy link
Contributor Author

@dukenv0307 dukenv0307 Sep 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ollyws Here are the list values of the step and this is only called after api update success. If we want to update the change field to draft we will need to compare draft value and achData, I think it will take the same amount of time when we merge all fields of the step.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dukenv0307 What I mean is, in RequestorStep for example we already have a list of input IDs could we perhaps use this list instead of creating a new list here, and implement something similar for the other steps?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The list here is the list that I copied in each step.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we create a const for the list and re-use this.

Copy link
Contributor Author

@dukenv0307 dukenv0307 Sep 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just updated it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dukenv0307 Thanks but I was specifically referring to this list of input IDs, which we could then perhaps get the values of using _.values()? Let me know what you think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ollyws I see that we only use this in the special form like AddressForm, other fields doesn't use this. So I think we don't need to create the list input key like this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok well if we're not going to implement that then I don't really see the need for a const, just to be used for the requiredFields. Could you revert those two commits? Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

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
Loading