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

Save VBA flow information as users type #5114

Merged
merged 49 commits into from
Sep 9, 2021
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
3736999
add reimbursementAccountDraft Onyx key
luacmartins Sep 6, 2021
8f3d5a5
rename key
luacmartins Sep 6, 2021
da65577
add proptypes and lodashget
luacmartins Sep 6, 2021
71db83e
add updateReimbursementAccountDraft function
luacmartins Sep 6, 2021
a769b05
add updateReimbursementAccountDraft to BankAccountStep
luacmartins Sep 6, 2021
f448d76
add defaultProps to BankAccountStep
luacmartins Sep 6, 2021
19e6ea4
add debounced updateReimbursementAccountDraft to BankAccountStep
luacmartins Sep 6, 2021
c5cfb0d
add input docs to debouncedUpdateRimbursementAccountDraft
luacmartins Sep 6, 2021
0ff33f9
add reimbursementAccountDraft to CompanyStep
luacmartins Sep 6, 2021
5451996
add default props
luacmartins Sep 6, 2021
c5eb905
add propTypes
luacmartins Sep 6, 2021
b88eeb0
refactor lodashget in companyStep state
luacmartins Sep 6, 2021
ae75dca
refactor lodashget in bankAccountState state
luacmartins Sep 6, 2021
7082e5f
add updateReimbursementAccountDraft to RequestorStep
luacmartins Sep 6, 2021
614dfa6
add hasNoConnectionToCannabis to draft state
luacmartins Sep 6, 2021
7344261
add isControllingOffice to draft state
luacmartins Sep 6, 2021
2e7e241
add updateReimbursementAccountDraft to BeneficialOwner step
luacmartins Sep 6, 2021
a8f5663
add additional beneficial owners to updateReimbursementAccountDraft
luacmartins Sep 6, 2021
57cc010
change debounce time to 100ms
luacmartins Sep 6, 2021
c1e4513
change propTypes and defaultProps
luacmartins Sep 6, 2021
817d952
add draft reimbursementAccount to ValidationStep
luacmartins Sep 6, 2021
84ca808
remove propTypes and defaultProps
luacmartins Sep 6, 2021
e2297a0
move setValue
luacmartins Sep 6, 2021
b5b65cd
clear reimbursementAccountDraft key after flow is completed
luacmartins Sep 6, 2021
cb0a56c
add hasAcceptedTerms to draft data
luacmartins Sep 6, 2021
19a1d75
fix style
luacmartins Sep 6, 2021
6cd5019
add debounce comment
luacmartins Sep 7, 2021
cd26127
edit comments, add newState variable
luacmartins Sep 7, 2021
5bc3988
remove oldACH changes
luacmartins Sep 7, 2021
d99d602
fix existingOwners bug
luacmartins Sep 7, 2021
ffbff49
remove space
luacmartins Sep 7, 2021
ff05b43
change {} to null
luacmartins Sep 8, 2021
e30126d
add jsdocs to updateReimbursementAccount
luacmartins Sep 8, 2021
97eb173
remove extra space
luacmartins Sep 8, 2021
26c0616
dry dupe states
luacmartins Sep 8, 2021
9b55bd7
add getDefaultStateForField
luacmartins Sep 8, 2021
607b9a0
fix styles
luacmartins Sep 8, 2021
650eb64
remove spread
luacmartins Sep 8, 2021
f70af8e
remove debounce
luacmartins Sep 8, 2021
f9d9e92
remove _ import
luacmartins Sep 8, 2021
0db99e2
merge main
luacmartins Sep 8, 2021
e02bd3b
change jsdocs
luacmartins Sep 9, 2021
f4471ad
rename getDefaultStateForField.js
luacmartins Sep 9, 2021
d3102fc
merge main
luacmartins Sep 9, 2021
71edf15
add hasAcceptedTerms variable
luacmartins Sep 9, 2021
5c5f573
fix style
luacmartins Sep 9, 2021
1ee007b
add getDefaultStateForField to BeneficialOwner and ValidationStep
luacmartins Sep 9, 2021
d11bebe
remove lodashGet
luacmartins Sep 9, 2021
946e4be
remove lodashGet from BeneicialOwner
luacmartins Sep 9, 2021
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
3 changes: 3 additions & 0 deletions src/ONYXKEYS.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ export default {
// Stores information about the active reimbursement account being set up
REIMBURSEMENT_ACCOUNT: 'reimbursementAccount',

// Stores draft information about the active reimbursement account being set up
REIMBURSEMENT_ACCOUNT_DRAFT: 'reimbursementAccountDraft',

// Stores Workspace ID that will be tied to reimbursement account during setup
REIMBURSEMENT_ACCOUNT_WORKSPACE_ID: 'reimbursementAccountWorkspaceID',
};
27 changes: 10 additions & 17 deletions src/libs/actions/BankAccounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,6 @@ function fetchUserWallet() {
* @param {String} [stepToOpen]
*/
function fetchFreePlanVerifiedBankAccount(stepToOpen) {
const oldACHData = {
accountNumber: reimbursementAccountInSetup.accountNumber || '',
routingNumber: reimbursementAccountInSetup.routingNumber || '',
};

// We are using set here since we will rely on data from the server (not local data) to populate the VBA flow
// and determine which step to navigate to.
Onyx.set(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {
Expand Down Expand Up @@ -503,18 +498,7 @@ function fetchFreePlanVerifiedBankAccount(stepToOpen) {
goToWithdrawalAccountSetupStep(currentStep, achData);
})
.finally(() => {
const dataToMerge = {
loading: false,
};

// If we didn't get a routingNumber and accountNumber from the response and we have previously saved
// values, autofill them
if (!reimbursementAccountInSetup.routingNumber && !reimbursementAccountInSetup.accountNumber
&& oldACHData.routingNumber && oldACHData.accountNumber) {
dataToMerge.achData = oldACHData;
}

Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, dataToMerge);
Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {loading: false});
});
});
}
Expand Down Expand Up @@ -587,6 +571,7 @@ function validateBankAccount(bankAccountID, validateCode) {
.then((response) => {
if (response.jsonCode === 200) {
Growl.show('Bank Account successfully validated!', CONST.GROWL.SUCCESS, 5000);
Onyx.set(ONYXKEYS.REIMBURSEMENT_ACCOUNT_DRAFT, null);
API.User_IsUsingExpensifyCard()
.then(({isUsingExpensifyCard}) => {
const reimbursementAccount = {
Expand Down Expand Up @@ -841,6 +826,13 @@ function setWorkspaceIDForReimbursementAccount(workspaceID) {
Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT_WORKSPACE_ID, workspaceID);
}

/**
* @param {Object} bankAccountData
*/
function updateReimbursementAccountDraft(bankAccountData) {
luacmartins marked this conversation as resolved.
Show resolved Hide resolved
Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT_DRAFT, bankAccountData);
}

export {
activateWallet,
addPersonalBankAccount,
Expand All @@ -859,4 +851,5 @@ export {
showBankAccountFormValidationError,
setBankAccountFormValidationErrors,
setWorkspaceIDForReimbursementAccount,
updateReimbursementAccountDraft,
};
16 changes: 16 additions & 0 deletions src/libs/getDefaultStateForField.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import lodashGet from 'lodash/get';

/**
* Add / to the end of any URL if not present
luacmartins marked this conversation as resolved.
Show resolved Hide resolved
* @param {Object} props
* @param {String} fieldName
* @param {*} defaultValue
*
* @returns {*}
*/
function getDefaultStateForField(props, fieldName, defaultValue = '') {
return lodashGet(props, ['reimbursementAccountDraft', fieldName])
|| lodashGet(props, ['achData', fieldName], defaultValue);
luacmartins marked this conversation as resolved.
Show resolved Hide resolved
}

export default getDefaultStateForField;
23 changes: 15 additions & 8 deletions src/pages/ReimbursementAccount/BankAccountStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ import {
setBankAccountFormValidationErrors,
setupWithdrawalAccount,
showBankAccountErrorModal,
updateReimbursementAccountDraft,
} from '../../libs/actions/BankAccounts';
import ONYXKEYS from '../../ONYXKEYS';
import compose from '../../libs/compose';
import getDefaultStateForField from '../../libs/getDefaultStateForField';

const propTypes = {
/** Bank account currently in setup */
Expand All @@ -50,9 +52,9 @@ class BankAccountStep extends React.Component {
this.state = {
// One of CONST.BANK_ACCOUNT.SETUP_TYPE
bankAccountAddMethod: props.achData.subStep || undefined,
hasAcceptedTerms: props.achData.acceptTerms || true,
routingNumber: props.achData.routingNumber || '',
accountNumber: props.achData.accountNumber || '',
hasAcceptedTerms: getDefaultStateForField(props, 'acceptTerms', true),
routingNumber: getDefaultStateForField(props, 'routingNumber'),
accountNumber: getDefaultStateForField(props, 'accountNumber'),
};

// Keys in this.errorTranslationKeys are associated to inputs, they are a subset of the keys found in this.state
Expand All @@ -79,9 +81,10 @@ class BankAccountStep extends React.Component {
}

toggleTerms() {
this.setState(prevState => ({
hasAcceptedTerms: !prevState.hasAcceptedTerms,
}));
this.setState((prevState) => {
updateReimbursementAccountDraft({acceptTerms: !prevState.hasAcceptedTerms});
return {hasAcceptedTerms: !prevState.hasAcceptedTerms};
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, can we use a variable for this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this is still duplicated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are using two different keys for the component state vs achData + Onyx. I think that hasAcceptedTerms is better than acceptTerms, but changing the key in achData didn't seem worth it.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah whoops missed that, yup this is fine then 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

We could do

            const hasAcceptedTerms = !prevState.hasAcceptedTerms;
            updateReimbursementAccountDraft({acceptTerms: hasAcceptedTerms});
            return {hasAcceptedTerms};

although not sure if worth it 😄

});
}

/**
Expand Down Expand Up @@ -117,7 +120,9 @@ class BankAccountStep extends React.Component {
* @param {String} value
*/
clearErrorAndSetValue(inputKey, value) {
this.setState({[inputKey]: value});
const newState = {[inputKey]: value};
this.setState(newState);
updateReimbursementAccountDraft(newState);
const errors = this.getErrors();
if (!errors[inputKey]) {
// No error found for this inputKey
Expand Down Expand Up @@ -308,12 +313,14 @@ class BankAccountStep extends React.Component {
}

BankAccountStep.propTypes = propTypes;

export default compose(
withLocalize,
withOnyx({
reimbursementAccount: {
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
},
reimbursementAccountDraft: {
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT_DRAFT,
},
}),
)(BankAccountStep);
53 changes: 37 additions & 16 deletions src/pages/ReimbursementAccount/BeneficialOwnersStep.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import _ from 'underscore';
import lodashGet from 'lodash/get';
import React from 'react';
import PropTypes from 'prop-types';
import {ScrollView, View} from 'react-native';
Expand All @@ -16,6 +17,7 @@ import {
goToWithdrawalAccountSetupStep,
setupWithdrawalAccount,
showBankAccountErrorModal,
updateReimbursementAccountDraft,
} from '../../libs/actions/BankAccounts';
import Navigation from '../../libs/Navigation/Navigation';
import CONST from '../../CONST';
Expand Down Expand Up @@ -44,11 +46,11 @@ class BeneficialOwnersStep extends React.Component {
this.submit = this.submit.bind(this);

this.state = {
ownsMoreThan25Percent: false,
hasOtherBeneficialOwners: false,
acceptTermsAndConditions: false,
certifyTrueInformation: false,
beneficialOwners: [],
ownsMoreThan25Percent: lodashGet(props, ['reimbursementAccountDraft', 'ownsMoreThan25Percent'], false),
hasOtherBeneficialOwners: lodashGet(props, ['reimbursementAccountDraft', 'hasOtherBeneficialOwners'], false),
acceptTermsAndConditions: lodashGet(props, ['reimbursementAccountDraft', 'acceptTermsAndConditions'], false),
certifyTrueInformation: lodashGet(props, ['reimbursementAccountDraft', 'certifyTrueInformation'], false),
beneficialOwners: lodashGet(props, ['reimbursementAccountDraft', 'beneficialOwners'], []),
luacmartins marked this conversation as resolved.
Show resolved Hide resolved
};
}

Expand Down Expand Up @@ -80,7 +82,15 @@ class BeneficialOwnersStep extends React.Component {
}

removeBeneficialOwner(beneficialOwner) {
this.setState(prevState => ({beneficialOwners: _.without(prevState.beneficialOwners, beneficialOwner)}));
this.setState((prevState) => {
const beneficialOwners = _.without(prevState.beneficialOwners, beneficialOwner);

// We set 'beneficialOwners' to null first because we don't have a way yet to replace a specific property without merging it.
// We don't use the debounced function because we want to make both function calls.
updateReimbursementAccountDraft({beneficialOwners: null});
luacmartins marked this conversation as resolved.
Show resolved Hide resolved
updateReimbursementAccountDraft({beneficialOwners});
luacmartins marked this conversation as resolved.
Show resolved Hide resolved
return {beneficialOwners};
});
}

addBeneficialOwner() {
Expand Down Expand Up @@ -110,6 +120,17 @@ class BeneficialOwnersStep extends React.Component {
() => setupWithdrawalAccount({...this.state}));
}

/**
* @param {Object} fieldName
*/
toggleCheckbox(fieldName) {
this.setState((prevState) => {
const newState = {[fieldName]: !prevState[fieldName]};
updateReimbursementAccountDraft(newState);
return newState;
});
}

render() {
return (
<>
Expand All @@ -129,9 +150,7 @@ class BeneficialOwnersStep extends React.Component {
<CheckboxWithLabel
style={[styles.mb2, styles.mr2]}
isChecked={this.state.ownsMoreThan25Percent}
onPress={() => this.setState(prevState => ({
ownsMoreThan25Percent: !prevState.ownsMoreThan25Percent,
}))}
onPress={() => this.toggleCheckbox('ownsMoreThan25Percent')}
LabelComponent={() => (
<Text>
{this.props.translate('beneficialOwnersStep.iOwnMoreThan25Percent')}
Expand All @@ -145,12 +164,14 @@ class BeneficialOwnersStep extends React.Component {
onPress={() => {
this.setState((prevState) => {
const hasOtherBeneficialOwners = !prevState.hasOtherBeneficialOwners;
return {
const newState = {
hasOtherBeneficialOwners,
beneficialOwners: hasOtherBeneficialOwners && _.isEmpty(prevState.beneficialOwners)
? [{}]
: prevState.beneficialOwners,
};
updateReimbursementAccountDraft(newState);
return newState;
});
}}
LabelComponent={() => (
Expand All @@ -172,6 +193,7 @@ class BeneficialOwnersStep extends React.Component {
onFieldChange={(fieldName, value) => this.setState((prevState) => {
const beneficialOwners = [...prevState.beneficialOwners];
beneficialOwners[index][fieldName] = value;
updateReimbursementAccountDraft({beneficialOwners});
return {beneficialOwners};
})}
values={{
Expand Down Expand Up @@ -207,9 +229,7 @@ class BeneficialOwnersStep extends React.Component {
<CheckboxWithLabel
style={[styles.mb2]}
isChecked={this.state.acceptTermsAndConditions}
onPress={() => this.setState(prevState => ({
acceptTermsAndConditions: !prevState.acceptTermsAndConditions,
}))}
onPress={() => this.toggleCheckbox('acceptTermsAndConditions')}
LabelComponent={() => (
<View style={[styles.flexRow]}>
<Text>{this.props.translate('common.iAcceptThe')}</Text>
Expand All @@ -222,9 +242,7 @@ class BeneficialOwnersStep extends React.Component {
<CheckboxWithLabel
style={[styles.mb2]}
isChecked={this.state.certifyTrueInformation}
onPress={() => this.setState(prevState => ({
certifyTrueInformation: !prevState.certifyTrueInformation,
}))}
onPress={() => this.toggleCheckbox('certifyTrueInformation')}
LabelComponent={() => (
<Text>{this.props.translate('beneficialOwnersStep.certifyTrueAndAccurate')}</Text>
)}
Expand All @@ -250,5 +268,8 @@ export default compose(
reimbursementAccount: {
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
},
reimbursementAccountDraft: {
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT_DRAFT,
},
}),
)(BeneficialOwnersStep);
Loading