Skip to content

Commit

Permalink
applying all the same changes in 'pages/iou/steps/MoneyRequstParticip…
Browse files Browse the repository at this point in the history
…antsPage/MoneyRequestParticipantsSelector.js'
  • Loading branch information
brunovjk committed Jan 15, 2024
1 parent 87f5cf5 commit 97f1c9a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function MoneyRequestParticipantsPage({iou, selectedTab, route, transaction}) {
shouldEnableMaxHeight={DeviceCapabilities.canUseTouchScreen()}
testID={MoneyRequestParticipantsPage.displayName}
>
{({safeAreaPaddingBottomStyle}) => (
{({didScreenTransitionEnd, safeAreaPaddingBottomStyle}) => (
<View style={styles.flex1}>
<HeaderWithBackButton
title={headerTitle}
Expand All @@ -145,6 +145,7 @@ function MoneyRequestParticipantsPage({iou, selectedTab, route, transaction}) {
iouType={iouType}
isDistanceRequest={isDistanceRequest}
isScanRequest={isScanRequest}
didScreenTransitionEnd={didScreenTransitionEnd}
/>
</View>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import lodashGet from 'lodash/get';
import PropTypes from 'prop-types';
import React, {useCallback, useMemo, useState} from 'react';
import React, {useCallback, useEffect,useMemo} from 'react';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
Expand All @@ -10,16 +10,19 @@ import {usePersonalDetails} from '@components/OnyxProvider';
import {PressableWithFeedback} from '@components/Pressable';
import SelectCircle from '@components/SelectCircle';
import SelectionList from '@components/SelectionList';
import useDebouncedState from '@hooks/useDebouncedState';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useThemeStyles from '@hooks/useThemeStyles';
import * as Report from '@libs/actions/Report';
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
import * as OptionsListUtils from '@libs/OptionsListUtils';
import * as ReportUtils from '@libs/ReportUtils';
import MoneyRequestReferralProgramCTA from '@pages/iou/MoneyRequestReferralProgramCTA';
import reportPropTypes from '@pages/reportPropTypes';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import {isNotEmptyObject} from '@src/types/utils/EmptyObject';

const propTypes = {
/** Beta features list */
Expand Down Expand Up @@ -59,6 +62,9 @@ const propTypes = {

/** Whether we are searching for reports in the server */
isSearchingForReports: PropTypes.bool,

/** Whether the parent screen transition has ended */
didScreenTransitionEnd: PropTypes.bool,
};

const defaultProps = {
Expand All @@ -68,6 +74,7 @@ const defaultProps = {
betas: [],
isDistanceRequest: false,
isSearchingForReports: false,
didScreenTransitionEnd: false,
};

function MoneyRequestParticipantsSelector({
Expand All @@ -81,16 +88,24 @@ function MoneyRequestParticipantsSelector({
iouType,
isDistanceRequest,
isSearchingForReports,
didScreenTransitionEnd,
}) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const [searchTerm, setSearchTerm] = useState('');
const [searchTerm, debouncedSearchTerm, setSearchTerm] = useDebouncedState('');
const {isOffline} = useNetwork();
const personalDetails = usePersonalDetails();

const offlineMessage = isOffline ? `${translate('common.youAppearToBeOffline')} ${translate('search.resultsAreLimited')}` : '';

const newChatOptions = useMemo(() => {
if (!didScreenTransitionEnd) {
return {
recentReports: {},
personalDetails: {},
userToInvite: {},
};
}
const chatOptions = OptionsListUtils.getFilteredOptions(
reports,
personalDetails,
Expand Down Expand Up @@ -121,7 +136,7 @@ function MoneyRequestParticipantsSelector({
personalDetails: chatOptions.personalDetails,
userToInvite: chatOptions.userToInvite,
};
}, [betas, reports, participants, personalDetails, searchTerm, iouType, isDistanceRequest]);
}, [betas, didScreenTransitionEnd, reports, participants, personalDetails, searchTerm, iouType, isDistanceRequest]);

const maxParticipantsReached = participants.length === CONST.REPORT.MAXIMUM_PARTICIPANTS;

Expand Down Expand Up @@ -166,7 +181,7 @@ function MoneyRequestParticipantsSelector({
});
indexOffset += newChatOptions.personalDetails.length;

if (newChatOptions.userToInvite && !OptionsListUtils.isCurrentUser(newChatOptions.userToInvite)) {
if (isNotEmptyObject(newChatOptions.userToInvite) && !OptionsListUtils.isCurrentUser(newChatOptions.userToInvite)) {
newSections.push({
title: undefined,
data: _.map([newChatOptions.userToInvite], (participant) => {
Expand Down Expand Up @@ -258,11 +273,12 @@ function MoneyRequestParticipantsSelector({
[maxParticipantsReached, newChatOptions.personalDetails.length, newChatOptions.recentReports.length, newChatOptions.userToInvite, participants, searchTerm],
);

// When search term updates we will fetch any reports
const setSearchTermAndSearchInServer = useCallback((text = '') => {
Report.searchInServer(text);
setSearchTerm(text);
}, []);
useEffect(() => {
if (!debouncedSearchTerm.length) {
return;
}
Report.searchInServer(debouncedSearchTerm);
}, [debouncedSearchTerm]);

// Right now you can't split a request with a workspace and other additional participants
// This is getting properly fixed in https://github.com/Expensify/App/issues/27508, but as a stop-gap to prevent
Expand Down Expand Up @@ -341,21 +357,24 @@ function MoneyRequestParticipantsSelector({
[addParticipantToSelection, isAllowedToSplit, styles, translate],
);

const isOptionsDataReady = useMemo(() => ReportUtils.isReportDataReady() && OptionsListUtils.isPersonalDetailsReady(personalDetails), [personalDetails]);

return (
<View style={[styles.flex1, styles.w100, participants.length > 0 ? safeAreaPaddingBottomStyle : {}]}>
<SelectionList
onConfirm={handleConfirmSelection}
sections={sections}
sections={didScreenTransitionEnd && isOptionsDataReady ? sections : CONST.EMPTY_ARRAY}
textInputValue={searchTerm}
textInputLabel={translate('optionsSelector.nameEmailOrPhoneNumber')}
textInputHint={offlineMessage}
onChangeText={setSearchTermAndSearchInServer}
onChangeText={setSearchTerm}
shouldPreventDefaultFocusOnSelectRow={!DeviceCapabilities.canUseTouchScreen()}
onSelectRow={addSingleParticipant}
footerContent={footerContent}
headerMessage={headerMessage}
showLoadingPlaceholder={isSearchingForReports}
showLoadingPlaceholder={!(didScreenTransitionEnd && isOptionsDataReady)}
rightHandSideComponent={itemRightSideComponent}
isLoadingNewOptions={isSearchingForReports}
/>
</View>
);
Expand Down

0 comments on commit 97f1c9a

Please sign in to comment.