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 11 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
18 changes: 12 additions & 6 deletions 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, showBankAccountErrorModal} 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 @@ -74,33 +74,39 @@ function isValidSSNLastFour(ssnLast4) {
*/
function isValidIdentity(identity) {
if (!isValidAddress(identity.street)) {
showBankAccountFormValidationError(translateLocal('bankAccount.error.address'), true);
showBankAccountFormValidationError(translateLocal('bankAccount.error.address'));
showBankAccountErrorModal();
return false;
}

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

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

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

if (!isValidSSNLastFour(identity.ssnLast4)) {
showBankAccountFormValidationError(translateLocal('bankAccount.error.ssnLast4'), true);
showBankAccountFormValidationError(translateLocal('bankAccount.error.ssnLast4'));
showBankAccountErrorModal();
return false;
}

return true;
}


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} errorModalMessage The error message to be displayed in the modal's body.
*/

function showBankAccountErrorModal(errorModalMessage = null) {
Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {isErrorModalVisible: true, errorModalMessage});
}

/**
* Hide error modal
*/
function hideBankAccountErrorModal() {
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);
showBankAccountErrorModal(error);
}
})
.catch((response) => {
Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {loading: false, achData: {...newACHData}});
console.error(response.stack);
Growl.error(translateLocal('common.genericErrorMessage'), 5000);
showBankAccountErrorModal(translateLocal('common.genericErrorMessage'));
});
}

Expand All @@ -816,5 +830,7 @@ export {
setupWithdrawalAccount,
validateBankAccount,
hideBankAccountErrors,
hideBankAccountErrorModal,
showBankAccountErrorModal,
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,
showBankAccountErrorModal,
} 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'));
showBankAccountErrorModal(this.props.translate('beneficialOwnersStep.error.termsAndConditions'));
return false;
}

if (!this.state.certifyTrueInformation) {
Growl.error(this.props.translate('beneficialOwnersStep.error.certify'));
showBankAccountErrorModal(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,
showBankAccountErrorModal,
} 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});
showBankAccountErrorModal();
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, hideBankAccountErrorModal} 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={hideBankAccountErrorModal}
prompt={this.props.reimbursementAccount.errorModalMessage || this.props.translate('companyStep.confirmModalPrompt')}
isVisible={Boolean(this.props.reimbursementAccount.isErrorModalVisible)}
confirmText={this.props.translate('companyStep.confirmModalConfirmText')}
shouldShowCancelButton={false}
/>
</KeyboardAvoidingView>
</ScreenWrapper>
);
Expand Down
4 changes: 2 additions & 2 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,
showBankAccountErrorModal,
} 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,7 +71,7 @@ class RequestorStep extends React.Component {
*/
validate() {
if (!this.state.isControllingOfficer) {
Growl.error(this.props.translate('requestorStep.isControllingOfficerError'));
showBankAccountErrorModal(this.props.translate('requestorStep.isControllingOfficerError'));
return false;
}

Expand Down