diff --git a/src/components/Search/FilterDropdowns/UserSelectPopup.tsx b/src/components/Search/FilterDropdowns/UserSelectPopup.tsx index 1b39219c004d..b2ab953aba14 100644 --- a/src/components/Search/FilterDropdowns/UserSelectPopup.tsx +++ b/src/components/Search/FilterDropdowns/UserSelectPopup.tsx @@ -93,8 +93,9 @@ function UserSelectPopup({value, closeOverlay, onChange}: UserSelectPopupProps) excludeLogins: CONST.EXPENSIFY_EMAILS_OBJECT, includeCurrentUser: true, }, + countryCode, ); - }, [options.reports, options.personalDetails, draftComments]); + }, [options.reports, options.personalDetails, draftComments, countryCode]); const filteredOptions = useMemo(() => { return filterAndOrderOptions(optionsList, cleanSearchTerm, countryCode, { diff --git a/src/components/Search/SearchAutocompleteList.tsx b/src/components/Search/SearchAutocompleteList.tsx index 073e3a196b8a..067002dab2c6 100644 --- a/src/components/Search/SearchAutocompleteList.tsx +++ b/src/components/Search/SearchAutocompleteList.tsx @@ -181,6 +181,7 @@ function SearchAutocompleteList({ const [betas] = useOnyx(ONYXKEYS.BETAS, {canBeMissing: true}); const [draftComments] = useOnyx(ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT, {canBeMissing: true}); const [recentSearches] = useOnyx(ONYXKEYS.RECENT_SEARCHES, {canBeMissing: true}); + const [countryCode] = useOnyx(ONYXKEYS.COUNTRY_CODE, {canBeMissing: false}); const taxRates = getAllTaxRates(); const {options, areOptionsInitialized} = useOptionsList(); @@ -199,9 +200,10 @@ function SearchAutocompleteList({ includeUserToInvite: true, includeRecentReports: true, includeCurrentUser: true, + countryCode, shouldShowGBR: false, }); - }, [areOptionsInitialized, options, draftComments, betas, autocompleteQueryValue]); + }, [areOptionsInitialized, options, draftComments, betas, autocompleteQueryValue, countryCode]); const [isInitialRender, setIsInitialRender] = useState(true); const parsedQuery = parseForAutocomplete(autocompleteQueryValue); @@ -402,6 +404,7 @@ function SearchAutocompleteList({ includeUserToInvite: false, includeRecentReports: false, includeCurrentUser: true, + countryCode, shouldShowGBR: true, }).personalDetails.filter((participant) => participant.text && !alreadyAutocompletedKeys.includes(participant.text.toLowerCase())); @@ -424,6 +427,7 @@ function SearchAutocompleteList({ includeUserToInvite: false, includeRecentReports: true, includeCurrentUser: false, + countryCode, shouldShowGBR: true, }).recentReports; @@ -584,6 +588,7 @@ function SearchAutocompleteList({ options, draftComments, betas, + countryCode, currentUserLogin, typeAutocompleteList, groupByAutocompleteList, diff --git a/src/components/Search/SearchFiltersChatsSelector.tsx b/src/components/Search/SearchFiltersChatsSelector.tsx index e328d300f94c..fc2829cb3933 100644 --- a/src/components/Search/SearchFiltersChatsSelector.tsx +++ b/src/components/Search/SearchFiltersChatsSelector.tsx @@ -67,8 +67,8 @@ function SearchFiltersChatsSelector({initialReportIDs, onFiltersUpdate, isScreen if (!areOptionsInitialized || !isScreenTransitionEnd) { return defaultListOptions; } - return getSearchOptions({options, draftComments, betas: undefined, isUsedInChatFinder: false}); - }, [areOptionsInitialized, draftComments, isScreenTransitionEnd, options]); + return getSearchOptions({options, draftComments, betas: undefined, isUsedInChatFinder: false, countryCode}); + }, [areOptionsInitialized, draftComments, isScreenTransitionEnd, options, countryCode]); const chatOptions = useMemo(() => { return filterAndOrderOptions(defaultOptions, cleanSearchTerm, countryCode, { diff --git a/src/components/Search/SearchFiltersParticipantsSelector.tsx b/src/components/Search/SearchFiltersParticipantsSelector.tsx index 7bb484d93eb3..282503c31dc0 100644 --- a/src/components/Search/SearchFiltersParticipantsSelector.tsx +++ b/src/components/Search/SearchFiltersParticipantsSelector.tsx @@ -69,8 +69,9 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate}: excludeLogins: CONST.EXPENSIFY_EMAILS_OBJECT, includeCurrentUser: true, }, + countryCode, ); - }, [areOptionsInitialized, draftComments, options.personalDetails, options.reports]); + }, [areOptionsInitialized, draftComments, options.personalDetails, options.reports, countryCode]); const unselectedOptions = useMemo(() => { return filterSelectedOptions(defaultOptions, new Set(selectedOptions.map((option) => option.accountID))); diff --git a/src/hooks/useSearchSelector.base.ts b/src/hooks/useSearchSelector.base.ts index 64294892e548..6d14bf56b8e1 100644 --- a/src/hooks/useSearchSelector.base.ts +++ b/src/hooks/useSearchSelector.base.ts @@ -179,6 +179,7 @@ function useSearchSelectorBase({ searchQuery: computedSearchTerm, maxResults, includeUserToInvite, + countryCode, }); case CONST.SEARCH_SELECTOR.SEARCH_CONTEXT_MEMBER_INVITE: return getValidOptions(optionsWithContacts, draftComments, { @@ -232,6 +233,7 @@ function useSearchSelectorBase({ computedSearchTerm, maxResults, includeUserToInvite, + countryCode, excludeLogins, includeRecentReports, maxRecentReportsToShow, diff --git a/src/libs/OptionsListUtils/index.ts b/src/libs/OptionsListUtils/index.ts index b8f2b8245eff..87c41ba1b026 100644 --- a/src/libs/OptionsListUtils/index.ts +++ b/src/libs/OptionsListUtils/index.ts @@ -1370,12 +1370,13 @@ function getUserToInviteOption({ selectedOptions = [], showChatPreviewLine = false, shouldAcceptName = false, + countryCode = CONST.DEFAULT_COUNTRY_CODE, }: GetUserToInviteConfig): SearchOptionData | null { if (!searchValue) { return null; } - const parsedPhoneNumber = parsePhoneNumber(appendCountryCode(Str.removeSMSDomain(searchValue))); + const parsedPhoneNumber = parsePhoneNumber(appendCountryCodeWithCountryCode(Str.removeSMSDomain(searchValue), countryCode)); const isCurrentUserLogin = isCurrentUser({login: searchValue} as PersonalDetails); const isInSelectedOption = selectedOptions.some((option) => 'login' in option && option.login === searchValue); const isValidEmail = Str.isValidEmail(searchValue) && !Str.isDomainEmail(searchValue) && !Str.endsWith(searchValue, CONST.SMS.DOMAIN); @@ -1783,6 +1784,7 @@ function getValidOptions( maxRecentReportElements = undefined, ...config }: GetOptionsConfig = {}, + countryCode: number = CONST.DEFAULT_COUNTRY_CODE, ): Options { const restrictedLogins = getRestrictedLogins(config, options, canShowManagerMcTest); @@ -1932,9 +1934,14 @@ function getValidOptions( let userToInvite: SearchOptionData | null = null; if (includeUserToInvite) { - userToInvite = filterUserToInvite({currentUserOption: currentUserRef.current, recentReports: recentReportOptions, personalDetails: personalDetailsOptions}, searchString ?? '', { - excludeLogins: loginsToExclude, - }); + userToInvite = filterUserToInvite( + {currentUserOption: currentUserRef.current, recentReports: recentReportOptions, personalDetails: personalDetailsOptions}, + searchString ?? '', + countryCode, + { + excludeLogins: loginsToExclude, + }, + ); } return { @@ -1958,6 +1965,7 @@ type SearchOptionsConfig = { includeUserToInvite?: boolean; includeRecentReports?: boolean; includeCurrentUser?: boolean; + countryCode?: number; shouldShowGBR?: boolean; }; @@ -1975,31 +1983,37 @@ function getSearchOptions({ includeUserToInvite, includeRecentReports = true, includeCurrentUser = false, + countryCode = CONST.DEFAULT_COUNTRY_CODE, shouldShowGBR = false, }: SearchOptionsConfig): Options { Timing.start(CONST.TIMING.LOAD_SEARCH_OPTIONS); Performance.markStart(CONST.TIMING.LOAD_SEARCH_OPTIONS); - const optionList = getValidOptions(options, draftComments, { - betas, - includeRecentReports, - includeMultipleParticipantReports: true, - showChatPreviewLine: isUsedInChatFinder, - includeP2P: true, - includeOwnedWorkspaceChats: true, - includeThreads: true, - includeMoneyRequests: true, - includeTasks: true, - includeReadOnly, - includeSelfDM: true, - shouldBoldTitleByDefault: !isUsedInChatFinder, - excludeHiddenThreads: true, - maxElements: maxResults, - includeCurrentUser, - searchString: searchQuery, - includeUserToInvite, - shouldShowGBR, - }); + const optionList = getValidOptions( + options, + draftComments, + { + betas, + includeRecentReports, + includeMultipleParticipantReports: true, + showChatPreviewLine: isUsedInChatFinder, + includeP2P: true, + includeOwnedWorkspaceChats: true, + includeThreads: true, + includeMoneyRequests: true, + includeTasks: true, + includeReadOnly, + includeSelfDM: true, + shouldBoldTitleByDefault: !isUsedInChatFinder, + excludeHiddenThreads: true, + maxElements: maxResults, + includeCurrentUser, + searchString: searchQuery, + includeUserToInvite, + shouldShowGBR, + }, + countryCode, + ); Timing.end(CONST.TIMING.LOAD_SEARCH_OPTIONS); Performance.markEnd(CONST.TIMING.LOAD_SEARCH_OPTIONS); @@ -2007,20 +2021,33 @@ function getSearchOptions({ return optionList; } -function getShareLogOptions(options: OptionList, draftComments: OnyxCollection, betas: Beta[] = [], searchString = '', maxElements?: number, includeUserToInvite = false): Options { - return getValidOptions(options, draftComments, { - betas, - includeMultipleParticipantReports: true, - includeP2P: true, - forcePolicyNamePreview: true, - includeOwnedWorkspaceChats: true, - includeSelfDM: true, - includeThreads: true, - includeReadOnly: false, - searchString, - maxElements, - includeUserToInvite, - }); +function getShareLogOptions( + options: OptionList, + draftComments: OnyxCollection, + betas: Beta[] = [], + searchString = '', + maxElements?: number, + includeUserToInvite = false, + countryCode: number = CONST.DEFAULT_COUNTRY_CODE, +): Options { + return getValidOptions( + options, + draftComments, + { + betas, + includeMultipleParticipantReports: true, + includeP2P: true, + forcePolicyNamePreview: true, + includeOwnedWorkspaceChats: true, + includeSelfDM: true, + includeThreads: true, + includeReadOnly: false, + searchString, + maxElements, + includeUserToInvite, + }, + countryCode, + ); } /** @@ -2047,18 +2074,33 @@ function getIOUConfirmationOptionsFromPayeePersonalDetail(personalDetail: OnyxEn }; } -function getAttendeeOptions( - reports: Array>, - personalDetails: Array>, - betas: OnyxEntry, - attendees: Attendee[], - recentAttendees: Attendee[], - draftComments: OnyxCollection, +type GetAttendeeOptionsParams = { + reports: Array>; + personalDetails: Array>; + betas: OnyxEntry; + attendees: Attendee[]; + recentAttendees: Attendee[]; + draftComments: OnyxCollection; + includeOwnedWorkspaceChats: boolean; + includeP2P: boolean; + includeInvoiceRooms: boolean; + action: IOUAction | undefined; + countryCode: number; +}; + +function getAttendeeOptions({ + reports, + personalDetails, + betas, + attendees, + recentAttendees, + draftComments, includeOwnedWorkspaceChats = false, includeP2P = true, includeInvoiceRooms = false, - action: IOUAction | undefined = undefined, -) { + action = undefined, + countryCode = CONST.DEFAULT_COUNTRY_CODE, +}: GetAttendeeOptionsParams) { const personalDetailList = keyBy( personalDetails.map(({item}) => item), 'accountID', @@ -2087,19 +2129,24 @@ function getAttendeeOptions( })) .map((attendee) => getParticipantsOption(attendee, personalDetailList as never)); - return getValidOptions({reports, personalDetails}, draftComments, { - betas, - selectedOptions: attendees.map((attendee) => ({...attendee, login: attendee.email})), - excludeLogins: CONST.EXPENSIFY_EMAILS_OBJECT, - includeOwnedWorkspaceChats, - includeRecentReports: false, - includeP2P, - includeSelectedOptions: false, - includeSelfDM: false, - includeInvoiceRooms, - action, - recentAttendees: filteredRecentAttendees, - }); + return getValidOptions( + {reports, personalDetails}, + draftComments, + { + betas, + selectedOptions: attendees.map((attendee) => ({...attendee, login: attendee.email})), + excludeLogins: CONST.EXPENSIFY_EMAILS_OBJECT, + includeOwnedWorkspaceChats, + includeRecentReports: false, + includeP2P, + includeSelectedOptions: false, + includeSelfDM: false, + includeInvoiceRooms, + action, + recentAttendees: filteredRecentAttendees, + }, + countryCode, + ); } /** @@ -2137,16 +2184,22 @@ function getMemberInviteOptions( betas: Beta[] = [], excludeLogins: Record = {}, includeSelectedOptions = false, + countryCode: number = CONST.DEFAULT_COUNTRY_CODE, ): Options { - return getValidOptions({personalDetails, reports: []}, undefined, { - betas, - includeP2P: true, - excludeLogins, - includeSelectedOptions, - includeRecentReports: false, - searchString: '', - maxElements: undefined, - }); + return getValidOptions( + {personalDetails, reports: []}, + undefined, + { + betas, + includeP2P: true, + excludeLogins, + includeSelectedOptions, + includeRecentReports: false, + searchString: '', + maxElements: undefined, + }, + countryCode, + ); } /** @@ -2365,7 +2418,12 @@ function filterCurrentUserOption(currentUserOption: SearchOptionData | null | un }, currentUserOption); } -function filterUserToInvite(options: Omit, searchValue: string, config?: FilterUserToInviteConfig): SearchOptionData | null { +function filterUserToInvite( + options: Omit, + searchValue: string, + countryCode: number = CONST.DEFAULT_COUNTRY_CODE, + config?: FilterUserToInviteConfig, +): SearchOptionData | null { const {canInviteUser = true, excludeLogins = {}} = config ?? {}; if (!canInviteUser) { return null; @@ -2389,6 +2447,7 @@ function filterUserToInvite(options: Omit, searchValue: return getUserToInviteOption({ searchValue, loginsToExclude, + countryCode, ...config, }); } @@ -2437,6 +2496,7 @@ function filterOptions(options: Options, searchInputValue: string, countryCode: currentUserOption, }, searchValue, + countryCode, config, ); const workspaceChats = filterWorkspaceChats(options.workspaceChats ?? [], searchTerms); diff --git a/src/libs/OptionsListUtils/types.ts b/src/libs/OptionsListUtils/types.ts index 4b047c8aa6d5..76cc3379ccca 100644 --- a/src/libs/OptionsListUtils/types.ts +++ b/src/libs/OptionsListUtils/types.ts @@ -203,6 +203,7 @@ type GetUserToInviteConfig = { avatar?: AvatarSource; shouldAcceptName?: boolean; optionsToExclude?: GetOptionsConfig['selectedOptions']; + countryCode?: number; } & Pick; type MemberForList = { diff --git a/src/pages/NewChatPage.tsx b/src/pages/NewChatPage.tsx index b74354e8455c..52305b7083ad 100755 --- a/src/pages/NewChatPage.tsx +++ b/src/pages/NewChatPage.tsx @@ -83,9 +83,10 @@ function useOptions() { betas: betas ?? [], includeSelfDM: true, }, + countryCode, ); return filteredOptions; - }, [listOptions.reports, listOptions.personalDetails, contacts, draftComments, betas]); + }, [listOptions.reports, listOptions.personalDetails, contacts, draftComments, betas, countryCode]); const unselectedOptions = useMemo(() => filterSelectedOptions(defaultOptions, new Set(selectedOptions.map(({accountID}) => accountID))), [defaultOptions, selectedOptions]); diff --git a/src/pages/Share/ShareTab.tsx b/src/pages/Share/ShareTab.tsx index 258adf7eb905..51b2761d6e89 100644 --- a/src/pages/Share/ShareTab.tsx +++ b/src/pages/Share/ShareTab.tsx @@ -44,6 +44,7 @@ function ShareTab({ref}: ShareTabProps) { const [textInputValue, debouncedTextInputValue, setTextInputValue] = useDebouncedState(''); const [betas] = useOnyx(ONYXKEYS.BETAS, {canBeMissing: true}); const selectionListRef = useRef(null); + const [countryCode] = useOnyx(ONYXKEYS.COUNTRY_CODE, {canBeMissing: false}); const [draftComments] = useOnyx(ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT, {canBeMissing: true}); useImperativeHandle(ref, () => ({ @@ -70,8 +71,9 @@ function ShareTab({ref}: ShareTabProps) { searchQuery: textInputValue, maxResults: 20, includeUserToInvite: true, + countryCode, }); - }, [areOptionsInitialized, betas, draftComments, options, textInputValue]); + }, [areOptionsInitialized, betas, draftComments, options, textInputValue, countryCode]); const recentReportsOptions = useMemo(() => { if (textInputValue.trim() === '') { diff --git a/src/pages/iou/request/MoneyRequestAccountantSelector.tsx b/src/pages/iou/request/MoneyRequestAccountantSelector.tsx index fd7896497866..94630e1cc437 100644 --- a/src/pages/iou/request/MoneyRequestAccountantSelector.tsx +++ b/src/pages/iou/request/MoneyRequestAccountantSelector.tsx @@ -84,6 +84,7 @@ function MoneyRequestAccountantSelector({onFinish, onAccountantSelected, iouType excludeLogins: CONST.EXPENSIFY_EMAILS_OBJECT, action, }, + countryCode, ); const orderedOptions = orderOptions(optionList); @@ -92,7 +93,7 @@ function MoneyRequestAccountantSelector({onFinish, onAccountantSelected, iouType ...optionList, ...orderedOptions, }; - }, [action, areOptionsInitialized, betas, didScreenTransitionEnd, draftComments, options.personalDetails, options.reports]); + }, [action, areOptionsInitialized, betas, didScreenTransitionEnd, draftComments, options.personalDetails, options.reports, countryCode]); const chatOptions = useMemo(() => { if (!areOptionsInitialized) { diff --git a/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx b/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx index 9afedc7e1e75..2611479983ce 100644 --- a/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx +++ b/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx @@ -88,18 +88,19 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde if (!areOptionsInitialized || !didScreenTransitionEnd) { getEmptyOptions(); } - const optionList = getAttendeeOptions( - options.reports, - options.personalDetails, + const optionList = getAttendeeOptions({ + reports: options.reports, + personalDetails: options.personalDetails, betas, attendees, - recentAttendees ?? [], - draftComments, - iouType === CONST.IOU.TYPE.SUBMIT, - true, - false, + recentAttendees: recentAttendees ?? [], + draftComments: draftComments ?? {}, + includeOwnedWorkspaceChats: iouType === CONST.IOU.TYPE.SUBMIT, + includeP2P: true, + includeInvoiceRooms: false, action, - ); + countryCode: countryCode ?? CONST.DEFAULT_COUNTRY_CODE, + }); if (isPaidGroupPolicy) { const orderedOptions = orderOptions(optionList, searchTerm, { preferChatRoomsOverThreads: true, diff --git a/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx b/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx index 77615d9b675d..f53b35276fcf 100644 --- a/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx +++ b/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx @@ -201,6 +201,7 @@ function MoneyRequestParticipantsSelector({ isPerDiemRequest, showRBR: false, }, + countryCode, ); const orderedOptions = orderOptions(optionList); @@ -223,6 +224,7 @@ function MoneyRequestParticipantsSelector({ isCategorizeOrShareAction, isPerDiemRequest, canShowManagerMcTest, + countryCode, isCorporateCardTransaction, ]); diff --git a/src/pages/settings/Profile/CustomStatus/VacationDelegatePage.tsx b/src/pages/settings/Profile/CustomStatus/VacationDelegatePage.tsx index a3ac65331d14..02982f8cd71f 100644 --- a/src/pages/settings/Profile/CustomStatus/VacationDelegatePage.tsx +++ b/src/pages/settings/Profile/CustomStatus/VacationDelegatePage.tsx @@ -53,6 +53,7 @@ function useOptions() { betas, excludeLogins, }, + countryCode, ); const headerMessage = getHeaderMessage((recentReports?.length || 0) + (personalDetails?.length || 0) !== 0, !!userToInvite, ''); @@ -64,7 +65,7 @@ function useOptions() { currentUserOption, headerMessage, }; - }, [optionsList.reports, optionsList.personalDetails, draftComments, betas, excludeLogins]); + }, [optionsList.reports, optionsList.personalDetails, draftComments, betas, excludeLogins, countryCode]); const options = useMemo(() => { const filteredOptions = filterAndOrderOptions(defaultOptions, debouncedSearchValue.trim(), countryCode, { diff --git a/src/pages/settings/Security/AddDelegate/AddDelegatePage.tsx b/src/pages/settings/Security/AddDelegate/AddDelegatePage.tsx index 64d88f455239..73a38e5a89c1 100644 --- a/src/pages/settings/Security/AddDelegate/AddDelegatePage.tsx +++ b/src/pages/settings/Security/AddDelegate/AddDelegatePage.tsx @@ -54,6 +54,7 @@ function useOptions() { betas, excludeLogins: {...CONST.EXPENSIFY_EMAILS_OBJECT, ...existingDelegates}, }, + countryCode, ); const headerMessage = getHeaderMessage((recentReports?.length || 0) + (personalDetails?.length || 0) !== 0, !!userToInvite, ''); @@ -70,7 +71,7 @@ function useOptions() { currentUserOption, headerMessage, }; - }, [optionsList.reports, optionsList.personalDetails, draftComments, betas, existingDelegates, isLoading]); + }, [optionsList.reports, optionsList.personalDetails, draftComments, betas, existingDelegates, isLoading, countryCode]); const options = useMemo(() => { const filteredOptions = filterAndOrderOptions(defaultOptions, debouncedSearchValue.trim(), countryCode, { diff --git a/src/pages/tasks/TaskAssigneeSelectorModal.tsx b/src/pages/tasks/TaskAssigneeSelectorModal.tsx index eedbf86e6959..855796c72c15 100644 --- a/src/pages/tasks/TaskAssigneeSelectorModal.tsx +++ b/src/pages/tasks/TaskAssigneeSelectorModal.tsx @@ -58,6 +58,7 @@ function useOptions() { excludeLogins: CONST.EXPENSIFY_EMAILS_OBJECT, includeCurrentUser: true, }, + countryCode, ); const headerMessage = getHeaderMessage((recentReports?.length || 0) + (personalDetails?.length || 0) !== 0 || !!currentUserOption, !!userToInvite, ''); @@ -74,7 +75,7 @@ function useOptions() { currentUserOption, headerMessage, }; - }, [optionsList.reports, optionsList.personalDetails, draftComments, betas, isLoading]); + }, [optionsList.reports, optionsList.personalDetails, draftComments, betas, isLoading, countryCode]); const optionsWithoutCurrentUser = useMemo(() => { if (!session?.accountID) {