diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index c8f83ed2f2a2..15155d5c4e52 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -195,10 +195,10 @@ function getPersonalDetailsForLogins(logins, personalDetails) { /** * Return true if personal details data is ready, i.e. report list options can be created. * @param {Object} personalDetails - * @returns {boolean} + * @returns {Boolean} */ function isPersonalDetailsReady(personalDetails) { - return !_.isEmpty(personalDetails) && !_.some(_.keys(personalDetails), (key) => !personalDetails[key].login); + return !_.isEmpty(personalDetails) && _.some(_.keys(personalDetails), (key) => personalDetails[key].login); } /** diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 15b17acf2924..0119762ec543 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1926,6 +1926,14 @@ function shouldReportShowSubscript(report) { return isExpenseReport(report); } +/** + * Return true if reports data exists + * @returns {Boolean} + */ +function isReportDataReady() { + return !_.isEmpty(allReports) && _.some(_.keys(allReports), (key) => allReports[key].reportID); +} + export { getReportParticipantsTitle, isReportMessageAttachment, @@ -2006,5 +2014,6 @@ export { getWhisperDisplayNames, getWorkspaceAvatar, shouldReportShowSubscript, + isReportDataReady, isSettled, }; diff --git a/src/pages/NewChatPage.js b/src/pages/NewChatPage.js index 7ef2836b3e17..1765c700221e 100755 --- a/src/pages/NewChatPage.js +++ b/src/pages/NewChatPage.js @@ -5,6 +5,7 @@ import PropTypes from 'prop-types'; import {withOnyx} from 'react-native-onyx'; import OptionsSelector from '../components/OptionsSelector'; import * as OptionsListUtils from '../libs/OptionsListUtils'; +import * as ReportUtils from '../libs/ReportUtils'; import ONYXKEYS from '../ONYXKEYS'; import styles from '../styles/styles'; import * as Report from '../libs/actions/Report'; @@ -31,9 +32,6 @@ const propTypes = { /** All reports shared with the user */ reports: PropTypes.objectOf(reportPropTypes), - /** Indicates whether the reports data is ready */ - isLoadingReportData: PropTypes.bool, - ...windowDimensionsPropTypes, ...withLocalizePropTypes, @@ -44,7 +42,6 @@ const defaultProps = { betas: [], personalDetails: {}, reports: {}, - isLoadingReportData: true, }; class NewChatPage extends Component { @@ -226,7 +223,7 @@ class NewChatPage extends Component { this.state.searchTerm, maxParticipantsReached, ); - const isOptionsDataReady = !this.props.isLoadingReportData && OptionsListUtils.isPersonalDetailsReady(this.props.personalDetails); + const isOptionsDataReady = ReportUtils.isReportDataReady() && OptionsListUtils.isPersonalDetailsReady(this.props.personalDetails); return ( @@ -218,8 +215,5 @@ export default compose( betas: { key: ONYXKEYS.BETAS, }, - isLoadingReportData: { - key: ONYXKEYS.IS_LOADING_REPORT_DATA, - }, }), )(SearchPage); diff --git a/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js b/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js index a3a7ee6e33f6..74a7c7961a9d 100755 --- a/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js +++ b/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js @@ -3,6 +3,7 @@ import PropTypes from 'prop-types'; import {withOnyx} from 'react-native-onyx'; import _ from 'underscore'; import * as OptionsListUtils from '../../../../libs/OptionsListUtils'; +import * as ReportUtils from '../../../../libs/ReportUtils'; import OptionsSelector from '../../../../components/OptionsSelector'; import ONYXKEYS from '../../../../ONYXKEYS'; import withLocalize, {withLocalizePropTypes} from '../../../../components/withLocalize'; @@ -27,9 +28,6 @@ const propTypes = { /** All reports shared with the user */ reports: PropTypes.objectOf(reportPropTypes), - /** Indicates whether report data is ready */ - isLoadingReportData: PropTypes.bool, - /** padding bottom style of safe area */ safeAreaPaddingBottomStyle: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.object), PropTypes.object]), @@ -44,7 +42,6 @@ const defaultProps = { personalDetails: {}, reports: {}, betas: [], - isLoadingReportData: true, }; class MoneyRequestParticipantsSelector extends Component { @@ -154,7 +151,7 @@ class MoneyRequestParticipantsSelector extends Component { Boolean(this.state.userToInvite), this.state.searchTerm, ); - const isOptionsDataReady = !this.props.isLoadingReportData && OptionsListUtils.isPersonalDetailsReady(this.props.personalDetails); + const isOptionsDataReady = ReportUtils.isReportDataReady() && OptionsListUtils.isPersonalDetailsReady(this.props.personalDetails); return ( 0 ? this.props.safeAreaPaddingBottomStyle : {}]}> @@ -254,8 +251,5 @@ export default compose( betas: { key: ONYXKEYS.BETAS, }, - isLoadingReportData: { - key: ONYXKEYS.IS_LOADING_REPORT_DATA, - }, }), )(MoneyRequestParticipantsSplitSelector);