Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/hooks/useSearchSelector.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ function useSearchSelectorBase({
searchString: computedSearchTerm,
includeUserToInvite,
includeCurrentUser,
shouldAcceptName: true,
});
default:
return getEmptyOptions();
Expand Down
11 changes: 8 additions & 3 deletions src/libs/OptionsListUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
*/
let currentUserLogin: string | undefined;
let currentUserAccountID: number | undefined;
Onyx.connect({

Check warning on line 193 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
currentUserLogin = value?.email;
Expand All @@ -199,13 +199,13 @@
});

let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
Onyx.connect({

Check warning on line 202 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => (allPersonalDetails = isEmptyObject(value) ? {} : value),
});

const policies: OnyxCollection<Policy> = {};
Onyx.connect({

Check warning on line 208 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
callback: (policy, key) => {
if (!policy || !key || !policy.name) {
Expand All @@ -217,14 +217,14 @@
});

let allPolicies: OnyxCollection<Policy> = {};
Onyx.connect({

Check warning on line 220 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (val) => (allPolicies = val),
});

let allReports: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 227 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -233,7 +233,7 @@
});

let allReportNameValuePairs: OnyxCollection<ReportNameValuePairs>;
Onyx.connect({

Check warning on line 236 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -245,7 +245,7 @@
const allSortedReportActions: Record<string, ReportAction[]> = {};
let allReportActions: OnyxCollection<ReportActions>;
const lastVisibleReportActions: ReportActions = {};
Onyx.connect({

Check warning on line 248 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand Down Expand Up @@ -307,7 +307,7 @@
});

let activePolicyID: OnyxEntry<string>;
Onyx.connect({

Check warning on line 310 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.NVP_ACTIVE_POLICY_ID,
callback: (value) => (activePolicyID = value),
});
Expand Down Expand Up @@ -1687,7 +1687,10 @@
const isValidPhoneNumber = parsedPhoneNumber.possible && Str.isValidE164Phone(getPhoneNumberWithoutSpecialChars(parsedPhoneNumber.number?.input ?? ''));
const isInOptionToExclude = loginsToExclude[addSMSDomainIfPhoneNumber(searchValue).toLowerCase()];

if (isCurrentUserLogin || isInSelectedOption || (!isValidEmail && !isValidPhoneNumber && !shouldAcceptName) || isInOptionToExclude) {
// Angle brackets are not valid characters for user names
const hasInvalidCharacters = shouldAcceptName && (searchValue.includes('<') || searchValue.includes('>'));

if (isCurrentUserLogin || isInSelectedOption || (!isValidEmail && !isValidPhoneNumber && !shouldAcceptName) || isInOptionToExclude || hasInvalidCharacters) {
return null;
}

Expand All @@ -1704,7 +1707,7 @@
showChatPreviewLine,
});
userToInvite.isOptimisticAccount = true;
userToInvite.login = isValidEmail || isValidPhoneNumber ? searchValue : '';
userToInvite.login = searchValue;
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
userToInvite.text = userToInvite.text || searchValue;
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
Expand Down Expand Up @@ -2125,6 +2128,7 @@
maxElements,
includeUserToInvite = false,
maxRecentReportElements = undefined,
shouldAcceptName = false,
...config
}: GetOptionsConfig = {},
countryCode: number = CONST.DEFAULT_COUNTRY_CODE,
Expand Down Expand Up @@ -2311,6 +2315,7 @@
countryCode,
{
excludeLogins: loginsToExclude,
shouldAcceptName,
},
);
}
Expand Down Expand Up @@ -2444,7 +2449,7 @@
.filter((attendee) => !attendees.find(({email, displayName}) => (attendee.email ? email === attendee.email : displayName === attendee.displayName)))
.map((attendee) => ({
...attendee,
login: attendee.email ?? attendee.displayName,
login: attendee.email ? attendee.email : attendee.displayName,
...getPersonalDetailByEmail(attendee.email),
}))
.map((attendee) => getParticipantsOption(attendee, personalDetails));
Expand Down
1 change: 1 addition & 0 deletions src/libs/OptionsListUtils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ type GetOptionsConfig = {
maxElements?: number;
maxRecentReportElements?: number;
includeUserToInvite?: boolean;
shouldAcceptName?: boolean;
} & GetValidReportsConfig;

type GetUserToInviteConfig = {
Expand Down
11 changes: 3 additions & 8 deletions src/pages/iou/request/MoneyRequestAttendeeSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde
...attendee,
reportID: CONST.DEFAULT_NUMBER_ID.toString(),
selected: true,
login: attendee.email,
login: attendee.email ? attendee.email : attendee.displayName,
...getPersonalDetailByEmail(attendee.email),
})),
[attendees],
Expand Down Expand Up @@ -204,13 +204,7 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde
const cleanSearchTerm = searchTerm.trim().toLowerCase();
const formatResults = formatSectionsFromSearchTerm(
cleanSearchTerm,
attendees.map((attendee) => ({
...attendee,
reportID: CONST.DEFAULT_NUMBER_ID.toString(),
selected: true,
login: attendee.email,
...getPersonalDetailByEmail(attendee.email),
})),
initialSelectedOptions,
orderedAvailableOptions.recentReports,
orderedAvailableOptions.personalDetails,
personalDetails,
Expand Down Expand Up @@ -272,6 +266,7 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde
areOptionsInitialized,
didScreenTransitionEnd,
searchTerm,
initialSelectedOptions,
attendees,
orderedAvailableOptions.recentReports,
orderedAvailableOptions.personalDetails,
Expand Down
21 changes: 21 additions & 0 deletions tests/unit/OptionsListUtilsTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
getPersonalDetailSearchTerms,
getSearchOptions,
getSearchValueForPhoneOrEmail,
getUserToInviteOption,
getValidOptions,
optionsOrderBy,
orderOptions,
Expand Down Expand Up @@ -2962,4 +2963,24 @@ describe('OptionsListUtils', () => {
expect(searchTerms2.includes(displayName)).toBe(true);
});
});

describe('getUserToInviteOption', () => {
it('should not return userToInvite for plain text name when shouldAcceptName is false', () => {
const result = getUserToInviteOption({
searchValue: 'Jeff Amazon',
loginList: {},
});
expect(result).toBeNull();
});

it('should return userToInvite for plain text name when shouldAcceptName is true', () => {
const result = getUserToInviteOption({
searchValue: 'Jeff Amazon',
shouldAcceptName: true,
loginList: {},
});
expect(result).not.toBeNull();
expect(result?.login).toBe('Jeff Amazon');
});
});
});
Loading