Skip to content
Open
4 changes: 2 additions & 2 deletions src/components/Search/SearchAutocompleteList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,11 @@ function SearchAutocompleteList({

const reportOptions: OptionData[] = [...orderedOptions.recentReports, ...orderedOptions.personalDetails];
if (searchOptions.userToInvite) {
reportOptions.push(searchOptions.userToInvite);
reportOptions.push({...searchOptions.userToInvite, alternateText: translate('common.invite')});
}

return reportOptions.slice(0, 20);
}, [autocompleteQueryValue, searchOptions]);
}, [autocompleteQueryValue, searchOptions, translate]);

const debounceHandleSearch = useDebounce(() => {
if (!handleSearch || !autocompleteQueryWithoutFilters) {
Expand Down
11 changes: 9 additions & 2 deletions src/libs/OptionsListUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1911,13 +1911,20 @@ function canCreateOptimisticPersonalDetailOption({
currentUserOption?: SearchOptionData | null;
searchValue: string;
}) {
if (recentReportOptions.length + personalDetailsOptions.length > 0) {
const normalizedSearchValue = addSMSDomainIfPhoneNumber(searchValue ?? '').toLowerCase();
const rawSearchValue = (searchValue ?? '').toLowerCase();
const matchesLogin = (login: string | undefined) => {
const normalizedLogin = login?.toLowerCase();
return normalizedLogin === normalizedSearchValue || normalizedLogin === rawSearchValue;
};
const hasExactLoginMatch = recentReportOptions.some((o) => matchesLogin(o.login)) || personalDetailsOptions.some((o) => matchesLogin(o.login));
if (hasExactLoginMatch) {
return false;
}
if (!currentUserOption) {
return true;
}
return currentUserOption.login !== addSMSDomainIfPhoneNumber(searchValue ?? '').toLowerCase() && currentUserOption.login !== searchValue?.toLowerCase();
return currentUserOption.login !== normalizedSearchValue && currentUserOption.login !== rawSearchValue;
}

/**
Expand Down
Loading
Loading