Skip to content

Commit

Permalink
Merge pull request #9170 from Expensify/amy-refactor-hasVBA
Browse files Browse the repository at this point in the history
Refactor to use an explicit prop for VBA loading state
  • Loading branch information
marcaaron committed May 26, 2022
2 parents e1ce016 + 8423bb4 commit eaee93f
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 29 deletions.
7 changes: 3 additions & 4 deletions src/pages/workspace/WorkspacePageWithSections.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ class WorkspacePageWithSections extends React.Component {

render() {
const achState = lodashGet(this.props.reimbursementAccount, 'achData.state', '');
const hasVBA = this.props.reimbursementAccount.loading
? null
: achState === BankAccount.STATE.OPEN;
const isLoadingVBA = this.props.reimbursementAccount.loading;
const hasVBA = achState === BankAccount.STATE.OPEN;
const isUsingECard = lodashGet(this.props.user, 'isUsingExpensifyCard', false);
const policyID = lodashGet(this.props.route, 'params.policyID');
const policyName = lodashGet(this.props.policy, 'name');
Expand All @@ -112,7 +111,7 @@ class WorkspacePageWithSections extends React.Component {
>
<View style={[styles.w100, styles.flex1]}>

{this.props.children(hasVBA, policyID, isUsingECard)}
{this.props.children(isLoadingVBA, hasVBA, policyID, isUsingECard)}

</View>
</ScrollView>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/workspace/WorkspaceSettingsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class WorkspaceSettingsPage extends React.Component {
</FixedFooter>
)}
>
{hasVBA => (
{(isLoadingVBA, hasVBA) => (
<View style={[styles.pageWrapper, styles.flex1, styles.alignItemsStretch]}>
<AvatarWithImagePicker
isUploading={this.props.policy.isAvatarUploading}
Expand Down Expand Up @@ -176,7 +176,7 @@ class WorkspaceSettingsPage extends React.Component {
onInputChange={currency => this.setState({currency})}
items={this.getCurrencyItems()}
value={this.state.currency}
isDisabled={hasVBA}
isDisabled={isLoadingVBA || hasVBA}
/>
</View>
<Text style={[styles.textLabel, styles.colorMuted, styles.mt2]}>
Expand Down
7 changes: 4 additions & 3 deletions src/pages/workspace/bills/WorkspaceBillsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ const WorkspaceBillsPage = props => (
route={props.route}
guidesCallTaskID={CONST.GUIDES_CALL_TASK_IDS.WORKSPACE_BILLS}
>
{(hasVBA, policyID) => (
{(isLoadingVBA, hasVBA, policyID) => (
<>
{!hasVBA ? (
{!isLoadingVBA && !hasVBA && (
<WorkspaceBillsNoVBAView policyID={policyID} />
) : (
)}
{!isLoadingVBA && hasVBA && (
<WorkspaceBillsVBAView policyID={policyID} />
)}
</>
Expand Down
8 changes: 4 additions & 4 deletions src/pages/workspace/card/WorkspaceCardPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ const WorkspaceCardPage = props => (
route={props.route}
guidesCallTaskID={CONST.GUIDES_CALL_TASK_IDS.WORKSPACE_CARD}
>
{(hasVBA, policyID, isUsingECard) => (
{(isLoadingVBA, hasVBA, policyID, isUsingECard) => (
<>
{!hasVBA && (
{!isLoadingVBA && !hasVBA && (
<WorkspaceCardNoVBAView policyID={policyID} />
)}

{hasVBA && !isUsingECard && (
{!isLoadingVBA && hasVBA && !isUsingECard && (
<WorkspaceCardVBANoECardView />
)}

{hasVBA && isUsingECard && (
{!isLoadingVBA && hasVBA && isUsingECard && (
<WorkspaceCardVBAWithECardView />
)}
</>
Expand Down
7 changes: 4 additions & 3 deletions src/pages/workspace/invoices/WorkspaceInvoicesPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ const WorkspaceInvoicesPage = props => (
route={props.route}
guidesCallTaskID={CONST.GUIDES_CALL_TASK_IDS.WORKSPACE_INVOICES}
>
{(hasVBA, policyID) => (
{(isLoadingVBA, hasVBA, policyID) => (
<>
{!hasVBA ? (
{!isLoadingVBA && !hasVBA && (
<WorkspaceInvoicesNoVBAView policyID={policyID} />
) : (
)}
{!isLoadingVBA && hasVBA && (
<WorkspaceInvoicesVBAView policyID={policyID} />
)}
</>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/workspace/reimburse/WorkspaceReimbursePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const WorkspaceReimbursePage = props => (
route={props.route}
guidesCallTaskID={CONST.GUIDES_CALL_TASK_IDS.WORKSPACE_REIMBURSE}
>
{(hasVBA, policyID) => (
<WorkspaceReimburseView policyID={policyID} hasVBA={hasVBA} />
{(isLoadingVBA, hasVBA, policyID) => (
<WorkspaceReimburseView policyID={policyID} isLoadingVBA={isLoadingVBA} hasVBA={hasVBA} />
)}
</WorkspacePageWithSections>
);
Expand Down
14 changes: 6 additions & 8 deletions src/pages/workspace/reimburse/WorkspaceReimburseView.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ const propTypes = {
/** The policy ID currently being configured */
policyID: PropTypes.string.isRequired,

/** Whether VBA data is loading */
isLoadingVBA: PropTypes.bool.isRequired,

/** Does the user have a VBA in their account? */
hasVBA: PropTypes.bool,
hasVBA: PropTypes.bool.isRequired,

/** Policy values needed in the component */
policy: PropTypes.shape({
Expand All @@ -48,10 +51,6 @@ const propTypes = {
...withLocalizePropTypes,
};

const defaultProps = {
hasVBA: null,
};

class WorkspaceReimburseView extends React.Component {
constructor(props) {
super(props);
Expand Down Expand Up @@ -195,7 +194,7 @@ class WorkspaceReimburseView extends React.Component {
</View>
</Section>

{this.props.hasVBA === false && (
{!this.props.isLoadingVBA && !this.props.hasVBA && (
<Section
title={this.props.translate('workspace.reimburse.unlockNextDayReimbursements')}
icon={Illustrations.JewelBoxGreen}
Expand All @@ -215,7 +214,7 @@ class WorkspaceReimburseView extends React.Component {
/>
</Section>
)}
{Boolean(this.props.hasVBA) && (
{!this.props.isLoadingVBA && this.props.hasVBA && (
<Section
title={this.props.translate('workspace.reimburse.fastReimbursementsHappyMembers')}
icon={Illustrations.BankUserGreen}
Expand All @@ -240,7 +239,6 @@ class WorkspaceReimburseView extends React.Component {
}

WorkspaceReimburseView.propTypes = propTypes;
WorkspaceReimburseView.defaultProps = defaultProps;
WorkspaceReimburseView.displayName = 'WorkspaceReimburseView';

export default compose(
Expand Down
7 changes: 4 additions & 3 deletions src/pages/workspace/travel/WorkspaceTravelPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ const WorkspaceTravelPage = props => (
route={props.route}
guidesCallTaskID={CONST.GUIDES_CALL_TASK_IDS.WORKSPACE_TRAVEL}
>
{(hasVBA, policyID) => (
{(isLoadingVBA, hasVBA, policyID) => (
<>
{!hasVBA ? (
{!isLoadingVBA && !hasVBA && (
<WorkspaceTravelNoVBAView policyID={policyID} />
) : (
)}
{!isLoadingVBA && hasVBA && (
<WorkspaceTravelVBAView />
)}
</>
Expand Down

0 comments on commit eaee93f

Please sign in to comment.