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

Fix blank screen when showing the WorkspaceResetBankAccount modal #14726

Merged
merged 18 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from 8 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
6 changes: 6 additions & 0 deletions src/pages/ReimbursementAccount/EnableStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import * as Link from '../../libs/actions/Link';
import * as User from '../../libs/actions/User';
import ScreenWrapper from '../../components/ScreenWrapper';
import * as BankAccounts from '../../libs/actions/ReimbursementAccount';
import WorkspaceResetBankAccountModal from '../workspace/WorkspaceResetBankAccountModal';

const propTypes = {
/** Bank account currently in setup */
Expand Down Expand Up @@ -102,6 +103,11 @@ const EnableStep = (props) => {
</Text>
)}
</ScrollView>
{props.reimbursementAccount.shouldShowResetModal && (
<WorkspaceResetBankAccountModal
reimbursementAccount={props.reimbursementAccount}
/>
)}
</ScreenWrapper>
);
};
Expand Down
28 changes: 15 additions & 13 deletions src/pages/ReimbursementAccount/ReimbursementAccountPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,8 @@ class ReimbursementAccountPage extends React.Component {
);
}

if (this.props.reimbursementAccount.shouldShowResetModal && Boolean(achData.bankAccountID)) {
return (
<WorkspaceResetBankAccountModal reimbursementAccount={this.props.reimbursementAccount} />
);
}

// Show the "Continue with setup" button if a bank account setup is already in progress and no specific further step was passed in the url
// We'll show the workspace bank account reset modal if the user wishes to start over
if (!this.state.shouldHideContinueSetupButton
&& Boolean(achData.bankAccountID)
&& achData.state !== BankAccount.STATE.OPEN
Expand All @@ -279,13 +274,20 @@ class ReimbursementAccountPage extends React.Component {
|| achData.state === BankAccount.STATE.PENDING
)) {
return (
<ContinueBankAccountSetup
continue={this.continue}
startOver={() => {
this.setState({shouldHideContinueSetupButton: true});
BankAccounts.requestResetFreePlanBankAccount();
}}
/>
<View>
<ContinueBankAccountSetup
continue={this.continue}
startOver={() => {
BankAccounts.requestResetFreePlanBankAccount();
}}
/>
{this.props.reimbursementAccount.shouldShowResetModal && (
Copy link
Contributor

Choose a reason for hiding this comment

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

thoughts about putting this direcly within ContinueBankAccountSetup?

<WorkspaceResetBankAccountModal
reimbursementAccount={this.props.reimbursementAccount}
onConfirm={() => this.setState({shouldHideContinueSetupButton: true})}
/>
)}
</View>
);
}

Expand Down
6 changes: 6 additions & 0 deletions src/pages/ReimbursementAccount/ValidationStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import Section from '../../components/Section';
import CONST from '../../CONST';
import Button from '../../components/Button';
import MenuItem from '../../components/MenuItem';
import WorkspaceResetBankAccountModal from '../workspace/WorkspaceResetBankAccountModal';
import Enable2FAPrompt from './Enable2FAPrompt';

const propTypes = {
Expand Down Expand Up @@ -226,6 +227,11 @@ class ValidationStep extends React.Component {
wrapperStyle={[styles.cardMenuItem, styles.mv3]}
/>
</Section>
{this.props.reimbursementAccount.shouldShowResetModal && (
<WorkspaceResetBankAccountModal
reimbursementAccount={this.props.reimbursementAccount}
/>
)}
{!requiresTwoFactorAuth && (
<Enable2FAPrompt />
)}
Expand Down
16 changes: 15 additions & 1 deletion src/pages/workspace/WorkspaceResetBankAccountModal.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import lodashGet from 'lodash/get';
import PropTypes from 'prop-types';
import React from 'react';
import ConfirmModal from '../../components/ConfirmModal';
import * as BankAccounts from '../../libs/actions/BankAccounts';
Expand All @@ -12,9 +13,16 @@ const propTypes = {
/** Reimbursement account data */
reimbursementAccount: ReimbursementAccountProps.reimbursementAccountPropTypes.isRequired,

/** Callback when the user confirms resetting the workspace bank account */
onConfirm: PropTypes.func,

...withLocalizePropTypes,
};

const defaultProps = {
onConfirm: null,
Copy link
Contributor

Choose a reason for hiding this comment

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

or you can default to () => {} and then no need for if (props.onConfirm) { below

};

const WorkspaceResetBankAccountModal = (props) => {
const achData = lodashGet(props.reimbursementAccount, 'achData') || {};
const isInOpenState = achData.state === BankAccount.STATE.OPEN;
Expand All @@ -37,7 +45,12 @@ const WorkspaceResetBankAccountModal = (props) => {
) : props.translate('workspace.bankAccount.clearProgress')}
danger
onCancel={BankAccounts.cancelResetFreePlanBankAccount}
onConfirm={() => BankAccounts.resetFreePlanBankAccount(bankAccountID)}
onConfirm={() => {
BankAccounts.resetFreePlanBankAccount(bankAccountID);
if (props.onConfirm) {
props.onConfirm();
}
}}
shouldShowCancelButton
isVisible
/>
Expand All @@ -46,5 +59,6 @@ const WorkspaceResetBankAccountModal = (props) => {

WorkspaceResetBankAccountModal.displayName = 'WorkspaceResetBankAccountModal';
WorkspaceResetBankAccountModal.propTypes = propTypes;
WorkspaceResetBankAccountModal.defaultProps = defaultProps;

export default withLocalize(WorkspaceResetBankAccountModal);