Skip to content

Commit

Permalink
Merge branch 'ts/lib/PersonalDetails' of github.com:fabioh8010/expens…
Browse files Browse the repository at this point in the history
…ify-app into ts/lib/PersonalDetails
  • Loading branch information
kubabutkiewicz committed Nov 6, 2023
2 parents c801a02 + fe109f1 commit 3d2abe0
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 44 deletions.
15 changes: 12 additions & 3 deletions src/libs/actions/PersonalDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function getDisplayName(login: string, personalDetail: Pick<PersonalDetails, 'fi
const lastName = userDetails.lastName ?? '';
const fullName = `${firstName} ${lastName}`.trim();

// It's possible for fullName to be empty string, so we must use "||" to fallback to userLogin.
return fullName || userLogin;
}

Expand All @@ -70,11 +71,17 @@ function getDisplayNameForTypingIndicator(userAccountIDOrLogin: string, defaultD
// so Number(string) is NaN. Search for personalDetails by login to get the display name.
if (Number.isNaN(accountID)) {
const detailsByLogin = Object.entries(allPersonalDetails ?? {}).find(([, value]) => value?.login === userAccountIDOrLogin)?.[1];
return detailsByLogin?.displayName ?? userAccountIDOrLogin;

// It's possible for displayName to be empty string, so we must use "||" to fallback to userAccountIDOrLogin.
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
return detailsByLogin?.displayName || userAccountIDOrLogin;
}

const detailsByAccountID = allPersonalDetails?.[accountID];
return detailsByAccountID?.displayName ?? detailsByAccountID?.login ?? defaultDisplayName;

// It's possible for displayName to be empty string, so we must use "||" to fallback to login or defaultDisplayName.
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
return detailsByAccountID?.displayName || detailsByAccountID?.login || defaultDisplayName;
}

/**
Expand All @@ -83,7 +90,9 @@ function getDisplayNameForTypingIndicator(userAccountIDOrLogin: string, defaultD
* so we return empty strings instead.
*/
function extractFirstAndLastNameFromAvailableDetails({login, displayName, firstName, lastName}: PersonalDetails): FirstAndLastName {
if (firstName ?? lastName) {
// It's possible for firstName to be empty string, so we must use "||" to consider lastName instead.
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
if (firstName || lastName) {
return {firstName: firstName ?? '', lastName: lastName ?? ''};
}
if (login && Str.removeSMSDomain(login) === displayName) {
Expand Down
82 changes: 41 additions & 41 deletions src/types/onyx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,59 +51,59 @@ import WalletTransfer from './WalletTransfer';

export type {
Account,
Request,
AccountData,
AddDebitCardForm,
BankAccount,
Beta,
BlockedFromConcierge,
Card,
Credentials,
Currency,
CustomStatusDraft,
DateOfBirthForm,
Download,
Form,
FrequentlyUsedEmoji,
Fund,
IOU,
Login,
MapboxAccessToken,
Modal,
Network,
CustomStatusDraft,
OnyxUpdateEvent,
OnyxUpdatesFromServer,
PersonalBankAccount,
PersonalDetails,
PrivatePersonalDetails,
Task,
Currency,
ScreenShareRequest,
User,
Login,
Session,
Beta,
BlockedFromConcierge,
PlaidData,
UserWallet,
WalletOnfido,
WalletAdditionalDetails,
WalletTerms,
BankAccount,
Card,
Fund,
WalletStatement,
PersonalBankAccount,
ReimbursementAccount,
ReimbursementAccountDraft,
FrequentlyUsedEmoji,
WalletTransfer,
MapboxAccessToken,
Download,
PolicyMember,
Policy,
PolicyCategory,
PolicyMember,
PolicyMembers,
PolicyTag,
PolicyTags,
PrivatePersonalDetails,
RecentlyUsedCategories,
RecentlyUsedTags,
RecentWaypoint,
ReimbursementAccount,
ReimbursementAccountDraft,
Report,
ReportMetadata,
ReportAction,
ReportActionReactions,
ReportActions,
ReportActionsDrafts,
ReportActionReactions,
ReportMetadata,
Request,
ScreenShareRequest,
SecurityGroup,
Session,
Task,
Transaction,
Form,
AddDebitCardForm,
DateOfBirthForm,
OnyxUpdatesFromServer,
RecentWaypoint,
OnyxUpdateEvent,
RecentlyUsedCategories,
RecentlyUsedTags,
PolicyTag,
PolicyTags,
PolicyMembers,
AccountData,
User,
UserWallet,
WalletAdditionalDetails,
WalletOnfido,
WalletStatement,
WalletTerms,
WalletTransfer,
};

0 comments on commit 3d2abe0

Please sign in to comment.