diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 4a8883ddf60c..bfa384da7af6 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1475,7 +1475,6 @@ function getDisplayNameForParticipant(accountID?: number, shouldUseShortForm = f } const personalDetails = getPersonalDetailsForAccountID(accountID); - // console.log(personalDetails); // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing const formattedLogin = LocalePhoneNumber.formatPhoneNumber(personalDetails.login || ''); // This is to check if account is an invite/optimistically created one diff --git a/src/libs/actions/PersonalDetails.ts b/src/libs/actions/PersonalDetails.ts index 20c6d8fef247..6bcbb57695c9 100644 --- a/src/libs/actions/PersonalDetails.ts +++ b/src/libs/actions/PersonalDetails.ts @@ -41,20 +41,19 @@ Onyx.connect({ }); /** - * Returns the displayName for a user + * Creates a new displayName for a user based on passed personal details or login. */ -function getDisplayName(login: string, personalDetail: Pick | null): string { +function createDisplayName(login: string, personalDetails: Pick): string { // If we have a number like +15857527441@expensify.sms then let's remove @expensify.sms and format it // so that the option looks cleaner in our UI. const userLogin = LocalePhoneNumber.formatPhoneNumber(login); - const userDetails = personalDetail ?? allPersonalDetails?.[login]; - if (!userDetails) { + if (!personalDetails) { return userLogin; } - const firstName = userDetails.firstName ?? ''; - const lastName = userDetails.lastName ?? ''; + const firstName = personalDetails.firstName ?? ''; + const lastName = personalDetails.lastName ?? ''; const fullName = `${firstName} ${lastName}`.trim(); // It's possible for fullName to be empty string, so we must use "||" to fallback to userLogin. @@ -148,7 +147,7 @@ function updateDisplayName(firstName: string, lastName: string) { [currentUserAccountID]: { firstName, lastName, - displayName: getDisplayName(currentUserEmail ?? '', { + displayName: createDisplayName(currentUserEmail ?? '', { firstName, lastName, }), @@ -560,7 +559,7 @@ export { deleteAvatar, extractFirstAndLastNameFromAvailableDetails, getCountryISO, - getDisplayName, + createDisplayName, getPrivatePersonalDetails, openPersonalDetailsPage, openPublicProfilePage, diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index 67828c766147..4984d32bafb5 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -724,7 +724,7 @@ function setContactMethodAsDefault(newDefaultContactMethod) { value: { [currentUserAccountID]: { login: newDefaultContactMethod, - displayName: PersonalDetails.getDisplayName(newDefaultContactMethod, myPersonalDetails), + displayName: PersonalDetails.createDisplayName(newDefaultContactMethod, myPersonalDetails), }, }, },