From e385ace93761c5eb1b79f2e96b28f27280994030 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Thu, 15 Sep 2022 15:44:02 -0600 Subject: [PATCH 01/11] create updateCompanyInformationForBankAccount --- src/libs/actions/BankAccounts.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/BankAccounts.js b/src/libs/actions/BankAccounts.js index 7b52777e6e18..7f0b5f569e92 100644 --- a/src/libs/actions/BankAccounts.js +++ b/src/libs/actions/BankAccounts.js @@ -47,7 +47,6 @@ function clearPlaid() { * @returns {Object} */ // We'll remove the below once this function is used by the VBBA commands that are yet to be implemented -/* eslint-disable no-unused-vars */ function getVBBADataForOnyx() { return { optimisticData: [ @@ -192,10 +191,18 @@ function validateBankAccount(bankAccountID, validateCode) { }); } +function updateCompanyInformationForBankAccount() { + API.write('UpdateCompanyInformationForBankAccount', { + routingNumber: 'routingNumber', + }, + getVBBADataForOnyx()); +} + export { addPersonalBankAccount, deletePaymentBankAccount, clearPersonalBankAccount, clearPlaid, validateBankAccount, + updateCompanyInformationForBankAccount, }; From 3aaa093c94fad84f824a03c8558235b68997d3a7 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Thu, 15 Sep 2022 15:51:51 -0600 Subject: [PATCH 02/11] use updateCompanyInformationForBankAccount, add jsdocs --- src/libs/actions/BankAccounts.js | 24 +++++++++++++++---- src/pages/ReimbursementAccount/CompanyStep.js | 2 +- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/libs/actions/BankAccounts.js b/src/libs/actions/BankAccounts.js index 7f0b5f569e92..31b5cc215790 100644 --- a/src/libs/actions/BankAccounts.js +++ b/src/libs/actions/BankAccounts.js @@ -191,11 +191,25 @@ function validateBankAccount(bankAccountID, validateCode) { }); } -function updateCompanyInformationForBankAccount() { - API.write('UpdateCompanyInformationForBankAccount', { - routingNumber: 'routingNumber', - }, - getVBBADataForOnyx()); +/** + * Updates the bank account in db with the company step data + * + * @param {Object} params + * @param {String} [params.companyName] + * @param {String} [params.addressStreet] + * @param {String} [params.addressCity] + * @param {String} [params.addressState] + * @param {String} [params.addressZipCode] + * @param {String} [params.companyPhone] + * @param {String} [params.website] + * @param {String} [params.companyTaxID] + * @param {String} [params.incorporationType] + * @param {String} [params.incorporationState] + * @param {String} [params.incorporationDate] + * @param {Boolean} [params.hasNoConnectionToCannabis] + */ +function updateCompanyInformationForBankAccount(params) { + API.write('UpdateCompanyInformationForBankAccount', params, getVBBADataForOnyx()); } export { diff --git a/src/pages/ReimbursementAccount/CompanyStep.js b/src/pages/ReimbursementAccount/CompanyStep.js index 21aa54fdf57d..8f45c6025568 100644 --- a/src/pages/ReimbursementAccount/CompanyStep.js +++ b/src/pages/ReimbursementAccount/CompanyStep.js @@ -177,7 +177,7 @@ class CompanyStep extends React.Component { } const incorporationDate = moment(this.state.incorporationDate).format(CONST.DATE.MOMENT_FORMAT_STRING); - BankAccounts.setupWithdrawalAccount({ + BankAccounts.updateCompanyInformationForBankAccount({ ...this.state, incorporationDate, companyTaxID: this.state.companyTaxID.replace(CONST.REGEX.NON_NUMERIC, ''), From 42bd32e1d4b089fb003367550050b1b99106acd4 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Thu, 15 Sep 2022 16:18:16 -0600 Subject: [PATCH 03/11] create mergeWithLocalACHData --- src/libs/actions/BankAccounts.js | 41 +++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/BankAccounts.js b/src/libs/actions/BankAccounts.js index 31b5cc215790..356cbfc69443 100644 --- a/src/libs/actions/BankAccounts.js +++ b/src/libs/actions/BankAccounts.js @@ -1,4 +1,6 @@ import Onyx from 'react-native-onyx'; +import lodashGet from 'lodash/get'; +import _ from 'underscore'; import CONST from '../../CONST'; import * as API from '../API'; import ONYXKEYS from '../../ONYXKEYS'; @@ -41,6 +43,15 @@ function clearPlaid() { Onyx.set(ONYXKEYS.PLAID_LINK_TOKEN, ''); } +/** Reimbursement account actively being set up */ +let reimbursementAccountInSetup = {}; +Onyx.connect({ + key: ONYXKEYS.REIMBURSEMENT_ACCOUNT, + callback: (val) => { + reimbursementAccountInSetup = lodashGet(val, 'achData', {}); + }, +}); + /** * Helper method to build the Onyx data required during setup of a Verified Business Bank Account * @@ -191,6 +202,33 @@ function validateBankAccount(bankAccountID, validateCode) { }); } +/** + * @param {Object} data + * @returns {Object} + */ +function mergeWithLocalACHData(data) { + const updatedACHData = { + ...reimbursementAccountInSetup, + ...data, + + // This param tells Web-Secure that this bank account is from NewDot so we can modify links back to the correct + // app in any communications. It also will be used to provision a customer for the Expensify card automatically + // once their bank account is successfully validated. + enableCardAfterVerified: true, + }; + + if (data && !_.isUndefined(data.isSavings)) { + updatedACHData.isSavings = Boolean(data.isSavings); + } + if (!updatedACHData.setupType) { + updatedACHData.setupType = updatedACHData.plaidAccountID + ? CONST.BANK_ACCOUNT.SETUP_TYPE.PLAID + : CONST.BANK_ACCOUNT.SETUP_TYPE.MANUAL; + } + + return updatedACHData; +} + /** * Updates the bank account in db with the company step data * @@ -209,7 +247,8 @@ function validateBankAccount(bankAccountID, validateCode) { * @param {Boolean} [params.hasNoConnectionToCannabis] */ function updateCompanyInformationForBankAccount(params) { - API.write('UpdateCompanyInformationForBankAccount', params, getVBBADataForOnyx()); + const achData = mergeWithLocalACHData(params); + API.write('UpdateCompanyInformationForBankAccount', achData, getVBBADataForOnyx()); } export { From 3dfe15421773e30429c2353289d7ef5fddb29fee Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Fri, 16 Sep 2022 13:47:45 -0600 Subject: [PATCH 04/11] rm const --- src/libs/actions/BankAccounts.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/BankAccounts.js b/src/libs/actions/BankAccounts.js index 356cbfc69443..faaa2c08ae72 100644 --- a/src/libs/actions/BankAccounts.js +++ b/src/libs/actions/BankAccounts.js @@ -247,8 +247,11 @@ function mergeWithLocalACHData(data) { * @param {Boolean} [params.hasNoConnectionToCannabis] */ function updateCompanyInformationForBankAccount(params) { - const achData = mergeWithLocalACHData(params); - API.write('UpdateCompanyInformationForBankAccount', achData, getVBBADataForOnyx()); + API.write( + 'UpdateCompanyInformationForBankAccount', + mergeWithLocalACHData(params), + getVBBADataForOnyx(), + ); } export { From e869bb8edac0ab8b65630f325dd82bc29886730e Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Thu, 22 Sep 2022 15:45:10 -0600 Subject: [PATCH 05/11] update comment --- src/libs/actions/BankAccounts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/BankAccounts.js b/src/libs/actions/BankAccounts.js index ca1f4747d060..4fa79fa042ff 100644 --- a/src/libs/actions/BankAccounts.js +++ b/src/libs/actions/BankAccounts.js @@ -231,7 +231,7 @@ function mergeWithLocalACHData(data) { } /** - * Updates the bank account in db with the company step data + * Updates the bank account in the database with the company step data * * @param {Object} params * @param {String} [params.companyName] From b5ac1a7afdbaca53cfcbec179ff8be7cd02676b9 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 27 Sep 2022 10:31:48 -0600 Subject: [PATCH 06/11] use store --- src/libs/actions/BankAccounts.js | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/libs/actions/BankAccounts.js b/src/libs/actions/BankAccounts.js index e57bfd3bff1e..bb8606ec8b60 100644 --- a/src/libs/actions/BankAccounts.js +++ b/src/libs/actions/BankAccounts.js @@ -1,11 +1,11 @@ import Onyx from 'react-native-onyx'; -import lodashGet from 'lodash/get'; import _ from 'underscore'; import CONST from '../../CONST'; import * as API from '../API'; import ONYXKEYS from '../../ONYXKEYS'; import * as Localize from '../Localize'; import DateUtils from '../DateUtils'; +import * as store from './ReimbursementAccount/store'; export { setupWithdrawalAccount, @@ -42,15 +42,6 @@ function clearPlaid() { Onyx.set(ONYXKEYS.PLAID_LINK_TOKEN, ''); } -/** Reimbursement account actively being set up */ -let reimbursementAccountInSetup = {}; -Onyx.connect({ - key: ONYXKEYS.REIMBURSEMENT_ACCOUNT, - callback: (val) => { - reimbursementAccountInSetup = lodashGet(val, 'achData', {}); - }, -}); - function updatePlaidData(plaidData) { Onyx.merge(ONYXKEYS.PLAID_DATA, plaidData); } @@ -232,7 +223,7 @@ function validateBankAccount(bankAccountID, validateCode) { */ function mergeWithLocalACHData(data) { const updatedACHData = { - ...reimbursementAccountInSetup, + ...store.getReimbursementAccountInSetup(), ...data, // This param tells Web-Secure that this bank account is from NewDot so we can modify links back to the correct From fc99e92b302bf091b47d1f13acd5e838947aea04 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 27 Sep 2022 12:54:45 -0600 Subject: [PATCH 07/11] rm mergeWithLocalACHData, create getBankAccountFields --- src/libs/ReimbursementAccountUtils.js | 17 +++++ src/libs/actions/BankAccounts.js | 75 +++++++------------ src/pages/ReimbursementAccount/CompanyStep.js | 16 +++- 3 files changed, 56 insertions(+), 52 deletions(-) diff --git a/src/libs/ReimbursementAccountUtils.js b/src/libs/ReimbursementAccountUtils.js index 5f7ce0782367..e23982076903 100644 --- a/src/libs/ReimbursementAccountUtils.js +++ b/src/libs/ReimbursementAccountUtils.js @@ -1,3 +1,4 @@ +import _ from 'underscore'; import lodashGet from 'lodash/get'; import * as BankAccounts from './actions/BankAccounts'; import FormHelper from './FormHelper'; @@ -25,6 +26,21 @@ function getDefaultStateForField(props, fieldName, defaultValue = '') { || lodashGet(props, ['achData', fieldName], defaultValue); } +/** + * Get bank account fields + * + * @param {Object} props + * @param {Array} fieldNames + * + * @returns {*} + */ +function getBankAccountFields(props, fieldNames) { + return { + ..._.pick(props.achData, ...fieldNames), + ..._.pick(props.reimbursementAccountDraft, ...fieldNames), + }; +} + /** * @param {Object} props * @param {Object} errorTranslationKeys @@ -42,4 +58,5 @@ export { clearError, clearErrors, getErrorText, + getBankAccountFields, }; diff --git a/src/libs/actions/BankAccounts.js b/src/libs/actions/BankAccounts.js index 8b406eec24de..f933c4b6d8b1 100644 --- a/src/libs/actions/BankAccounts.js +++ b/src/libs/actions/BankAccounts.js @@ -1,11 +1,9 @@ import Onyx from 'react-native-onyx'; -import _ from 'underscore'; import CONST from '../../CONST'; import * as API from '../API'; import ONYXKEYS from '../../ONYXKEYS'; import * as Localize from '../Localize'; import DateUtils from '../DateUtils'; -import * as store from './ReimbursementAccount/store'; export { setupWithdrawalAccount, @@ -217,56 +215,37 @@ function validateBankAccount(bankAccountID, validateCode) { }); } -/** - * @param {Object} data - * @returns {Object} - */ -function mergeWithLocalACHData(data) { - const updatedACHData = { - ...store.getReimbursementAccountInSetup(), - ...data, - - // This param tells Web-Secure that this bank account is from NewDot so we can modify links back to the correct - // app in any communications. It also will be used to provision a customer for the Expensify card automatically - // once their bank account is successfully validated. - enableCardAfterVerified: true, - }; - - if (data && !_.isUndefined(data.isSavings)) { - updatedACHData.isSavings = Boolean(data.isSavings); - } - if (!updatedACHData.setupType) { - updatedACHData.setupType = updatedACHData.plaidAccountID - ? CONST.BANK_ACCOUNT.SETUP_TYPE.PLAID - : CONST.BANK_ACCOUNT.SETUP_TYPE.MANUAL; - } - - return updatedACHData; -} - /** * Updates the bank account in the database with the company step data * - * @param {Object} params - * @param {String} [params.companyName] - * @param {String} [params.addressStreet] - * @param {String} [params.addressCity] - * @param {String} [params.addressState] - * @param {String} [params.addressZipCode] - * @param {String} [params.companyPhone] - * @param {String} [params.website] - * @param {String} [params.companyTaxID] - * @param {String} [params.incorporationType] - * @param {String} [params.incorporationState] - * @param {String} [params.incorporationDate] - * @param {Boolean} [params.hasNoConnectionToCannabis] + * @param {Object} bankAccount + * @param {Number} [bankAccount.bankAccountID] + * + * Fields from BankAccount step + * @param {String} [bankAccount.routingNumber] + * @param {String} [bankAccount.accountNumber] + * @param {String} [bankAccount.bankName] + * @param {String} [bankAccount.plaidAccountID] + * @param {String} [bankAccount.plaidAccessToken] + * @param {String} [bankAccount.setupType] + * @param {Boolean} [bankAccount.isSavings] + * + * Fields from Company step + * @param {String} [bankAccount.companyName] + * @param {String} [bankAccount.addressStreet] + * @param {String} [bankAccount.addressCity] + * @param {String} [bankAccount.addressState] + * @param {String} [bankAccount.addressZipCode] + * @param {String} [bankAccount.companyPhone] + * @param {String} [bankAccount.website] + * @param {String} [bankAccount.companyTaxID] + * @param {String} [bankAccount.incorporationType] + * @param {String} [bankAccount.incorporationState] + * @param {String} [bankAccount.incorporationDate] + * @param {Boolean} [bankAccount.hasNoConnectionToCannabis] */ -function updateCompanyInformationForBankAccount(params) { - API.write( - 'UpdateCompanyInformationForBankAccount', - mergeWithLocalACHData(params), - getVBBADataForOnyx(), - ); +function updateCompanyInformationForBankAccount(bankAccount) { + API.write('UpdateCompanyInformationForBankAccount', bankAccount, getVBBADataForOnyx()); } /** diff --git a/src/pages/ReimbursementAccount/CompanyStep.js b/src/pages/ReimbursementAccount/CompanyStep.js index 0f959797e253..7e1ef1483cbe 100644 --- a/src/pages/ReimbursementAccount/CompanyStep.js +++ b/src/pages/ReimbursementAccount/CompanyStep.js @@ -156,13 +156,21 @@ class CompanyStep extends React.Component { return; } - const incorporationDate = moment(this.state.incorporationDate).format(CONST.DATE.MOMENT_FORMAT_STRING); - BankAccounts.updateCompanyInformationForBankAccount({ + const bankAccount = { + // Fields from BankAccount step + ...ReimbursementAccountUtils.getBankAccountFields( + this.props, + ['bankAccountID', 'routingNumber', 'accountNumber', 'bankName', 'plaidAccountID', 'plaidAccessToken', 'setupType', 'isSavings'], + ), + + // Fields from Company step ...this.state, - incorporationDate, + incorporationDate: moment(this.state.incorporationDate).format(CONST.DATE.MOMENT_FORMAT_STRING), companyTaxID: this.state.companyTaxID.replace(CONST.REGEX.NON_NUMERIC, ''), companyPhone: LoginUtils.getPhoneNumberWithoutUSCountryCodeAndSpecialChars(this.state.companyPhone), - }); + }; + + BankAccounts.updateCompanyInformationForBankAccount(bankAccount); } render() { From b5e7e2daad49c2553adb424d58c83599dde5a188 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 27 Sep 2022 13:28:54 -0600 Subject: [PATCH 08/11] rm setupType --- src/pages/ReimbursementAccount/CompanyStep.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/pages/ReimbursementAccount/CompanyStep.js b/src/pages/ReimbursementAccount/CompanyStep.js index 7e1ef1483cbe..29ea6bfea723 100644 --- a/src/pages/ReimbursementAccount/CompanyStep.js +++ b/src/pages/ReimbursementAccount/CompanyStep.js @@ -158,10 +158,7 @@ class CompanyStep extends React.Component { const bankAccount = { // Fields from BankAccount step - ...ReimbursementAccountUtils.getBankAccountFields( - this.props, - ['bankAccountID', 'routingNumber', 'accountNumber', 'bankName', 'plaidAccountID', 'plaidAccessToken', 'setupType', 'isSavings'], - ), + ...ReimbursementAccountUtils.getBankAccountFields(this.props, ['bankAccountID', 'routingNumber', 'accountNumber', 'bankName', 'plaidAccountID', 'plaidAccessToken', 'isSavings']), // Fields from Company step ...this.state, From 61f2cce50021a13f721e9d32f666dc9a805111c6 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 27 Sep 2022 13:31:03 -0600 Subject: [PATCH 09/11] rm setuptype from jsdocs --- src/libs/actions/BankAccounts.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/actions/BankAccounts.js b/src/libs/actions/BankAccounts.js index f933c4b6d8b1..7bff72e25cbf 100644 --- a/src/libs/actions/BankAccounts.js +++ b/src/libs/actions/BankAccounts.js @@ -227,7 +227,6 @@ function validateBankAccount(bankAccountID, validateCode) { * @param {String} [bankAccount.bankName] * @param {String} [bankAccount.plaidAccountID] * @param {String} [bankAccount.plaidAccessToken] - * @param {String} [bankAccount.setupType] * @param {Boolean} [bankAccount.isSavings] * * Fields from Company step From 02b211ed0c8ebd0ba33550708025a26f47f84e94 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 27 Sep 2022 13:33:26 -0600 Subject: [PATCH 10/11] rm useless jsdocs comment --- src/libs/ReimbursementAccountUtils.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/libs/ReimbursementAccountUtils.js b/src/libs/ReimbursementAccountUtils.js index e23982076903..32d456409030 100644 --- a/src/libs/ReimbursementAccountUtils.js +++ b/src/libs/ReimbursementAccountUtils.js @@ -27,8 +27,6 @@ function getDefaultStateForField(props, fieldName, defaultValue = '') { } /** - * Get bank account fields - * * @param {Object} props * @param {Array} fieldNames * From 012b438d6ecd6a075bed86f2dbf14140d24ce78b Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Wed, 28 Sep 2022 10:04:41 -0600 Subject: [PATCH 11/11] update getBankAccountFields --- src/libs/ReimbursementAccountUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReimbursementAccountUtils.js b/src/libs/ReimbursementAccountUtils.js index 32d456409030..1a9c9ba2589f 100644 --- a/src/libs/ReimbursementAccountUtils.js +++ b/src/libs/ReimbursementAccountUtils.js @@ -34,7 +34,7 @@ function getDefaultStateForField(props, fieldName, defaultValue = '') { */ function getBankAccountFields(props, fieldNames) { return { - ..._.pick(props.achData, ...fieldNames), + ..._.pick(lodashGet(props, 'reimbursementAccount.achData'), ...fieldNames), ..._.pick(props.reimbursementAccountDraft, ...fieldNames), }; }