diff --git a/src/libs/PolicyUtils.js b/src/libs/PolicyUtils.js index cd15ea19a160..d7a4c4fdff45 100644 --- a/src/libs/PolicyUtils.js +++ b/src/libs/PolicyUtils.js @@ -4,6 +4,15 @@ import Str from 'expensify-common/lib/str'; import CONST from '../CONST'; import ONYXKEYS from '../ONYXKEYS'; +/** + * Filter out the active policies, which will exclude policies with pending deletion + * @param {Object} policies + * @returns {Array} + */ +function getActivePolicies(policies) { + return _.filter(policies, (policy) => policy && policy.type === CONST.POLICY.TYPE.FREE && policy.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE); +} + /** * Checks if we have any errors stored within the POLICY_MEMBERS. Determines whether we should show a red brick road error or not. * Data structure: {accountID: {role:'user', errors: []}, accountID2: {role:'admin', errors: [{1231312313: 'Unable to do X'}]}, ...} @@ -134,6 +143,7 @@ function getClientPolicyMemberEmailsToAccountIDs(policyMembers, personalDetails) } export { + getActivePolicies, hasPolicyMemberError, hasPolicyError, hasPolicyErrorFields, diff --git a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js index 3e95818c1137..24c00a7af405 100644 --- a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js +++ b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js @@ -1,5 +1,4 @@ import React, {useState, useEffect, useCallback, useImperativeHandle, forwardRef} from 'react'; -import _ from 'underscore'; import {withOnyx} from 'react-native-onyx'; import PropTypes from 'prop-types'; import lodashGet from 'lodash/get'; @@ -12,6 +11,7 @@ import NAVIGATORS from '../../../../NAVIGATORS'; import SCREENS from '../../../../SCREENS'; import Permissions from '../../../../libs/Permissions'; import * as Policy from '../../../../libs/actions/Policy'; +import * as PolicyUtils from '../../../../libs/PolicyUtils'; import PopoverMenu from '../../../../components/PopoverMenu'; import CONST from '../../../../CONST'; import FloatingActionButton from '../../../../components/FloatingActionButton'; @@ -35,6 +35,7 @@ const policySelector = (policy) => policy && { type: policy.type, role: policy.role, + pendingAction: policy.pendingAction, }; const propTypes = { @@ -171,8 +172,7 @@ function FloatingActionButtonAndPopover(props) { }, })); - // Workspaces are policies with type === 'free' - const workspaces = _.filter(props.allPolicies, (policy) => policy && policy.type === CONST.POLICY.TYPE.FREE); + const workspaces = PolicyUtils.getActivePolicies(props.allPolicies); return ( diff --git a/src/pages/workspace/WorkspaceNewRoomPage.js b/src/pages/workspace/WorkspaceNewRoomPage.js index db010429980a..104270d22976 100644 --- a/src/pages/workspace/WorkspaceNewRoomPage.js +++ b/src/pages/workspace/WorkspaceNewRoomPage.js @@ -18,6 +18,7 @@ import Permissions from '../../libs/Permissions'; import Log from '../../libs/Log'; import * as ErrorUtils from '../../libs/ErrorUtils'; import * as ValidationUtils from '../../libs/ValidationUtils'; +import * as PolicyUtils from '../../libs/PolicyUtils'; import Form from '../../components/Form'; import shouldDelayFocus from '../../libs/shouldDelayFocus'; import policyMemberPropType from '../policyMemberPropType'; @@ -106,15 +107,7 @@ function WorkspaceNewRoomPage(props) { [props.reports], ); - // Workspaces are policies with type === 'free' - const workspaceOptions = useMemo( - () => - _.map( - _.filter(props.policies, (policy) => policy && policy.type === CONST.POLICY.TYPE.FREE), - (policy) => ({label: policy.name, key: policy.id, value: policy.id}), - ), - [props.policies], - ); + const workspaceOptions = useMemo(() => _.map(PolicyUtils.getActivePolicies(props.policies), (policy) => ({label: policy.name, key: policy.id, value: policy.id})), [props.policies]); const visibilityOptions = useMemo( () =>