Skip to content

Commit

Permalink
refactor: rename getDisplayName to createDisplayName
Browse files Browse the repository at this point in the history
  • Loading branch information
koko57 committed Jan 4, 2024
1 parent 2a73e48 commit 1c53bfa
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
1 change: 0 additions & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 7 additions & 8 deletions src/libs/actions/PersonalDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<PersonalDetails, 'firstName' | 'lastName'> | null): string {
function createDisplayName(login: string, personalDetails: Pick<PersonalDetails, 'firstName' | 'lastName'>): 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.
Expand Down Expand Up @@ -148,7 +147,7 @@ function updateDisplayName(firstName: string, lastName: string) {
[currentUserAccountID]: {
firstName,
lastName,
displayName: getDisplayName(currentUserEmail ?? '', {
displayName: createDisplayName(currentUserEmail ?? '', {
firstName,
lastName,
}),
Expand Down Expand Up @@ -560,7 +559,7 @@ export {
deleteAvatar,
extractFirstAndLastNameFromAvailableDetails,
getCountryISO,
getDisplayName,
createDisplayName,
getPrivatePersonalDetails,
openPersonalDetailsPage,
openPublicProfilePage,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ function setContactMethodAsDefault(newDefaultContactMethod) {
value: {
[currentUserAccountID]: {
login: newDefaultContactMethod,
displayName: PersonalDetails.getDisplayName(newDefaultContactMethod, myPersonalDetails),
displayName: PersonalDetails.createDisplayName(newDefaultContactMethod, myPersonalDetails),
},
},
},
Expand Down

0 comments on commit 1c53bfa

Please sign in to comment.