Skip to content

Commit

Permalink
Support vbbas per workspace + refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
nkuoch committed Feb 16, 2024
1 parent e3331db commit 2908c4f
Show file tree
Hide file tree
Showing 29 changed files with 137 additions and 106 deletions.
2 changes: 1 addition & 1 deletion src/libs/API/parameters/AcceptACHContractForBankAccount.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {ACHContractStepProps} from '@src/types/form/ReimbursementAccountForm';

type AcceptACHContractForBankAccount = ACHContractStepProps & {bankAccountID: number; canUseNewVbbaFlow?: boolean};
type AcceptACHContractForBankAccount = ACHContractStepProps & {bankAccountID: number; policyID: string};

export default AcceptACHContractForBankAccount;
4 changes: 2 additions & 2 deletions src/libs/API/parameters/AddPersonalBankAccountParams.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
type AddPersonalBankAccountParams = {
addressName: string;
addressName?: string;
routingNumber: string;
accountNumber: string;
isSavings: boolean;
isSavings?: boolean;
setupType: string;
bank?: string;
plaidAccountID: string;
Expand Down
9 changes: 0 additions & 9 deletions src/libs/API/parameters/ConnectBankAccountManuallyParams.ts

This file was deleted.

13 changes: 13 additions & 0 deletions src/libs/API/parameters/ConnectBankAccountParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
type ConnectBankAccountParams = {
bankAccountID: number;
routingNumber: string;
accountNumber: string;
bank?: string;
plaidAccountID?: string;
plaidAccessToken?: string;
plaidMask?: string;
isSavings?: boolean;
policyID?: string;
};

export default ConnectBankAccountParams;
12 changes: 0 additions & 12 deletions src/libs/API/parameters/ConnectBankAccountWithPlaidParams.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ type OpenReimbursementAccountPageParams = {
stepToOpen: ReimbursementAccountStep;
subStep: ReimbursementAccountSubStep;
localCurrentStep: ReimbursementAccountStep;
policyID?: string;
canUseNewVbbaFlow?: boolean;
policyID: string;
};

export default OpenReimbursementAccountPageParams;
5 changes: 5 additions & 0 deletions src/libs/API/parameters/OpenWorkspaceViewParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type OpenWorkspaceViewParams = {
policyID: string;
};

export default OpenWorkspaceViewParams;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {ACHContractStepProps} from '@src/types/form/ReimbursementAccountForm';
import type {BeneficialOwnersStepProps} from '@src/types/form/ReimbursementAccountForm';

type UpdateBeneficialOwnersForBankAccountParams = ACHContractStepProps & {bankAccountID: number; canUseNewVbbaFlow?: boolean};
type UpdateBeneficialOwnersForBankAccountParams = BeneficialOwnersStepProps & {bankAccountID: number; policyID: string};

export default UpdateBeneficialOwnersForBankAccountParams;
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import type {BankAccountStepProps, CompanyStepProps, ReimbursementAccountProps} from '@src/types/form/ReimbursementAccountForm';
import type {CompanyStepProps} from '@src/types/form/ReimbursementAccountForm';

type BankAccountCompanyInformation = BankAccountStepProps & CompanyStepProps & ReimbursementAccountProps;

type UpdateCompanyInformationForBankAccountParams = BankAccountCompanyInformation & {bankAccountID: number; canUseNewVbbaFlow?: boolean};
type UpdateCompanyInformationForBankAccountParams = CompanyStepProps & {bankAccountID: number; policyID: string};

export default UpdateCompanyInformationForBankAccountParams;
export type {BankAccountCompanyInformation};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {RequestorStepProps} from '@src/types/form/ReimbursementAccountForm';

type UpdatePersonalInformationForBankAccountParams = RequestorStepProps & {bankAccountID: number; canUseNewVbbaFlow: boolean};
type UpdatePersonalInformationForBankAccountParams = RequestorStepProps & {bankAccountID: number; policyID: string};

export default UpdatePersonalInformationForBankAccountParams;
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
type ValidateBankAccountWithTransactionsParams = {
bankAccountID: number;
validateCode: string;
policyID: string;
};

export default ValidateBankAccountWithTransactionsParams;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
type VerifyIdentityForBankAccountParams = {
bankAccountID: number;
onfidoData: string;
canUseNewVbbaFlow?: boolean;
policyID: string;
};
export default VerifyIdentityForBankAccountParams;
4 changes: 2 additions & 2 deletions src/libs/API/parameters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ export type {default as BeginAppleSignInParams} from './BeginAppleSignInParams';
export type {default as BeginGoogleSignInParams} from './BeginGoogleSignInParams';
export type {default as BeginSignInParams} from './BeginSignInParams';
export type {default as CloseAccountParams} from './CloseAccountParams';
export type {default as ConnectBankAccountManuallyParams} from './ConnectBankAccountManuallyParams';
export type {default as ConnectBankAccountWithPlaidParams} from './ConnectBankAccountWithPlaidParams';
export type {default as ConnectBankAccountParams} from './ConnectBankAccountParams';
export type {default as DeleteContactMethodParams} from './DeleteContactMethodParams';
export type {default as DeletePaymentBankAccountParams} from './DeletePaymentBankAccountParams';
export type {default as DeletePaymentCardParams} from './DeletePaymentCardParams';
Expand Down Expand Up @@ -109,6 +108,7 @@ export type {default as UpdateWorkspaceAvatarParams} from './UpdateWorkspaceAvat
export type {default as AddMembersToWorkspaceParams} from './AddMembersToWorkspaceParams';
export type {default as DeleteMembersFromWorkspaceParams} from './DeleteMembersFromWorkspaceParams';
export type {default as OpenWorkspaceParams} from './OpenWorkspaceParams';
export type {default as OpenWorkspaceViewParams} from './OpenWorkspaceViewParams';
export type {default as OpenWorkspaceReimburseViewParams} from './OpenWorkspaceReimburseViewParams';
export type {default as OpenWorkspaceInvitePageParams} from './OpenWorkspaceInvitePageParams';
export type {default as OpenWorkspaceMembersPageParams} from './OpenWorkspaceMembersPageParams';
Expand Down
6 changes: 3 additions & 3 deletions src/libs/API/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ type WriteCommandParameters = {
[WRITE_COMMANDS.VALIDATE_BANK_ACCOUNT_WITH_TRANSACTIONS]: Parameters.ValidateBankAccountWithTransactionsParams;
[WRITE_COMMANDS.UPDATE_COMPANY_INFORMATION_FOR_BANK_ACCOUNT]: Parameters.UpdateCompanyInformationForBankAccountParams;
[WRITE_COMMANDS.UPDATE_BENEFICIAL_OWNERS_FOR_BANK_ACCOUNT]: UpdateBeneficialOwnersForBankAccountParams;
[WRITE_COMMANDS.CONNECT_BANK_ACCOUNT_MANUALLY]: Parameters.ConnectBankAccountManuallyParams;
[WRITE_COMMANDS.CONNECT_BANK_ACCOUNT_MANUALLY]: Parameters.ConnectBankAccountParams;
[WRITE_COMMANDS.VERIFY_IDENTITY_FOR_BANK_ACCOUNT]: Parameters.VerifyIdentityForBankAccountParams;
[WRITE_COMMANDS.BANK_ACCOUNT_HANDLE_PLAID_ERROR]: Parameters.BankAccountHandlePlaidErrorParams;
[WRITE_COMMANDS.REPORT_VIRTUAL_EXPENSIFY_CARD_FRAUD]: Parameters.ReportVirtualExpensifyCardFraudParams;
Expand Down Expand Up @@ -213,7 +213,7 @@ type WriteCommandParameters = {
[WRITE_COMMANDS.TWO_FACTOR_AUTH_VALIDATE]: Parameters.ValidateTwoFactorAuthParams;
[WRITE_COMMANDS.ADD_COMMENT]: Parameters.AddCommentOrAttachementParams;
[WRITE_COMMANDS.ADD_ATTACHMENT]: Parameters.AddCommentOrAttachementParams;
[WRITE_COMMANDS.CONNECT_BANK_ACCOUNT_WITH_PLAID]: Parameters.ConnectBankAccountWithPlaidParams;
[WRITE_COMMANDS.CONNECT_BANK_ACCOUNT_WITH_PLAID]: Parameters.ConnectBankAccountParams;
[WRITE_COMMANDS.ADD_PERSONAL_BANK_ACCOUNT]: Parameters.AddPersonalBankAccountParams;
[WRITE_COMMANDS.OPT_IN_TO_PUSH_NOTIFICATIONS]: Parameters.OptInOutToPushNotificationsParams;
[WRITE_COMMANDS.OPT_OUT_OF_PUSH_NOTIFICATIONS]: Parameters.OptInOutToPushNotificationsParams;
Expand Down Expand Up @@ -325,7 +325,7 @@ type ReadCommand = ValueOf<typeof READ_COMMANDS>;
type ReadCommandParameters = {
[READ_COMMANDS.OPEN_APP]: Parameters.OpenAppParams;
[READ_COMMANDS.OPEN_REIMBURSEMENT_ACCOUNT_PAGE]: Parameters.OpenReimbursementAccountPageParams;
[READ_COMMANDS.OPEN_WORKSPACE_VIEW]: EmptyObject;
[READ_COMMANDS.OPEN_WORKSPACE_VIEW]: Parameters.OpenWorkspaceViewParams;
[READ_COMMANDS.GET_MAPBOX_ACCESS_TOKEN]: EmptyObject;
[READ_COMMANDS.OPEN_PAYMENTS_PAGE]: EmptyObject;
[READ_COMMANDS.OPEN_PERSONAL_DETAILS]: EmptyObject;
Expand Down
54 changes: 29 additions & 25 deletions src/libs/actions/BankAccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import * as API from '@libs/API';
import type {
AddPersonalBankAccountParams,
BankAccountHandlePlaidErrorParams,
ConnectBankAccountManuallyParams,
ConnectBankAccountWithPlaidParams,
ConnectBankAccountParams,
DeletePaymentBankAccountParams,
OpenReimbursementAccountPageParams,
ValidateBankAccountWithTransactionsParams,
Expand Down Expand Up @@ -152,14 +151,15 @@ function addBusinessWebsiteForDraft(websiteUrl: string) {
* Submit Bank Account step with Plaid data so php can perform some checks.
*/
function connectBankAccountWithPlaid(bankAccountID: number, selectedPlaidBankAccount: PlaidBankAccount, policyID: string) {
const parameters: ConnectBankAccountWithPlaidParams = {
const parameters: ConnectBankAccountParams = {
bankAccountID,
routingNumber: selectedPlaidBankAccount.routingNumber,
accountNumber: selectedPlaidBankAccount.accountNumber,
bank: selectedPlaidBankAccount.bankName,
plaidAccountID: selectedPlaidBankAccount.plaidAccountID,
plaidAccessToken: selectedPlaidBankAccount.plaidAccessToken,
canUseNewVbbaFlow: true,
plaidMask: selectedPlaidBankAccount.mask,
isSavings: selectedPlaidBankAccount.isSavings,
policyID,
};

Expand Down Expand Up @@ -254,22 +254,23 @@ function deletePaymentBankAccount(bankAccountID: number) {
* @param bankAccountID - ID for bank account
* @param params - User personal data
*/
function updatePersonalInformationForBankAccount(bankAccountID: number, params: RequestorStepProps) {
function updatePersonalInformationForBankAccount(bankAccountID: number, params: RequestorStepProps, policyID: string) {
API.write(
WRITE_COMMANDS.UPDATE_PERSONAL_INFORMATION_FOR_BANK_ACCOUNT,
{
...params,
bankAccountID,
canUseNewVbbaFlow: true,
policyID,
},
getVBBADataForOnyx(CONST.BANK_ACCOUNT.STEP.REQUESTOR),
);
}

function validateBankAccount(bankAccountID: number, validateCode: string) {
function validateBankAccount(bankAccountID: number, validateCode: string, policyID: string) {
const parameters: ValidateBankAccountWithTransactionsParams = {
bankAccountID,
validateCode,
policyID,
};

const onyxData: OnyxData = {
Expand Down Expand Up @@ -353,7 +354,6 @@ function openReimbursementAccountPage(stepToOpen: ReimbursementAccountStep, subS
subStep,
localCurrentStep,
policyID,
canUseNewVbbaFlow: true,
};

return API.read(READ_COMMANDS.OPEN_REIMBURSEMENT_ACCOUNT_PAGE, parameters, onyxData);
Expand All @@ -363,13 +363,13 @@ function openReimbursementAccountPage(stepToOpen: ReimbursementAccountStep, subS
* Updates the bank account in the database with the company step data
* @param params - Business step form data
*/
function updateCompanyInformationForBankAccount(bankAccountID: number, params: CompanyStepProps) {
function updateCompanyInformationForBankAccount(bankAccountID: number, params: CompanyStepProps, policyID: string) {
API.write(
WRITE_COMMANDS.UPDATE_COMPANY_INFORMATION_FOR_BANK_ACCOUNT,
{
...params,
bankAccountID,
canUseNewVbbaFlow: true,
policyID,
},
getVBBADataForOnyx(CONST.BANK_ACCOUNT.STEP.COMPANY),
);
Expand All @@ -379,13 +379,13 @@ function updateCompanyInformationForBankAccount(bankAccountID: number, params: C
* Add beneficial owners for the bank account and verify the accuracy of the information provided
* @param params - Beneficial Owners step form params
*/
function updateBeneficialOwnersForBankAccount(bankAccountID: number, params: BeneficialOwnersStepProps) {
function updateBeneficialOwnersForBankAccount(bankAccountID: number, params: BeneficialOwnersStepProps, policyID: string) {
API.write(
WRITE_COMMANDS.UPDATE_BENEFICIAL_OWNERS_FOR_BANK_ACCOUNT,
{
...params,
bankAccountID,
canUseNewVbbaFlow: true,
policyID,
},
getVBBADataForOnyx(),
);
Expand All @@ -395,29 +395,31 @@ function updateBeneficialOwnersForBankAccount(bankAccountID: number, params: Ben
* Accept the ACH terms and conditions and verify the accuracy of the information provided
* @param params - Verification step form params
*/
function acceptACHContractForBankAccount(bankAccountID: number, params: ACHContractStepProps) {
function acceptACHContractForBankAccount(bankAccountID: number, params: ACHContractStepProps, policyID: string) {
API.write(
WRITE_COMMANDS.ACCEPT_ACH_CONTRACT_FOR_BANK_ACCOUNT,
{
...params,
bankAccountID,
canUseNewVbbaFlow: true,
policyID,
},
getVBBADataForOnyx(),
);
}

/**
* Create the bank account with manually entered data.
* @param plaidMask - scheme for Plaid account number
*/
function connectBankAccountManually(bankAccountID: number, accountNumber?: string, routingNumber?: string, plaidMask?: string, policyID?: string) {
const parameters: ConnectBankAccountManuallyParams = {
function connectBankAccountManually(bankAccountID: number, bankAccount: PlaidBankAccount, policyID: string) {
const parameters: ConnectBankAccountParams = {
bankAccountID,
accountNumber,
routingNumber,
plaidMask,
canUseNewVbbaFlow: true,
routingNumber: bankAccount.routingNumber,
accountNumber: bankAccount.accountNumber,
bank: bankAccount.bankName,
plaidAccountID: bankAccount.plaidAccountID,
plaidAccessToken: bankAccount.plaidAccessToken,
plaidMask: bankAccount.mask,
isSavings: bankAccount.isSavings,
policyID,
};

Expand All @@ -427,20 +429,22 @@ function connectBankAccountManually(bankAccountID: number, accountNumber?: strin
/**
* Verify the user's identity via Onfido
*/
function verifyIdentityForBankAccount(bankAccountID: number, onfidoData: Record<string, unknown>) {
function verifyIdentityForBankAccount(bankAccountID: number, onfidoData: Record<string, unknown>, policyID: string) {
const parameters: VerifyIdentityForBankAccountParams = {
bankAccountID,
onfidoData: JSON.stringify(onfidoData),
canUseNewVbbaFlow: true,
policyID,
};

API.write(WRITE_COMMANDS.VERIFY_IDENTITY_FOR_BANK_ACCOUNT, parameters, getVBBADataForOnyx());
}

function openWorkspaceView() {
function openWorkspaceView(policyID: string) {
API.read(
READ_COMMANDS.OPEN_WORKSPACE_VIEW,
{},
{
policyID,
},
{
optimisticData: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import ONYXKEYS from '@src/ONYXKEYS';
* Reset user's reimbursement account. This will delete the bank account.
* @param {Number} bankAccountID
* @param {Object} session
* @param {String} policyID
*/
function resetFreePlanBankAccount(bankAccountID, session) {
function resetFreePlanBankAccount(bankAccountID, session, policyID) {
if (!bankAccountID) {
throw new Error('Missing bankAccountID when attempting to reset free plan bank account');
}
Expand All @@ -23,6 +24,7 @@ function resetFreePlanBankAccount(bankAccountID, session) {
{
bankAccountID,
ownerEmail: session.email,
policyID,
},
{
optimisticData: [
Expand Down
7 changes: 6 additions & 1 deletion src/pages/ReimbursementAccount/BankAccountStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ function BankAccountStep(props) {
};

if (subStep === CONST.BANK_ACCOUNT.SETUP_TYPE.PLAID || subStep === CONST.BANK_ACCOUNT.SETUP_TYPE.MANUAL) {
return <BankInfo onBackButtonPress={props.onBackButtonPress} />;
return (
<BankInfo
onBackButtonPress={props.onBackButtonPress}
policyID={props.policyID}
/>
);
}

return (
Expand Down
Loading

0 comments on commit 2908c4f

Please sign in to comment.