diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index d4066676a79e4..2a09c14956b70 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -197,6 +197,7 @@ function isSearchStringMatch(searchValue, searchText, participantNames) { * @private */ function getOptions(reports, personalDetails, draftComments, activeReportID, { + betas = [], selectedOptions = [], maxRecentReportsToShow = 0, excludeConcierge = false, @@ -335,7 +336,7 @@ function getOptions(reports, personalDetails, draftComments, activeReportID, { && personalDetailsOptions.length === 0 && _.every(selectedOptions, option => option.login !== searchValue) && ((Str.isValidEmail(searchValue) && !Str.isDomainEmail(searchValue)) || Str.isValidPhone(searchValue)) - && (searchValue !== CONST.EMAIL.CHRONOS || Permissions.canUseChronos()) + && (searchValue !== CONST.EMAIL.CHRONOS || Permissions.canUseChronos(betas)) ) { // If the phone number doesn't have an international code then let's prefix it with the // current users international code based on their IP address. @@ -362,14 +363,17 @@ function getOptions(reports, personalDetails, draftComments, activeReportID, { * @param {Object} reports * @param {Object} personalDetails * @param {String} searchValue + * @param {Array} betas * @returns {Object} */ function getSearchOptions( reports, personalDetails, searchValue = '', + betas, ) { return getOptions(reports, personalDetails, {}, 0, { + betas, searchValue, includeRecentReports: true, includeMultipleParticipantReports: true, @@ -389,6 +393,7 @@ function getSearchOptions( * @param {Object} personalDetails * @param {String} searchValue * @param {Boolean} excludeConcierge + * @param {Array} betas * @returns {Object} */ function getNewChatOptions( @@ -396,8 +401,10 @@ function getNewChatOptions( personalDetails, searchValue = '', excludeConcierge, + betas, ) { return getOptions(reports, personalDetails, {}, 0, { + betas, searchValue, includePersonalDetails: true, includeRecentReports: true, @@ -445,6 +452,7 @@ function getIOUConfirmationOptionsFromParticipants( * @param {String} searchValue * @param {Array} selectedOptions * @param {Boolean} excludeConcierge + * @param {Array} betas * @returns {Object} */ function getNewGroupOptions( @@ -453,8 +461,10 @@ function getNewGroupOptions( searchValue = '', selectedOptions = [], excludeConcierge, + betas, ) { return getOptions(reports, personalDetails, {}, 0, { + betas, searchValue, selectedOptions, includeRecentReports: true, diff --git a/src/libs/Permissions.js b/src/libs/Permissions.js index f554fa45bb43b..6adeabdba6417 100644 --- a/src/libs/Permissions.js +++ b/src/libs/Permissions.js @@ -1,35 +1,30 @@ import _ from 'underscore'; -import Onyx from 'react-native-onyx'; import {isDevelopment} from './Environment/Environment'; import CONST from '../CONST'; -import ONYXKEYS from '../ONYXKEYS'; - -let betas; -Onyx.connect({ - key: ONYXKEYS.BETAS, - callback: val => betas = val || [], -}); /** * @private + * @param {Array} betas * @returns {Boolean} */ -function canUseAllBetas() { +function canUseAllBetas(betas) { return isDevelopment() || _.contains(betas, CONST.BETAS.ALL); } /** + * @param {Array} betas * @returns {Boolean} */ -function canUseChronos() { - return _.contains(betas, CONST.BETAS.CHRONOS_IN_CASH) || canUseAllBetas(); +function canUseChronos(betas) { + return _.contains(betas, CONST.BETAS.CHRONOS_IN_CASH) || canUseAllBetas(betas); } /** + * @param {Array} betas * @returns {Boolean} */ -function canUseIOU() { - return _.contains(betas, CONST.BETAS.IOU) || canUseAllBetas(); +function canUseIOU(betas) { + return _.contains(betas, CONST.BETAS.IOU) || canUseAllBetas(betas); } export default { diff --git a/src/pages/NewChatPage.js b/src/pages/NewChatPage.js index 47e15eec3575d..6b94785958f28 100755 --- a/src/pages/NewChatPage.js +++ b/src/pages/NewChatPage.js @@ -32,6 +32,9 @@ const personalDetailsPropTypes = PropTypes.shape({ }); const propTypes = { + /** Beta features list */ + betas: PropTypes.arrayOf(PropTypes.string).isRequired, + /** All of the personal details for everyone */ personalDetails: PropTypes.objectOf(personalDetailsPropTypes).isRequired, @@ -62,6 +65,7 @@ class NewChatPage extends Component { props.reports, props.personalDetails, '', + props.betas, ); this.state = { @@ -149,6 +153,7 @@ class NewChatPage extends Component { this.props.reports, this.props.personalDetails, searchValue, + this.props.betas, ); this.setState({ searchValue, @@ -187,5 +192,8 @@ export default compose( session: { key: ONYXKEYS.SESSION, }, + betas: { + key: ONYXKEYS.BETAS, + }, }), )(NewChatPage); diff --git a/src/pages/NewGroupPage.js b/src/pages/NewGroupPage.js index 1b86984d9ba30..f7add0b42ba04 100755 --- a/src/pages/NewGroupPage.js +++ b/src/pages/NewGroupPage.js @@ -32,6 +32,9 @@ const personalDetailsPropTypes = PropTypes.shape({ }); const propTypes = { + /** Beta features list */ + betas: PropTypes.arrayOf(PropTypes.string).isRequired, + /** All of the personal details for everyone */ personalDetails: PropTypes.objectOf(personalDetailsPropTypes).isRequired, @@ -66,6 +69,8 @@ class NewGroupPage extends Component { props.personalDetails, '', [], + false, + props.betas, ); this.state = { @@ -163,6 +168,8 @@ class NewGroupPage extends Component { this.props.personalDetails, isOptionInList ? prevState.searchValue : '', newSelectedOptions, + false, + this.props.betas, ); return { @@ -212,6 +219,8 @@ class NewGroupPage extends Component { this.props.personalDetails, searchValue, [], + false, + this.props.betas, ); this.setState({ searchValue, @@ -262,5 +271,8 @@ export default compose( session: { key: ONYXKEYS.SESSION, }, + betas: { + key: ONYXKEYS.BETAS, + }, }), )(NewGroupPage); diff --git a/src/pages/SearchPage.js b/src/pages/SearchPage.js index db7162d8922de..fd835134f679c 100755 --- a/src/pages/SearchPage.js +++ b/src/pages/SearchPage.js @@ -34,6 +34,9 @@ const personalDetailsPropTypes = PropTypes.shape({ const propTypes = { /* Onyx Props */ + /** Beta features list */ + betas: PropTypes.arrayOf(PropTypes.string).isRequired, + /** All of the personal details for everyone */ personalDetails: PropTypes.objectOf(personalDetailsPropTypes).isRequired, @@ -69,6 +72,7 @@ class SearchPage extends Component { props.reports, props.personalDetails, '', + props.betas, ); this.state = { @@ -163,6 +167,7 @@ class SearchPage extends Component { this.props.reports, this.props.personalDetails, searchValue, + this.props.betas, ); this.setState({ searchValue, @@ -202,5 +207,8 @@ export default compose( session: { key: ONYXKEYS.SESSION, }, + betas: { + key: ONYXKEYS.BETAS, + }, }), )(SearchPage); diff --git a/src/pages/home/report/ReportActionCompose.js b/src/pages/home/report/ReportActionCompose.js index e1f0fecebbf88..ec8cc6a608254 100755 --- a/src/pages/home/report/ReportActionCompose.js +++ b/src/pages/home/report/ReportActionCompose.js @@ -53,6 +53,9 @@ import ReportActionPropTypes from './ReportActionPropTypes'; import {canEditReportAction} from '../../../libs/reportUtils'; const propTypes = { + /** Beta features list */ + betas: PropTypes.arrayOf(PropTypes.string).isRequired, + /** A method to call when the form is submitted */ onSubmit: PropTypes.func.isRequired, @@ -397,27 +400,32 @@ class ReportActionCompose extends React.Component { animationIn="fadeInUp" animationOut="fadeOutDown" menuItems={[ - ...(!hasConciergeParticipant && Permissions.canUseIOU() ? [ - hasMultipleParticipants - ? { - icon: Receipt, - text: this.props.translate('iou.splitBill'), - onSelected: () => { - Navigation.navigate( - ROUTES.getIouSplitRoute(this.props.reportID), - ); - }, - } - : { - icon: MoneyCircle, - text: this.props.translate('iou.requestMoney'), - onSelected: () => { - Navigation.navigate( - ROUTES.getIouRequestRoute(this.props.reportID), - ); + ...(!hasConciergeParticipant + && Permissions.canUseIOU(this.props.betas) ? [ + hasMultipleParticipants + ? { + icon: Receipt, + text: this.props.translate('iou.splitBill'), + onSelected: () => { + Navigation.navigate( + ROUTES.getIouSplitRoute( + this.props.reportID, + ), + ); + }, + } + : { + icon: MoneyCircle, + text: this.props.translate('iou.requestMoney'), + onSelected: () => { + Navigation.navigate( + ROUTES.getIouRequestRoute( + this.props.reportID, + ), + ); + }, }, - }, - ] : []), + ] : []), { icon: Paperclip, text: this.props.translate('reportActionCompose.addAttachment'), @@ -553,6 +561,9 @@ export default compose( withNavigationFocus, withLocalize, withOnyx({ + betas: { + key: ONYXKEYS.BETAS, + }, comment: { key: ({reportID}) => `${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${reportID}`, }, diff --git a/src/pages/home/sidebar/SidebarScreen.js b/src/pages/home/sidebar/SidebarScreen.js index 5d03df697d746..cdd674905b250 100755 --- a/src/pages/home/sidebar/SidebarScreen.js +++ b/src/pages/home/sidebar/SidebarScreen.js @@ -1,5 +1,7 @@ import React, {Component} from 'react'; import {View} from 'react-native'; +import {withOnyx} from 'react-native-onyx'; +import PropTypes from 'prop-types'; import styles from '../../../styles/styles'; import SidebarLinks from './SidebarLinks'; import CreateMenu from '../../../components/CreateMenu'; @@ -19,8 +21,12 @@ import { Receipt, } from '../../../components/Icon/Expensicons'; import Permissions from '../../../libs/Permissions'; +import ONYXKEYS from '../../../ONYXKEYS'; const propTypes = { + /** Beta features list */ + betas: PropTypes.arrayOf(PropTypes.string).isRequired, + ...windowDimensionsPropTypes, ...withLocalizePropTypes, @@ -107,7 +113,7 @@ class SidebarScreen extends Component { text: this.props.translate('sidebarScreen.newChat'), onSelected: () => Navigation.navigate(ROUTES.NEW_CHAT), }, - ...(Permissions.canUseIOU() ? [ + ...(Permissions.canUseIOU(this.props.betas) ? [ { icon: MoneyCircle, text: this.props.translate('iou.requestMoney'), @@ -119,7 +125,7 @@ class SidebarScreen extends Component { text: this.props.translate('sidebarScreen.newGroup'), onSelected: () => Navigation.navigate(ROUTES.NEW_GROUP), }, - ...(Permissions.canUseIOU() ? [ + ...(Permissions.canUseIOU(this.props.betas) ? [ { icon: Receipt, text: this.props.translate('iou.splitBill'), @@ -139,4 +145,9 @@ SidebarScreen.propTypes = propTypes; export default compose( withLocalize, withWindowDimensions, + withOnyx({ + betas: { + key: ONYXKEYS.BETAS, + }, + }), )(SidebarScreen);