From a6525fea4bc5072a3c709537c23ece8458085580 Mon Sep 17 00:00:00 2001 From: code0406 Date: Tue, 4 Jul 2023 08:47:14 -0400 Subject: [PATCH 1/3] migrated to function component --- src/pages/workspace/WorkspacesListPage.js | 83 ++++++++++------------- 1 file changed, 37 insertions(+), 46 deletions(-) diff --git a/src/pages/workspace/WorkspacesListPage.js b/src/pages/workspace/WorkspacesListPage.js index 6f11c70a6707..a91232ac924b 100755 --- a/src/pages/workspace/WorkspacesListPage.js +++ b/src/pages/workspace/WorkspacesListPage.js @@ -99,31 +99,23 @@ function dismissWorkspaceError(policyID, pendingAction) { throw new Error('Not implemented'); } -class WorkspacesListPage extends Component { - constructor(props) { - super(props); - - this.getWalletBalance = this.getWalletBalance.bind(this); - this.getWorkspaces = this.getWorkspaces.bind(this); - this.getMenuItem = this.getMenuItem.bind(this); - } - +function WorkspacesListPage({policies, allPolicyMembers, reimbursementAccount, userWallet, betas, network, translate}) { /** * @param {Boolean} isPaymentItem whether the item being rendered is the payments menu item * @returns {Number} the user wallet balance */ - getWalletBalance(isPaymentItem) { - return isPaymentItem && Permissions.canUseWallet(this.props.betas) ? CurrencyUtils.convertToDisplayString(this.props.userWallet.currentBalance) : undefined; + function getWalletBalance(isPaymentItem) { + return isPaymentItem && Permissions.canUseWallet(betas) ? CurrencyUtils.convertToDisplayString(userWallet.currentBalance) : undefined; } /** * Add free policies (workspaces) to the list of menu items and returns the list of menu items * @returns {Array} the menu item list */ - getWorkspaces() { - const reimbursementAccountBrickRoadIndicator = !_.isEmpty(this.props.reimbursementAccount.errors) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : ''; - return _.chain(this.props.policies) - .filter((policy) => PolicyUtils.shouldShowPolicy(policy, this.props.network.isOffline)) + function getWorkspaces() { + const reimbursementAccountBrickRoadIndicator = !_.isEmpty(reimbursementAccount.errors) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : ''; + return _.chain(policies) + .filter((policy) => PolicyUtils.shouldShowPolicy(policy, network.isOffline)) .map((policy) => ({ title: policy.name, icon: policy.avatar ? policy.avatar : ReportUtils.getDefaultWorkspaceAvatar(policy.name), @@ -131,7 +123,7 @@ class WorkspacesListPage extends Component { action: () => Navigation.navigate(ROUTES.getWorkspaceInitialRoute(policy.id)), iconFill: themeColors.textLight, fallbackIcon: Expensicons.FallbackWorkspaceAvatar, - brickRoadIndicator: reimbursementAccountBrickRoadIndicator || PolicyUtils.getPolicyBrickRoadIndicatorStatus(policy, this.props.allPolicyMembers), + brickRoadIndicator: reimbursementAccountBrickRoadIndicator || PolicyUtils.getPolicyBrickRoadIndicatorStatus(policy, allPolicyMembers), pendingAction: policy.pendingAction, errors: policy.errors, dismissError: () => dismissWorkspaceError(policy.id, policy.pendingAction), @@ -148,8 +140,8 @@ class WorkspacesListPage extends Component { * @param {Number} index * @returns {JSX} */ - getMenuItem(item, index) { - const keyTitle = item.translationKey ? this.props.translate(item.translationKey) : item.title; + function getMenuItem(item, index) { + const keyTitle = item.translationKey ? translate(item.translationKey) : item.title; const isPaymentItem = item.translationKey === 'common.payments'; return ( @@ -168,7 +160,7 @@ class WorkspacesListPage extends Component { iconStyles={item.iconStyles} iconFill={item.iconFill} shouldShowRightIcon - badgeText={this.getWalletBalance(isPaymentItem)} + badgeText={getWalletBalance(isPaymentItem)} fallbackIcon={item.fallbackIcon} brickRoadIndicator={item.brickRoadIndicator} disabled={item.disabled} @@ -177,34 +169,33 @@ class WorkspacesListPage extends Component { ); } - render() { - const workspaces = this.getWorkspaces(); - return ( - - Navigation.goBack(ROUTES.SETTINGS)} + const workspaces = getWorkspaces(); + + return ( + + Navigation.goBack(ROUTES.SETTINGS)} + /> + {_.isEmpty(workspaces) ? ( + - {_.isEmpty(workspaces) ? ( - - ) : ( - {_.map(workspaces, (item, index) => this.getMenuItem(item, index))} - )} - -