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

Re-fetch actions when we move from offline to online in ReimbursementAccountPage.js #8831

Merged
merged 3 commits into from
May 24, 2022
Merged
Changes from 2 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
24 changes: 19 additions & 5 deletions src/pages/ReimbursementAccount/ReimbursementAccountPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import styles from '../../styles/styles';
import KeyboardAvoidingView from '../../components/KeyboardAvoidingView';
import getPlaidOAuthReceivedRedirectURI from '../../libs/getPlaidOAuthReceivedRedirectURI';
import Text from '../../components/Text';
import {withNetwork} from '../../components/OnyxProvider';
import networkPropTypes from '../../components/networkPropTypes';

// Steps
import BankAccountStep from './BankAccountStep';
Expand All @@ -39,6 +41,9 @@ const propTypes = {
/** ACH data for the withdrawal account actively being set up */
reimbursementAccount: reimbursementAccountPropTypes,

/** Information about the network */
network: networkPropTypes.isRequired,

/** Current session for the user */
session: PropTypes.shape({
/** User login */
Expand Down Expand Up @@ -70,14 +75,13 @@ const defaultProps = {

class ReimbursementAccountPage extends React.Component {
componentDidMount() {
// We can specify a step to navigate to by using route params when the component mounts.
const stepToOpen = this.getStepToOpenFromRouteParams();

// If we are trying to navigate to `/bank-account/new` and we already have a bank account then don't allow returning to `/new`
BankAccounts.fetchFreePlanVerifiedBankAccount(stepToOpen !== CONST.BANK_ACCOUNT.STEP.BANK_ACCOUNT ? stepToOpen : '');
this.fetchData();
}

componentDidUpdate(prevProps) {
if (prevProps.network.isOffline && !this.props.network.isOffline) {
this.fetchData();
}
const currentStep = lodashGet(
this.props,
'reimbursementAccount.achData.currentStep',
Expand Down Expand Up @@ -144,6 +148,15 @@ class ReimbursementAccountPage extends React.Component {
}
}

fetchData() {
// We can specify a step to navigate to by using route params when the component mounts or when the network status changes.
// We initialize this variable because the route parameters may have changed when we toggle between offline and online states.
Justicea83 marked this conversation as resolved.
Show resolved Hide resolved
const stepToOpen = this.getStepToOpenFromRouteParams();
marcaaron marked this conversation as resolved.
Show resolved Hide resolved

// If we are trying to navigate to `/bank-account/new` and we already have a bank account then don't allow returning to `/new`
BankAccounts.fetchFreePlanVerifiedBankAccount(stepToOpen !== CONST.BANK_ACCOUNT.STEP.BANK_ACCOUNT ? stepToOpen : '');
}

render() {
if (!Permissions.canUseFreePlan(this.props.betas)) {
Log.info('Not showing new bank account page because user is not on free plan beta');
Expand Down Expand Up @@ -243,6 +256,7 @@ ReimbursementAccountPage.propTypes = propTypes;
ReimbursementAccountPage.defaultProps = defaultProps;

export default compose(
withNetwork(),
withOnyx({
reimbursementAccount: {
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
Expand Down