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

Replace growl errors by modal in VBA flow #4924

Merged
merged 17 commits into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
8 changes: 7 additions & 1 deletion src/libs/ValidationUtils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import moment from 'moment';
import CONST from '../CONST';
import {showBankAccountFormValidationError, showErrorModal} from './actions/BankAccounts';
import {translateLocal} from './translate';
import {showBankAccountFormValidationError} from './actions/BankAccounts';

/**
* Validating that this is a valid address (PO boxes are not allowed)
Expand Down Expand Up @@ -75,32 +75,38 @@ function isValidSSNLastFour(ssnLast4) {
function isValidIdentity(identity) {
if (!isValidAddress(identity.street)) {
showBankAccountFormValidationError(translateLocal('bankAccount.error.address'), true);
showErrorModal();
return false;
}

if (identity.state === '') {
showBankAccountFormValidationError(translateLocal('bankAccount.error.addressState'), true);
showErrorModal();
return false;
}

if (!isValidZipCode(identity.zipCode)) {
showBankAccountFormValidationError(translateLocal('bankAccount.error.zipCode'), true);
showErrorModal();
return false;
}

if (!isValidDate(identity.dob)) {
showBankAccountFormValidationError(translateLocal('bankAccount.error.dob'), true);
showErrorModal();
return false;
}

if (!isValidSSNLastFour(identity.ssnLast4)) {
showBankAccountFormValidationError(translateLocal('bankAccount.error.ssnLast4'), true);
marcaaron marked this conversation as resolved.
Show resolved Hide resolved
showErrorModal();
return false;
}

return true;
}


aldo-expensify marked this conversation as resolved.
Show resolved Hide resolved
export {
isValidAddress,
isValidDate,
Expand Down
32 changes: 24 additions & 8 deletions src/libs/actions/BankAccounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -603,16 +603,29 @@ function validateBankAccount(bankAccountID, validateCode) {
}

/**
* Set the current error message. Show Growl for errors which are not yet handled by the error Modal.
* Show error modal and optionally a specific error message
*
* @param {String} errorMessage The error message to be displayed in the modal's body. We show translate('companyStep.confirmModalPrompt') if not provided.
marcaaron marked this conversation as resolved.
Show resolved Hide resolved
*/

aldo-expensify marked this conversation as resolved.
Show resolved Hide resolved
function showErrorModal(errorMessage = null) {
marcaaron marked this conversation as resolved.
Show resolved Hide resolved
Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {isErrorModalVisible: true, errorModalMessage: errorMessage});
marcaaron marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Hide error modal
*/
function hideErrorModal() {
marcaaron marked this conversation as resolved.
Show resolved Hide resolved
Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {isErrorModalVisible: false});
}

/**
* Set the current error message.
*
* @param {String} error
* @param {Boolean} shouldGrowl
*/
function showBankAccountFormValidationError(error, shouldGrowl) {
function showBankAccountFormValidationError(error) {
Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {error});
if (shouldGrowl) {
Growl.error(error);
}
}

/**
Expand Down Expand Up @@ -789,13 +802,14 @@ function setupWithdrawalAccount(data) {
goToWithdrawalAccountSetupStep(nextStep, achData);

if (error) {
showBankAccountFormValidationError(error, true);
showBankAccountFormValidationError(error);
showErrorModal(error);
}
})
.catch((response) => {
Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {loading: false, achData: {...newACHData}});
console.error(response.stack);
Growl.error(translateLocal('common.genericErrorMessage'), 5000);
showErrorModal(translateLocal('common.genericErrorMessage'));
});
}

Expand All @@ -816,5 +830,7 @@ export {
setupWithdrawalAccount,
validateBankAccount,
hideBankAccountErrors,
hideErrorModal,
showErrorModal,
showBankAccountFormValidationError,
};
6 changes: 3 additions & 3 deletions src/pages/ReimbursementAccount/BeneficialOwnersStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize
import {
goToWithdrawalAccountSetupStep,
setupWithdrawalAccount,
showErrorModal,
} from '../../libs/actions/BankAccounts';
import Navigation from '../../libs/Navigation/Navigation';
import CONST from '../../CONST';
import {isValidIdentity} from '../../libs/ValidationUtils';
import Growl from '../../libs/Growl';
import ONYXKEYS from '../../ONYXKEYS';
import compose from '../../libs/compose';

Expand Down Expand Up @@ -67,12 +67,12 @@ class BeneficialOwnersStep extends React.Component {
}

if (!this.state.acceptTermsAndConditions) {
Growl.error(this.props.translate('beneficialOwnersStep.error.termsAndConditions'));
showErrorModal(this.props.translate('beneficialOwnersStep.error.termsAndConditions'));
return false;
}

if (!this.state.certifyTrueInformation) {
Growl.error(this.props.translate('beneficialOwnersStep.error.certify'));
showErrorModal(this.props.translate('beneficialOwnersStep.error.certify'));
return false;
}

Expand Down
14 changes: 2 additions & 12 deletions src/pages/ReimbursementAccount/CompanyStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
goToWithdrawalAccountSetupStep, hideBankAccountErrors,
setupWithdrawalAccount,
showBankAccountFormValidationError,
showErrorModal,
} from '../../libs/actions/BankAccounts';
import Navigation from '../../libs/Navigation/Navigation';
import Text from '../../components/Text';
Expand All @@ -28,7 +29,6 @@ import {
} from '../../libs/ValidationUtils';
import compose from '../../libs/compose';
import ONYXKEYS from '../../ONYXKEYS';
import ConfirmModal from '../../components/ConfirmModal';
import ExpensiPicker from '../../components/ExpensiPicker';

const propTypes = {
Expand Down Expand Up @@ -62,7 +62,6 @@ class CompanyStep extends React.Component {
industryCode: lodashGet(props, ['achData', 'industryCode'], ''),
hasNoConnectionToCannabis: lodashGet(props, ['achData', 'hasNoConnectionToCannabis'], false),
password: '',
isConfirmModalOpen: false,
};

// These fields need to be filled out in order to submit the form
Expand Down Expand Up @@ -136,7 +135,7 @@ class CompanyStep extends React.Component {

submit() {
if (!this.validate()) {
this.setState({isConfirmModalOpen: true});
showErrorModal();
return;
}

Expand Down Expand Up @@ -343,15 +342,6 @@ class CompanyStep extends React.Component {
/>
</View>
</ScrollView>
<ConfirmModal
title={this.props.translate('companyStep.confirmModalTitle')}
onConfirm={() => this.setState({isConfirmModalOpen: false})}
prompt={this.props.translate('companyStep.confirmModalPrompt')}
isVisible={this.state.isConfirmModalOpen}
confirmText={this.props.translate('companyStep.confirmModalConfirmText')}
shouldShowCancelButton={false}
/>

<FixedFooter style={[styles.mt5]}>
<Button
success
Expand Down
11 changes: 10 additions & 1 deletion src/pages/ReimbursementAccount/ReimbursementAccountPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Str from 'expensify-common/lib/str';
import {View} from 'react-native';
import PropTypes from 'prop-types';
import ScreenWrapper from '../../components/ScreenWrapper';
import {fetchFreePlanVerifiedBankAccount} from '../../libs/actions/BankAccounts';
import {fetchFreePlanVerifiedBankAccount, hideErrorModal} from '../../libs/actions/BankAccounts';
import ONYXKEYS from '../../ONYXKEYS';
import VBALoadingIndicator from '../../components/VBALoadingIndicator';
import Permissions from '../../libs/Permissions';
Expand All @@ -27,6 +27,7 @@ import BeneficialOwnersStep from './BeneficialOwnersStep';
import EnableStep from './EnableStep';
import ROUTES from '../../ROUTES';
import HeaderWithCloseButton from '../../components/HeaderWithCloseButton';
import ConfirmModal from '../../components/ConfirmModal';

const propTypes = {
/** List of betas */
Expand Down Expand Up @@ -238,6 +239,14 @@ class ReimbursementAccountPage extends React.Component {
achData={this.props.reimbursementAccount.achData}
/>
)}
<ConfirmModal
title={this.props.translate('companyStep.confirmModalTitle')} // TODO: Update translation key
onConfirm={() => hideErrorModal()}
marcaaron marked this conversation as resolved.
Show resolved Hide resolved
prompt={this.props.reimbursementAccount.errorModalMessage || this.props.translate('companyStep.confirmModalPrompt')}
isVisible={Boolean(this.props.reimbursementAccount.isErrorModalVisible)}
marcaaron marked this conversation as resolved.
Show resolved Hide resolved
confirmText={this.props.translate('companyStep.confirmModalConfirmText')}
shouldShowCancelButton={false}
/>
</KeyboardAvoidingView>
</ScreenWrapper>
);
Expand Down
9 changes: 5 additions & 4 deletions src/pages/ReimbursementAccount/RequestorStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import Text from '../../components/Text';
import {
goToWithdrawalAccountSetupStep,
setupWithdrawalAccount,
showErrorModal,
} from '../../libs/actions/BankAccounts';
import Button from '../../components/Button';
import FixedFooter from '../../components/FixedFooter';
import IdentityForm from './IdentityForm';
import {isValidIdentity} from '../../libs/ValidationUtils';
import Growl from '../../libs/Growl';
import Onfido from '../../components/Onfido';
import compose from '../../libs/compose';
import ONYXKEYS from '../../ONYXKEYS';
Expand Down Expand Up @@ -71,17 +71,18 @@ class RequestorStep extends React.Component {
*/
validate() {
if (!this.state.isControllingOfficer) {
Growl.error(this.props.translate('requestorStep.isControllingOfficerError'));
showErrorModal(this.props.translate('requestorStep.isControllingOfficerError'));
return false;
}

if (!isValidIdentity({
const identity = {
street: this.state.requestorAddressStreet,
state: this.state.requestorAddressState,
zipCode: this.state.requestorAddressZipCode,
dob: this.state.dob,
ssnLast4: this.state.ssnLast4,
})) {
};
if (!isValidIdentity(identity)) {
marcaaron marked this conversation as resolved.
Show resolved Hide resolved
return false;
}

Expand Down