-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33930 from koko57/refactor/31312-consolidate-getd…
…isplayname-methods-pt2-new Refactor/31312 consolidate getdisplayname methods pt2
- Loading branch information
Showing
4 changed files
with
15 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,20 +43,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<PersonalDetails, 'firstName' | 'lastName'> | null): string { | ||
function createDisplayName(login: string, personalDetails: Pick<PersonalDetails, 'firstName' | 'lastName'> | OnyxEntry<PersonalDetails>): string { | ||
// If we have a number like [email protected] 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. | ||
|
@@ -150,7 +149,7 @@ function updateDisplayName(firstName: string, lastName: string) { | |
[currentUserAccountID]: { | ||
firstName, | ||
lastName, | ||
displayName: getDisplayName(currentUserEmail ?? '', { | ||
displayName: createDisplayName(currentUserEmail ?? '', { | ||
firstName, | ||
lastName, | ||
}), | ||
|
@@ -566,7 +565,7 @@ export { | |
deleteAvatar, | ||
extractFirstAndLastNameFromAvailableDetails, | ||
getCountryISO, | ||
getDisplayName, | ||
createDisplayName, | ||
getPrivatePersonalDetails, | ||
openPersonalDetailsPage, | ||
openPublicProfilePage, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters