diff --git a/src/libs/actions/BankAccounts.js b/src/libs/actions/BankAccounts.js index e81e2b863190..699323eae5f2 100644 --- a/src/libs/actions/BankAccounts.js +++ b/src/libs/actions/BankAccounts.js @@ -321,6 +321,10 @@ function verifyIdentityForBankAccount(bankAccountID, onfidoData) { }, getVBBADataForOnyx()); } +function openWorkspaceView() { + API.read('OpenWorkspaceView'); +} + export { addPersonalBankAccount, connectBankAccountManually, @@ -329,6 +333,7 @@ export { clearOnfidoToken, connectBankAccountWithPlaid, deletePaymentBankAccount, + openWorkspaceView, updateBeneficialOwnersForBankAccount, updateCompanyInformationForBankAccount, updatePersonalInformationForBankAccount, diff --git a/src/pages/workspace/WorkspacePageWithSections.js b/src/pages/workspace/WorkspacePageWithSections.js index 706ff3c5bc64..00533829adc3 100644 --- a/src/pages/workspace/WorkspacePageWithSections.js +++ b/src/pages/workspace/WorkspacePageWithSections.js @@ -12,19 +12,11 @@ import HeaderWithCloseButton from '../../components/HeaderWithCloseButton'; import ScreenWrapper from '../../components/ScreenWrapper'; import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize'; import ONYXKEYS from '../../ONYXKEYS'; -import * as BankAccounts from '../../libs/actions/BankAccounts'; -import BankAccount from '../../libs/models/BankAccount'; -import reimbursementAccountPropTypes from '../ReimbursementAccount/reimbursementAccountPropTypes'; import userPropTypes from '../settings/userPropTypes'; import withPolicy from './withPolicy'; -import {withNetwork} from '../../components/OnyxProvider'; -import networkPropTypes from '../../components/networkPropTypes'; import FullPageNotFoundView from '../../components/BlockingViews/FullPageNotFoundView'; const propTypes = { - /** Information about the network from Onyx */ - network: networkPropTypes.isRequired, - /** The text to display in the header */ headerText: PropTypes.string.isRequired, @@ -37,10 +29,6 @@ const propTypes = { }).isRequired, }).isRequired, - /** From Onyx */ - /** Bank account currently in setup */ - reimbursementAccount: reimbursementAccountPropTypes, - /** User Data from Onyx */ user: userPropTypes, @@ -67,72 +55,49 @@ const propTypes = { const defaultProps = { children: () => {}, user: {}, - reimbursementAccount: {}, footer: null, guidesCallTaskID: '', shouldUseScrollView: false, }; -class WorkspacePageWithSections extends React.Component { - componentDidMount() { - this.fetchData(); - } - - componentDidUpdate(prevProps) { - if (!prevProps.network.isOffline || this.props.network.isOffline) { - return; - } - - this.fetchData(); - } - - fetchData() { - const achState = lodashGet(this.props.reimbursementAccount, 'achData.state', ''); - BankAccounts.fetchFreePlanVerifiedBankAccount('', achState); - } - - render() { - const achState = lodashGet(this.props.reimbursementAccount, 'achData.state', ''); - 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'); - - return ( - - - Navigation.navigate(ROUTES.getWorkspaceInitialRoute(policyID))} - onCloseButtonPress={() => Navigation.dismissModal()} - /> - {this.props.shouldUseScrollView - ? ( - - - - {this.props.children(hasVBA, policyID, isUsingECard)} - - - - ) - : this.props.children(hasVBA, policyID, isUsingECard)} - {this.props.footer} - - - ); - } -} +const WorkspacePageWithSections = (props) => { + const isUsingECard = lodashGet(props.user, 'isUsingExpensifyCard', false); + const policyID = lodashGet(props.route, 'params.policyID'); + const policyName = lodashGet(props.policy, 'name'); + + return ( + + + Navigation.navigate(ROUTES.getWorkspaceInitialRoute(policyID))} + onCloseButtonPress={() => Navigation.dismissModal()} + /> + {props.shouldUseScrollView + ? ( + + + {props.children(policyID, isUsingECard)} + + + ) + : props.children(policyID, isUsingECard)} + {props.footer} + + + ); +}; -WorkspacePageWithSections.propTypes = propTypes; WorkspacePageWithSections.defaultProps = defaultProps; +WorkspacePageWithSections.displayName = 'WorkspacePageWithSections'; +WorkspacePageWithSections.propTypes = propTypes; export default compose( withLocalize, @@ -145,5 +110,4 @@ export default compose( }, }), withPolicy, - withNetwork(), )(WorkspacePageWithSections); diff --git a/src/pages/workspace/WorkspaceSettingsPage.js b/src/pages/workspace/WorkspaceSettingsPage.js index 9916619518c6..be414512536f 100644 --- a/src/pages/workspace/WorkspaceSettingsPage.js +++ b/src/pages/workspace/WorkspaceSettingsPage.js @@ -11,9 +11,12 @@ import compose from '../../libs/compose'; import * as Policy from '../../libs/actions/Policy'; import Icon from '../../components/Icon'; import * as Expensicons from '../../components/Icon/Expensicons'; +import * as BankAccounts from '../../libs/actions/BankAccounts'; import AvatarWithImagePicker from '../../components/AvatarWithImagePicker'; +import BankAccount from '../../libs/models/BankAccount'; import defaultTheme from '../../styles/themes/default'; import CONST from '../../CONST'; +import reimbursementAccountPropTypes from '../ReimbursementAccount/reimbursementAccountPropTypes'; import Picker from '../../components/Picker'; import TextInput from '../../components/TextInput'; import WorkspacePageWithSections from './WorkspacePageWithSections'; @@ -24,6 +27,10 @@ import FullPageNotFoundView from '../../components/BlockingViews/FullPageNotFoun import Form from '../../components/Form'; const propTypes = { + /** From Onyx */ + /** Bank account currently in setup */ + reimbursementAccount: reimbursementAccountPropTypes, + ...policyPropTypes, ...withLocalizePropTypes, }; @@ -41,6 +48,10 @@ class WorkspaceSettingsPage extends React.Component { this.validate = this.validate.bind(this); } + componentDidMount() { + BankAccounts.openWorkspaceView(); + } + /** * @returns {Object[]} */ @@ -71,6 +82,8 @@ class WorkspaceSettingsPage extends React.Component { } render() { + const achState = lodashGet(this.props.reimbursementAccount, 'achData.state', ''); + const hasVBBA = achState === BankAccount.STATE.OPEN; return ( - {hasVBA => ( + {() => (
@@ -148,7 +161,12 @@ WorkspaceSettingsPage.defaultProps = defaultProps; export default compose( withPolicy, withOnyx({ - currencyList: {key: ONYXKEYS.CURRENCY_LIST}, + currencyList: { + key: ONYXKEYS.CURRENCY_LIST, + }, + reimbursementAccount: { + key: ONYXKEYS.REIMBURSEMENT_ACCOUNT, + }, }), withLocalize, withNetwork(), diff --git a/src/pages/workspace/bills/WorkspaceBillsPage.js b/src/pages/workspace/bills/WorkspaceBillsPage.js index 2622c57f26df..58f12ccbe041 100644 --- a/src/pages/workspace/bills/WorkspaceBillsPage.js +++ b/src/pages/workspace/bills/WorkspaceBillsPage.js @@ -1,12 +1,23 @@ import React from 'react'; import PropTypes from 'prop-types'; +import lodashGet from 'lodash/get'; +import {withOnyx} from 'react-native-onyx'; import withLocalize, {withLocalizePropTypes} from '../../../components/withLocalize'; +import * as BankAccounts from '../../../libs/actions/BankAccounts'; +import BankAccount from '../../../libs/models/BankAccount'; +import compose from '../../../libs/compose'; +import CONST from '../../../CONST'; +import ONYXKEYS from '../../../ONYXKEYS'; +import reimbursementAccountPropTypes from '../../ReimbursementAccount/reimbursementAccountPropTypes'; +import withPolicy from '../withPolicy'; import WorkspaceBillsNoVBAView from './WorkspaceBillsNoVBAView'; import WorkspaceBillsVBAView from './WorkspaceBillsVBAView'; import WorkspacePageWithSections from '../WorkspacePageWithSections'; -import CONST from '../../../CONST'; const propTypes = { + /** Bank account currently in setup */ + reimbursementAccount: reimbursementAccountPropTypes, + /** The route object passed to this page from the navigator */ route: PropTypes.shape({ /** Each parameter passed via the URL */ @@ -19,26 +30,49 @@ const propTypes = { ...withLocalizePropTypes, }; -const WorkspaceBillsPage = props => ( - - {(hasVBA, policyID) => ( - <> - {!hasVBA && ( - - )} - {hasVBA && ( - +const defaultProps = { + reimbursementAccount: {}, +}; + +class WorkspaceBillsPage extends React.Component { + componentDidMount() { + BankAccounts.openWorkspaceView(); + } + + render() { + const achState = lodashGet(this.props.reimbursementAccount, 'achData.state', ''); + const hasVBBA = achState === BankAccount.STATE.OPEN; + return ( + + {policyID => ( + <> + {!hasVBBA && ( + + )} + {hasVBBA && ( + + )} + )} - - )} - -); + + ); + } +} WorkspaceBillsPage.propTypes = propTypes; -WorkspaceBillsPage.displayName = 'WorkspaceBillsPage'; -export default withLocalize(WorkspaceBillsPage); +WorkspaceBillsPage.defaultProps = defaultProps; + +export default compose( + withPolicy, + withOnyx({ + reimbursementAccount: { + key: ONYXKEYS.REIMBURSEMENT_ACCOUNT, + }, + }), + withLocalize, +)(WorkspaceBillsPage); diff --git a/src/pages/workspace/card/WorkspaceCardPage.js b/src/pages/workspace/card/WorkspaceCardPage.js index 2cf5ef28f259..ab2bef8d3526 100644 --- a/src/pages/workspace/card/WorkspaceCardPage.js +++ b/src/pages/workspace/card/WorkspaceCardPage.js @@ -1,13 +1,23 @@ import React from 'react'; import PropTypes from 'prop-types'; +import lodashGet from 'lodash/get'; +import {withOnyx} from 'react-native-onyx'; import withLocalize, {withLocalizePropTypes} from '../../../components/withLocalize'; +import * as BankAccounts from '../../../libs/actions/BankAccounts'; +import BankAccount from '../../../libs/models/BankAccount'; +import compose from '../../../libs/compose'; +import CONST from '../../../CONST'; +import ONYXKEYS from '../../../ONYXKEYS'; +import reimbursementAccountPropTypes from '../../ReimbursementAccount/reimbursementAccountPropTypes'; import WorkspaceCardNoVBAView from './WorkspaceCardNoVBAView'; import WorkspaceCardVBANoECardView from './WorkspaceCardVBANoECardView'; import WorkspaceCardVBAWithECardView from './WorkspaceCardVBAWithECardView'; import WorkspacePageWithSections from '../WorkspacePageWithSections'; -import CONST from '../../../CONST'; const propTypes = { + /** Bank account currently in setup */ + reimbursementAccount: reimbursementAccountPropTypes, + /** The route object passed to this page from the navigator */ route: PropTypes.shape({ /** Each parameter passed via the URL */ @@ -20,32 +30,53 @@ const propTypes = { ...withLocalizePropTypes, }; -const WorkspaceCardPage = props => ( - - {(hasVBA, policyID, isUsingECard) => ( - <> - {!hasVBA && ( - - )} +const defaultProps = { + reimbursementAccount: {}, +}; - {hasVBA && !isUsingECard && ( - - )} +class WorkspaceCardPage extends React.Component { + componentDidMount() { + BankAccounts.openWorkspaceView(); + } + + render() { + const achState = lodashGet(this.props.reimbursementAccount, 'achData.state', ''); + const hasVBBA = achState === BankAccount.STATE.OPEN; + return ( + + {(policyID, isUsingECard) => ( + <> + {!hasVBBA && ( + + )} + + {hasVBBA && !isUsingECard && ( + + )} - {hasVBA && isUsingECard && ( - + {hasVBBA && isUsingECard && ( + + )} + )} - - )} - -); + + ); + } +} WorkspaceCardPage.propTypes = propTypes; -WorkspaceCardPage.displayName = 'WorkspaceCardPage'; +WorkspaceCardPage.defaultProps = defaultProps; -export default withLocalize(WorkspaceCardPage); +export default compose( + withOnyx({ + reimbursementAccount: { + key: ONYXKEYS.REIMBURSEMENT_ACCOUNT, + }, + }), + withLocalize, +)(WorkspaceCardPage); diff --git a/src/pages/workspace/invoices/WorkspaceInvoicesPage.js b/src/pages/workspace/invoices/WorkspaceInvoicesPage.js index 537054df72a2..bc3dfa34d4e8 100644 --- a/src/pages/workspace/invoices/WorkspaceInvoicesPage.js +++ b/src/pages/workspace/invoices/WorkspaceInvoicesPage.js @@ -1,12 +1,22 @@ import React from 'react'; import PropTypes from 'prop-types'; +import lodashGet from 'lodash/get'; +import {withOnyx} from 'react-native-onyx'; import withLocalize, {withLocalizePropTypes} from '../../../components/withLocalize'; +import * as BankAccounts from '../../../libs/actions/BankAccounts'; +import BankAccount from '../../../libs/models/BankAccount'; +import compose from '../../../libs/compose'; +import CONST from '../../../CONST'; +import ONYXKEYS from '../../../ONYXKEYS'; +import reimbursementAccountPropTypes from '../../ReimbursementAccount/reimbursementAccountPropTypes'; import WorkspacePageWithSections from '../WorkspacePageWithSections'; import WorkspaceInvoicesNoVBAView from './WorkspaceInvoicesNoVBAView'; import WorkspaceInvoicesVBAView from './WorkspaceInvoicesVBAView'; -import CONST from '../../../CONST'; const propTypes = { + /** Bank account currently in setup */ + reimbursementAccount: reimbursementAccountPropTypes, + /** The route object passed to this page from the navigator */ route: PropTypes.shape({ /** Each parameter passed via the URL */ @@ -19,27 +29,48 @@ const propTypes = { ...withLocalizePropTypes, }; -const WorkspaceInvoicesPage = props => ( - - {(hasVBA, policyID) => ( - <> - {!hasVBA && ( - - )} - {hasVBA && ( - +const defaultProps = { + reimbursementAccount: {}, +}; + +class WorkspaceInvoicesPage extends React.Component { + componentDidMount() { + BankAccounts.openWorkspaceView(); + } + + render() { + const achState = lodashGet(this.props.reimbursementAccount, 'achData.state', ''); + const hasVBBA = achState === BankAccount.STATE.OPEN; + return ( + + {policyID => ( + <> + {!hasVBBA && ( + + )} + {hasVBBA && ( + + )} + )} - - )} - -); + + ); + } +} WorkspaceInvoicesPage.propTypes = propTypes; -WorkspaceInvoicesPage.displayName = 'WorkspaceInvoicesPage'; +WorkspaceInvoicesPage.defaultProps = defaultProps; -export default withLocalize(WorkspaceInvoicesPage); +export default compose( + withOnyx({ + reimbursementAccount: { + key: ONYXKEYS.REIMBURSEMENT_ACCOUNT, + }, + }), + withLocalize, +)(WorkspaceInvoicesPage); diff --git a/src/pages/workspace/reimburse/WorkspaceReimbursePage.js b/src/pages/workspace/reimburse/WorkspaceReimbursePage.js index 3a208fcfa9eb..55ad8a0bda23 100644 --- a/src/pages/workspace/reimburse/WorkspaceReimbursePage.js +++ b/src/pages/workspace/reimburse/WorkspaceReimbursePage.js @@ -1,13 +1,21 @@ import React from 'react'; import PropTypes from 'prop-types'; +import lodashGet from 'lodash/get'; +import {withOnyx} from 'react-native-onyx'; import withLocalize, {withLocalizePropTypes} from '../../../components/withLocalize'; -import WorkspaceReimburseView from './WorkspaceReimburseView'; -import WorkspacePageWithSections from '../WorkspacePageWithSections'; +import BankAccount from '../../../libs/models/BankAccount'; import CONST from '../../../CONST'; import compose from '../../../libs/compose'; +import ONYXKEYS from '../../../ONYXKEYS'; +import reimbursementAccountPropTypes from '../../ReimbursementAccount/reimbursementAccountPropTypes'; import withPolicy, {policyPropTypes} from '../withPolicy'; +import WorkspaceReimburseView from './WorkspaceReimburseView'; +import WorkspacePageWithSections from '../WorkspacePageWithSections'; const propTypes = { + /** Bank account currently in setup */ + reimbursementAccount: reimbursementAccountPropTypes, + /** The route object passed to this page from the navigator */ route: PropTypes.shape({ /** Each parameter passed via the URL */ @@ -21,23 +29,37 @@ const propTypes = { ...withLocalizePropTypes, }; -const WorkspaceReimbursePage = props => ( - - {hasVBA => ( - - )} - -); +const defaultProps = { + reimbursementAccount: {}, +}; -WorkspaceReimbursePage.propTypes = propTypes; +const WorkspaceReimbursePage = (props) => { + const achState = lodashGet(props.reimbursementAccount, 'achData.state', ''); + const hasVBBA = achState === BankAccount.STATE.OPEN; + return ( + + {() => ( + + )} + + ); +}; + +WorkspaceReimbursePage.defaultProps = defaultProps; WorkspaceReimbursePage.displayName = 'WorkspaceReimbursePage'; +WorkspaceReimbursePage.propTypes = propTypes; export default compose( withPolicy, + withOnyx({ + reimbursementAccount: { + key: ONYXKEYS.REIMBURSEMENT_ACCOUNT, + }, + }), withLocalize, )(WorkspaceReimbursePage); diff --git a/src/pages/workspace/reimburse/WorkspaceReimburseView.js b/src/pages/workspace/reimburse/WorkspaceReimburseView.js index f077583faa01..3f251e058df5 100644 --- a/src/pages/workspace/reimburse/WorkspaceReimburseView.js +++ b/src/pages/workspace/reimburse/WorkspaceReimburseView.js @@ -25,6 +25,9 @@ import networkPropTypes from '../../../components/networkPropTypes'; import Log from '../../../libs/Log'; const propTypes = { + /** has free plan VBBA setup */ + hasVBBA: PropTypes.bool.isRequired, + /** Policy values needed in the component */ policy: PropTypes.shape({ id: PropTypes.string, @@ -267,7 +270,7 @@ class WorkspaceReimburseView extends React.Component { - {this.props.hasVBA ? ( + {this.props.hasVBBA ? (
( - - {(hasVBA, policyID) => ( - <> - {!hasVBA && ( - - )} - {hasVBA && ( - +const defaultProps = { + reimbursementAccount: {}, +}; + +class WorkspaceTravelPage extends React.Component { + componentDidMount() { + BankAccounts.openWorkspaceView(); + } + + render() { + const achState = lodashGet(this.props.reimbursementAccount, 'achData.state', ''); + const hasVBBA = achState === BankAccount.STATE.OPEN; + return ( + + {policyID => ( + <> + {!hasVBBA && ( + + )} + {hasVBBA && ( + + )} + )} - - )} - -); + + ); + } +} WorkspaceTravelPage.propTypes = propTypes; -WorkspaceTravelPage.displayName = 'WorkspaceTravelPage'; +WorkspaceTravelPage.defaultProps = defaultProps; -export default withLocalize(WorkspaceTravelPage); +export default compose( + withOnyx({ + reimbursementAccount: { + key: ONYXKEYS.REIMBURSEMENT_ACCOUNT, + }, + }), + withLocalize, +)(WorkspaceTravelPage);