Skip to content

Commit 6e871e8

Browse files
authored
Merge pull request Expensify#68899 from callstack-internal/66333-part3-migrating-loginutils-from-onyx-connect
[Part 3 of Migrating LoginUtils from Onyx.connect] Migrate filterOptions to use new method appendCountryCodeWithCountryCode
2 parents ec59f27 + 8d13aaf commit 6e871e8

19 files changed

Lines changed: 98 additions & 74 deletions

src/components/Search/FilterDropdowns/UserSelectPopup.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function UserSelectPopup({value, closeOverlay, onChange}: UserSelectPopupProps)
5353
const {shouldUseNarrowLayout} = useResponsiveLayout();
5454
const [accountID] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: true, selector: (onyxSession) => onyxSession?.accountID});
5555
const shouldFocusInputOnScreenFocus = canFocusInputOnScreenFocus();
56-
56+
const [countryCode] = useOnyx(ONYXKEYS.COUNTRY_CODE, {canBeMissing: false});
5757
const [searchTerm, setSearchTerm] = useState('');
5858
const [isSearchingForReports] = useOnyx(ONYXKEYS.IS_SEARCHING_FOR_REPORTS, {initWithStoredValues: false, canBeMissing: true});
5959
const initialSelectedOptions = useMemo(() => {
@@ -94,12 +94,12 @@ function UserSelectPopup({value, closeOverlay, onChange}: UserSelectPopupProps)
9494
}, [options.reports, options.personalDetails]);
9595

9696
const filteredOptions = useMemo(() => {
97-
return filterAndOrderOptions(optionsList, cleanSearchTerm, {
97+
return filterAndOrderOptions(optionsList, cleanSearchTerm, countryCode, {
9898
excludeLogins: CONST.EXPENSIFY_EMAILS_OBJECT,
9999
maxRecentReportsToShow: CONST.IOU.MAX_RECENT_REPORTS_TO_SHOW,
100100
canInviteUser: false,
101101
});
102-
}, [optionsList, cleanSearchTerm]);
102+
}, [optionsList, cleanSearchTerm, countryCode]);
103103

104104
const listData = useMemo(() => {
105105
const personalDetailList = filteredOptions.personalDetails.map((participant) => ({

src/components/Search/SearchFiltersChatsSelector.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ function SearchFiltersChatsSelector({initialReportIDs, onFiltersUpdate, isScreen
4646
});
4747

4848
const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: true});
49+
const [countryCode] = useOnyx(ONYXKEYS.COUNTRY_CODE, {canBeMissing: false});
4950
const [isSearchingForReports] = useOnyx(ONYXKEYS.IS_SEARCHING_FOR_REPORTS, {initWithStoredValues: false, canBeMissing: true});
5051
const [reportAttributesDerived] = useOnyx(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES, {canBeMissing: true, selector: (val) => val?.reports});
5152
const [selectedReportIDs, setSelectedReportIDs] = useState<string[]>(initialReportIDs);
@@ -68,11 +69,11 @@ function SearchFiltersChatsSelector({initialReportIDs, onFiltersUpdate, isScreen
6869
}, [areOptionsInitialized, isScreenTransitionEnd, options]);
6970

7071
const chatOptions = useMemo(() => {
71-
return filterAndOrderOptions(defaultOptions, cleanSearchTerm, {
72+
return filterAndOrderOptions(defaultOptions, cleanSearchTerm, countryCode, {
7273
selectedOptions,
7374
excludeLogins: CONST.EXPENSIFY_EMAILS_OBJECT,
7475
});
75-
}, [defaultOptions, cleanSearchTerm, selectedOptions]);
76+
}, [defaultOptions, cleanSearchTerm, selectedOptions, countryCode]);
7677

7778
const {sections, headerMessage} = useMemo(() => {
7879
const newSections: Section[] = [];

src/components/Search/SearchFiltersParticipantsSelector.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate}:
4747
});
4848
const [isSearchingForReports] = useOnyx(ONYXKEYS.IS_SEARCHING_FOR_REPORTS, {canBeMissing: false, initWithStoredValues: false});
4949
const [reportAttributesDerived] = useOnyx(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES, {canBeMissing: true, selector: (val) => val?.reports});
50+
const [countryCode] = useOnyx(ONYXKEYS.COUNTRY_CODE, {canBeMissing: false});
5051
const [selectedOptions, setSelectedOptions] = useState<OptionData[]>([]);
5152
const [searchTerm, setSearchTerm] = useState('');
5253
const cleanSearchTerm = useMemo(() => searchTerm.trim().toLowerCase(), [searchTerm]);
@@ -73,7 +74,7 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate}:
7374
}, [defaultOptions, selectedOptions]);
7475

7576
const chatOptions = useMemo(() => {
76-
const filteredOptions = filterAndOrderOptions(unselectedOptions, cleanSearchTerm, {
77+
const filteredOptions = filterAndOrderOptions(unselectedOptions, cleanSearchTerm, countryCode, {
7778
selectedOptions,
7879
excludeLogins: CONST.EXPENSIFY_EMAILS_OBJECT,
7980
maxRecentReportsToShow: CONST.IOU.MAX_RECENT_REPORTS_TO_SHOW,
@@ -88,7 +89,7 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate}:
8889
}
8990

9091
return filteredOptions;
91-
}, [unselectedOptions, cleanSearchTerm, selectedOptions]);
92+
}, [unselectedOptions, cleanSearchTerm, selectedOptions, countryCode]);
9293

9394
const {sections, headerMessage} = useMemo(() => {
9495
const newSections: Section[] = [];

src/libs/OptionsListUtils/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2381,8 +2381,8 @@ function filterSelfDMChat(report: SearchOptionData, searchTerms: string[]): Sear
23812381
return isMatch ? report : undefined;
23822382
}
23832383

2384-
function filterOptions(options: Options, searchInputValue: string, config?: FilterUserToInviteConfig): Options {
2385-
const parsedPhoneNumber = parsePhoneNumber(appendCountryCode(Str.removeSMSDomain(searchInputValue)));
2384+
function filterOptions(options: Options, searchInputValue: string, countryCode: OnyxEntry<number>, config?: FilterUserToInviteConfig): Options {
2385+
const parsedPhoneNumber = parsePhoneNumber(appendCountryCodeWithCountryCode(Str.removeSMSDomain(searchInputValue), countryCode ?? 1));
23862386
const searchValue = parsedPhoneNumber.possible && parsedPhoneNumber.number?.e164 ? parsedPhoneNumber.number.e164 : searchInputValue.toLowerCase();
23872387
const searchTerms = searchValue ? searchValue.split(' ') : [];
23882388

@@ -2450,10 +2450,10 @@ function combineOrderingOfReportsAndPersonalDetails(
24502450
* Filters and orders the options based on the search input value.
24512451
* Note that personal details that are part of the recent reports will always be shown as part of the recent reports (ie. DMs).
24522452
*/
2453-
function filterAndOrderOptions(options: Options, searchInputValue: string, config: FilterAndOrderConfig = {}): Options {
2453+
function filterAndOrderOptions(options: Options, searchInputValue: string, countryCode: OnyxEntry<number>, config: FilterAndOrderConfig = {}): Options {
24542454
let filterResult = options;
24552455
if (searchInputValue.trim().length > 0) {
2456-
filterResult = filterOptions(options, searchInputValue, config);
2456+
filterResult = filterOptions(options, searchInputValue, countryCode, config);
24572457
}
24582458

24592459
const orderedOptions = combineOrderingOfReportsAndPersonalDetails(filterResult, searchInputValue, config);

src/pages/InviteReportParticipantsPage.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ type Sections = Array<SectionListData<MemberForList, Section<MemberForList>>>;
5050

5151
function InviteReportParticipantsPage({betas, report, didScreenTransitionEnd}: InviteReportParticipantsPageProps) {
5252
const route = useRoute<PlatformStackRouteProp<ParticipantsNavigatorParamList, typeof SCREENS.REPORT_PARTICIPANTS.INVITE>>();
53-
const [countryCode] = useOnyx(ONYXKEYS.COUNTRY_CODE, {canBeMissing: false});
5453
const {options, areOptionsInitialized} = useOptionsList({
5554
shouldInitialize: didScreenTransitionEnd,
5655
});
5756

5857
const styles = useThemeStyles();
5958
const {translate, formatPhoneNumber} = useLocalize();
6059
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {canBeMissing: false});
60+
const [countryCode] = useOnyx(ONYXKEYS.COUNTRY_CODE, {canBeMissing: false});
6161
const [userSearchPhrase] = useOnyx(ONYXKEYS.ROOM_MEMBERS_USER_SEARCH_PHRASE, {canBeMissing: true});
6262
const [searchValue, debouncedSearchTerm, setSearchValue] = useDebouncedState(userSearchPhrase ?? '');
6363
const [selectedOptions, setSelectedOptions] = useState<OptionData[]>([]);
@@ -88,7 +88,10 @@ function InviteReportParticipantsPage({betas, report, didScreenTransitionEnd}: I
8888
return getMemberInviteOptions(options.personalDetails, betas ?? [], excludedUsers, false, options.reports, true);
8989
}, [areOptionsInitialized, betas, excludedUsers, options.personalDetails, options.reports]);
9090

91-
const inviteOptions = useMemo(() => filterAndOrderOptions(defaultOptions, debouncedSearchTerm, {excludeLogins: excludedUsers}), [debouncedSearchTerm, defaultOptions, excludedUsers]);
91+
const inviteOptions = useMemo(
92+
() => filterAndOrderOptions(defaultOptions, debouncedSearchTerm, countryCode, {excludeLogins: excludedUsers}),
93+
[debouncedSearchTerm, defaultOptions, excludedUsers, countryCode],
94+
);
9295

9396
useEffect(() => {
9497
// Update selectedOptions with the latest personalDetails information

src/pages/NewChatPage.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ function useOptions() {
6060
const [selectedOptions, setSelectedOptions] = useState<SelectedOption[]>([]);
6161
const [betas] = useOnyx(ONYXKEYS.BETAS, {canBeMissing: true});
6262
const [newGroupDraft] = useOnyx(ONYXKEYS.NEW_GROUP_CHAT_DRAFT, {canBeMissing: true});
63+
const [countryCode] = useOnyx(ONYXKEYS.COUNTRY_CODE, {canBeMissing: false});
6364
const personalData = useCurrentUserPersonalDetails();
6465
const focusTimeoutRef = useRef<NodeJS.Timeout | null>(null);
6566
const [didScreenTransitionEnd, setDidScreenTransitionEnd] = useState(false);
@@ -85,13 +86,13 @@ function useOptions() {
8586
const unselectedOptions = useMemo(() => filterSelectedOptions(defaultOptions, new Set(selectedOptions.map(({accountID}) => accountID))), [defaultOptions, selectedOptions]);
8687

8788
const options = useMemo(() => {
88-
const filteredOptions = filterAndOrderOptions(unselectedOptions, debouncedSearchTerm, {
89+
const filteredOptions = filterAndOrderOptions(unselectedOptions, debouncedSearchTerm, countryCode, {
8990
selectedOptions,
9091
maxRecentReportsToShow: CONST.IOU.MAX_RECENT_REPORTS_TO_SHOW,
9192
});
9293

9394
return filteredOptions;
94-
}, [debouncedSearchTerm, unselectedOptions, selectedOptions]);
95+
}, [debouncedSearchTerm, unselectedOptions, selectedOptions, countryCode]);
9596
const cleanSearchTerm = useMemo(() => debouncedSearchTerm.trim().toLowerCase(), [debouncedSearchTerm]);
9697
const headerMessage = useMemo(() => {
9798
return getHeaderMessage(

src/pages/OnboardingWorkspaceInvite/BaseOnboardingWorkspaceInvite.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ function BaseOnboardingWorkspaceInvite({shouldUseNativeStyles}: BaseOnboardingWo
9494
return {...inviteOptions, recentReports: [], currentUserOption: null};
9595
}, [areOptionsInitialized, betas, excludedUsers, options.personalDetails]);
9696

97-
const inviteOptions = useMemo(() => filterAndOrderOptions(defaultOptions, debouncedSearchTerm, {excludeLogins: excludedUsers}), [debouncedSearchTerm, defaultOptions, excludedUsers]);
97+
const inviteOptions = useMemo(
98+
() => filterAndOrderOptions(defaultOptions, debouncedSearchTerm, countryCode, {excludeLogins: excludedUsers}),
99+
[debouncedSearchTerm, defaultOptions, excludedUsers, countryCode],
100+
);
98101

99102
useEffect(() => {
100103
if (!areOptionsInitialized) {

src/pages/RoomInvitePage.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ function RoomInvitePage({
5555
const styles = useThemeStyles();
5656
const {translate, formatPhoneNumber} = useLocalize();
5757
const [userSearchPhrase] = useOnyx(ONYXKEYS.ROOM_MEMBERS_USER_SEARCH_PHRASE, {canBeMissing: true});
58+
const [countryCode] = useOnyx(ONYXKEYS.COUNTRY_CODE, {canBeMissing: false});
5859
const [searchTerm, debouncedSearchTerm, setSearchTerm] = useDebouncedState(userSearchPhrase ?? '');
5960
const [selectedOptions, setSelectedOptions] = useState<OptionData[]>([]);
6061
const [isSearchingForReports] = useOnyx(ONYXKEYS.IS_SEARCHING_FOR_REPORTS, {initWithStoredValues: false, canBeMissing: true});
@@ -109,10 +110,10 @@ function RoomInvitePage({
109110
if (debouncedSearchTerm.trim() === '') {
110111
return defaultOptions;
111112
}
112-
const filteredOptions = filterAndOrderOptions(defaultOptions, debouncedSearchTerm, {excludeLogins: excludedUsers});
113+
const filteredOptions = filterAndOrderOptions(defaultOptions, debouncedSearchTerm, countryCode, {excludeLogins: excludedUsers});
113114

114115
return filteredOptions;
115-
}, [debouncedSearchTerm, defaultOptions, excludedUsers]);
116+
}, [debouncedSearchTerm, defaultOptions, excludedUsers, countryCode]);
116117

117118
const sections = useMemo(() => {
118119
const sectionsArr: Sections = [];

src/pages/iou/request/MoneyRequestAccountantSelector.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ function MoneyRequestAccountantSelector({onFinish, onAccountantSelected, iouType
5353
const {isOffline} = useNetwork();
5454
const personalDetails = usePersonalDetails();
5555
const {didScreenTransitionEnd} = useScreenWrapperTransitionStatus();
56+
const [countryCode] = useOnyx(ONYXKEYS.COUNTRY_CODE, {canBeMissing: false});
5657
const [betas] = useOnyx(ONYXKEYS.BETAS, {canBeMissing: false});
5758
const [isSearchingForReports] = useOnyx(ONYXKEYS.IS_SEARCHING_FOR_REPORTS, {initWithStoredValues: false, canBeMissing: true});
5859
const {options, areOptionsInitialized} = useOptionsList({
@@ -100,12 +101,12 @@ function MoneyRequestAccountantSelector({onFinish, onAccountantSelected, iouType
100101
headerMessage: '',
101102
};
102103
}
103-
const newOptions = filterAndOrderOptions(defaultOptions, debouncedSearchTerm, {
104+
const newOptions = filterAndOrderOptions(defaultOptions, debouncedSearchTerm, countryCode, {
104105
excludeLogins: CONST.EXPENSIFY_EMAILS_OBJECT,
105106
maxRecentReportsToShow: CONST.IOU.MAX_RECENT_REPORTS_TO_SHOW,
106107
});
107108
return newOptions;
108-
}, [areOptionsInitialized, defaultOptions, debouncedSearchTerm]);
109+
}, [areOptionsInitialized, defaultOptions, debouncedSearchTerm, countryCode]);
109110

110111
/**
111112
* Returns the sections needed for the OptionsSelector

src/pages/iou/request/MoneyRequestAttendeeSelector.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde
6363
const {isOffline} = useNetwork();
6464
const personalDetails = usePersonalDetails();
6565
const {didScreenTransitionEnd} = useScreenWrapperTransitionStatus();
66+
const [countryCode] = useOnyx(ONYXKEYS.COUNTRY_CODE, {canBeMissing: false});
6667
const [betas] = useOnyx(ONYXKEYS.BETAS, {canBeMissing: false});
6768
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID, {canBeMissing: true});
6869
const [recentAttendees] = useOnyx(ONYXKEYS.NVP_RECENT_ATTENDEES, {canBeMissing: true});
@@ -108,7 +109,7 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde
108109
headerMessage: '',
109110
};
110111
}
111-
const newOptions = filterAndOrderOptions(defaultOptions, cleanSearchTerm, {
112+
const newOptions = filterAndOrderOptions(defaultOptions, cleanSearchTerm, countryCode, {
112113
excludeLogins: CONST.EXPENSIFY_EMAILS_OBJECT,
113114
preferPolicyExpenseChat: isPaidGroupPolicy,
114115
shouldAcceptName: true,
@@ -121,7 +122,7 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde
121122
})),
122123
});
123124
return newOptions;
124-
}, [areOptionsInitialized, defaultOptions, cleanSearchTerm, isPaidGroupPolicy, attendees]);
125+
}, [areOptionsInitialized, defaultOptions, cleanSearchTerm, isPaidGroupPolicy, attendees, countryCode]);
125126

126127
/**
127128
* Returns the sections needed for the OptionsSelector

0 commit comments

Comments
 (0)