diff --git a/src/libs/PolicyUtils.js b/src/libs/PolicyUtils.js index 80c837d32557..632fddcf1182 100644 --- a/src/libs/PolicyUtils.js +++ b/src/libs/PolicyUtils.js @@ -1,5 +1,6 @@ import _ from 'underscore'; import lodashGet from 'lodash/get'; +import Str from 'expensify-common/lib/str'; import CONST from '../CONST'; import ONYXKEYS from '../ONYXKEYS'; @@ -75,10 +76,20 @@ function shouldShowPolicy(policy, isOffline) { ); } +/** + * @param {string} email + * @returns {boolean} + */ +function isExpensifyTeam(email) { + const emailDomain = Str.extractEmailDomain(email); + return emailDomain === CONST.EXPENSIFY_PARTNER_NAME || emailDomain === CONST.EMAIL.GUIDES_DOMAIN; +} + export { hasPolicyMemberError, hasPolicyError, hasCustomUnitsError, getPolicyBrickRoadIndicatorStatus, shouldShowPolicy, + isExpensifyTeam, }; diff --git a/src/pages/workspace/WorkspaceMembersPage.js b/src/pages/workspace/WorkspaceMembersPage.js index 812a817dc503..e9bccbca50f6 100644 --- a/src/pages/workspace/WorkspaceMembersPage.js +++ b/src/pages/workspace/WorkspaceMembersPage.js @@ -33,6 +33,8 @@ import * as ReportUtils from '../../libs/ReportUtils'; import FormHelpMessage from '../../components/FormHelpMessage'; import TextInput from '../../components/TextInput'; import KeyboardDismissingFlatList from '../../components/KeyboardDismissingFlatList'; +import withCurrentUserPersonalDetails from '../../components/withCurrentUserPersonalDetails'; +import * as PolicyUtils from '../../libs/PolicyUtils'; const propTypes = { /** The personal details of the person who is logged in */ @@ -247,11 +249,11 @@ class WorkspaceMembersPage extends React.Component { } /** - * @param {String} value + * @param {String} [value = ''] * @param {String} keyword * @returns {Boolean} */ - isKeywordMatch(value, keyword) { + isKeywordMatch(value = '', keyword) { return value.trim().toLowerCase().includes(keyword); } @@ -335,6 +337,18 @@ class WorkspaceMembersPage extends React.Component { || this.isKeywordMatch(member.firstName, searchValue) || this.isKeywordMatch(member.lastName, searchValue)); + data = _.reject(data, (member) => { + // If this policy is owned by Expensify then show all support (expensify.com or team.expensify.com) emails + if (PolicyUtils.isExpensifyTeam(lodashGet(this.props.policy, 'owner'))) { + return; + } + + // We don't want to show guides as policy members unless the user is not a guide. Some customers get confused when they + // see random people added to their policy, but guides having access to the policies help set them up. + const isCurrentUserExpensifyTeam = PolicyUtils.isExpensifyTeam(this.props.currentUserPersonalDetails.login); + return !isCurrentUserExpensifyTeam && PolicyUtils.isExpensifyTeam(member.login); + }); + _.each(data, (member) => { if (member.login === this.props.session.email || member.login === this.props.policy.owner || member.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) { return; @@ -426,13 +440,11 @@ class WorkspaceMembersPage extends React.Component { /> ) : ( - !_.isEmpty(policyMemberList) && ( - - - {this.props.translate('common.noResultsFound')} - - - ) + + + {this.props.translate('common.noResultsFound')} + + )} @@ -458,4 +470,5 @@ export default compose( key: ONYXKEYS.SESSION, }, }), + withCurrentUserPersonalDetails, )(WorkspaceMembersPage);