Skip to content

Commit

Permalink
Merge pull request #11026 from Expensify/cmartins-UpdateCompanyInform…
Browse files Browse the repository at this point in the history
…ationForBankAccount

Create updateCompanyInformationForBankAccount in App
  • Loading branch information
luacmartins authored Sep 29, 2022
2 parents e453550 + 947296c commit f8a4fa6
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 14 deletions.
15 changes: 15 additions & 0 deletions src/libs/ReimbursementAccountUtils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _ from 'underscore';
import lodashGet from 'lodash/get';
import * as BankAccounts from './actions/BankAccounts';
import FormHelper from './FormHelper';
Expand Down Expand Up @@ -25,6 +26,19 @@ function getDefaultStateForField(props, fieldName, defaultValue = '') {
|| lodashGet(props, ['reimbursementAccount', 'achData', fieldName], defaultValue);
}

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

/**
* @param {Object} props
* @param {Object} errorTranslationKeys
Expand All @@ -42,4 +56,5 @@ export {
clearError,
clearErrors,
getErrorText,
getBankAccountFields,
};
33 changes: 33 additions & 0 deletions src/libs/actions/BankAccounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,38 @@ function validateBankAccount(bankAccountID, validateCode) {
});
}

/**
* Updates the bank account in the database with the company step data
*
* @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 {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(bankAccount) {
API.write('UpdateCompanyInformationForBankAccount', bankAccount, getVBBADataForOnyx());
}

/**
* Create the bank account with manually entered data.
*
Expand Down Expand Up @@ -268,6 +300,7 @@ export {
clearOnfido,
updatePersonalInformationForBankAccount,
validateBankAccount,
updateCompanyInformationForBankAccount,
connectBankAccountWithPlaid,
updatePlaidData,
};
22 changes: 8 additions & 14 deletions src/pages/ReimbursementAccount/CompanyStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,24 +156,18 @@ class CompanyStep extends React.Component {
return;
}

const incorporationDate = moment(this.state.incorporationDate).format(CONST.DATE.MOMENT_FORMAT_STRING);
BankAccounts.setupWithdrawalAccount({
bankAccountID: ReimbursementAccountUtils.getDefaultStateForField(this.props, 'bankAccountID', 0),
const bankAccount = {
// Fields from BankAccount step
...ReimbursementAccountUtils.getBankAccountFields(this.props, ['bankAccountID', 'routingNumber', 'accountNumber', 'bankName', 'plaidAccountID', 'plaidAccessToken', 'isSavings']),

// Fields from bankAccount step
routingNumber: ReimbursementAccountUtils.getDefaultStateForField(this.props, 'routingNumber'),
accountNumber: ReimbursementAccountUtils.getDefaultStateForField(this.props, 'accountNumber'),
bankName: ReimbursementAccountUtils.getDefaultStateForField(this.props, 'bankName'),
plaidAccountID: ReimbursementAccountUtils.getDefaultStateForField(this.props, 'plaidAccountID'),
isSavings: ReimbursementAccountUtils.getDefaultStateForField(this.props, 'isSavings'),
plaidAccessToken: ReimbursementAccountUtils.getDefaultStateForField(this.props, 'plaidAccessToken'),

// Fields from company step
// 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() {
Expand Down

0 comments on commit f8a4fa6

Please sign in to comment.