Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 25 additions & 20 deletions src/pages/iou/request/MoneyRequestAccountantSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import type {GestureResponderEvent} from 'react-native';
import EmptySelectionListContent from '@components/EmptySelectionListContent';
import {usePersonalDetails} from '@components/OnyxListItemProvider';
import {useOptionsList} from '@components/OptionListContextProvider';
// eslint-disable-next-line no-restricted-imports
import SelectionList from '@components/SelectionListWithSections';
import InviteMemberListItem from '@components/SelectionListWithSections/InviteMemberListItem';
import InviteMemberListItem from '@components/SelectionList/ListItem/InviteMemberListItem';
import SelectionListWithSections from '@components/SelectionList/SelectionListWithSections';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useDebouncedState from '@hooks/useDebouncedState';
import useLocalize from '@hooks/useLocalize';
Expand All @@ -16,7 +15,6 @@ import useOnyx from '@hooks/useOnyx';
import useScreenWrapperTransitionStatus from '@hooks/useScreenWrapperTransitionStatus';
import {canUseTouchScreen} from '@libs/DeviceCapabilities';
import memoize from '@libs/memoize';
import type {Section} from '@libs/OptionsListUtils';
import {
filterAndOrderOptions,
formatSectionsFromSearchTerm,
Expand All @@ -28,6 +26,7 @@ import {
isCurrentUser,
orderOptions,
} from '@libs/OptionsListUtils';
import type {SelectionListSections} from '@libs/OptionsListUtils/types';
import {searchInServer} from '@userActions/Report';
import type {IOUAction, IOUType} from '@src/CONST';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -145,7 +144,7 @@ function MoneyRequestAccountantSelector({onFinish, onAccountantSelected, iouType
* Returns the sections needed for the OptionsSelector
*/
const [sections, header] = useMemo(() => {
const newSections: Section[] = [];
const newSections: SelectionListSections = [];
if (!areOptionsInitialized || !didScreenTransitionEnd) {
return [newSections, ''];
}
Expand All @@ -164,20 +163,18 @@ function MoneyRequestAccountantSelector({onFinish, onAccountantSelected, iouType
undefined,
reportAttributesDerived,
);
// Just a temporary fix to satisfy the type checker
// Will be fixed when migrating to use new SelectionListWithSections
newSections.push({...formatResults.section, title: undefined, shouldShow: true});
newSections.push({...formatResults.section, sectionIndex: 0});

newSections.push({
title: translate('common.recents'),
data: fiveRecents,
shouldShow: fiveRecents.length > 0,
sectionIndex: 1,
});

newSections.push({
title: translate('common.contacts'),
data: contactsWithRestOfRecents,
shouldShow: contactsWithRestOfRecents.length > 0,
sectionIndex: 2,
});

if (
Expand All @@ -196,7 +193,7 @@ function MoneyRequestAccountantSelector({onFinish, onAccountantSelected, iouType
? getPolicyExpenseReportOption(participant, currentUserAccountID, personalDetails, reportAttributesDerived)
: getParticipantsOption(participant, personalDetails);
}),
shouldShow: true,
sectionIndex: 3,
});
}

Expand Down Expand Up @@ -255,23 +252,31 @@ function MoneyRequestAccountantSelector({onFinish, onAccountantSelected, iouType

const shouldShowListEmptyContent = useMemo(() => optionLength === 0 && !showLoadingPlaceholder, [optionLength, showLoadingPlaceholder]);

const textInputOptions = {
value: searchTerm,
label: translate('selectionList.nameEmailOrPhoneNumber'),
onChangeText: setSearchTerm,
headerMessage: header,
hint: offlineMessage,
};

return (
<SelectionList
onConfirm={handleConfirmSelection}
sections={areOptionsInitialized ? sections : CONST.EMPTY_ARRAY}
<SelectionListWithSections
sections={areOptionsInitialized ? sections : []}
ListItem={InviteMemberListItem}
textInputValue={searchTerm}
textInputLabel={translate('selectionList.nameEmailOrPhoneNumber')}
textInputHint={offlineMessage}
onChangeText={setSearchTerm}
shouldPreventDefaultFocusOnSelectRow={!canUseTouchScreen()}
onSelectRow={selectAccountant}
confirmButtonOptions={{
onConfirm: handleConfirmSelection,
}}
shouldShowTextInput
shouldSingleExecuteRowSelect
textInputOptions={textInputOptions}
listEmptyContent={<EmptySelectionListContent contentType={iouType} />}
headerMessage={header}
showLoadingPlaceholder={showLoadingPlaceholder}
isLoadingNewOptions={!!isSearchingForReports}
shouldShowListEmptyContent={shouldShowListEmptyContent}
showListEmptyContent={shouldShowListEmptyContent}
disableMaintainingScrollPosition
/>
);
}
Expand Down
Loading