Skip to content

Commit

Permalink
Merge pull request #45393 from nkdengineer/fix/44295-wrong-title
Browse files Browse the repository at this point in the history
fix: User avatar and email does not show when using Submit
  • Loading branch information
grgia committed Aug 6, 2024
2 parents 69476a1 + b9dfc66 commit 1147c3b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
29 changes: 22 additions & 7 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1910,7 +1910,7 @@ function getWorkspaceIcon(report: OnyxInputOrEntry<Report>, policy?: OnyxInputOr
* Gets the personal details for a login by looking in the ONYXKEYS.PERSONAL_DETAILS_LIST Onyx key (stored in the local variable, allPersonalDetails). If it doesn't exist in Onyx,
* then a default object is constructed.
*/
function getPersonalDetailsForAccountID(accountID: number): Partial<PersonalDetails> {
function getPersonalDetailsForAccountID(accountID: number, personalDetailsData?: Partial<PersonalDetailsList>): Partial<PersonalDetails> {
if (!accountID) {
return {};
}
Expand All @@ -1919,7 +1919,11 @@ function getPersonalDetailsForAccountID(accountID: number): Partial<PersonalDeta
isOptimisticPersonalDetail: true,
};

return allPersonalDetails?.[accountID] ?? defaultDetails;
if (!personalDetailsData) {
return allPersonalDetails?.[accountID] ?? defaultDetails;
}

return personalDetailsData?.[accountID] ?? defaultDetails;
}

/**
Expand All @@ -1936,12 +1940,18 @@ const phoneNumberCache: Record<string, string> = {};
/**
* Get the displayName for a single report participant.
*/
function getDisplayNameForParticipant(accountID?: number, shouldUseShortForm = false, shouldFallbackToHidden = true, shouldAddCurrentUserPostfix = false): string {
function getDisplayNameForParticipant(
accountID?: number,
shouldUseShortForm = false,
shouldFallbackToHidden = true,
shouldAddCurrentUserPostfix = false,
personalDetailsData?: Partial<PersonalDetailsList>,
): string {
if (!accountID) {
return '';
}

const personalDetails = getPersonalDetailsOrDefault(allPersonalDetails?.[accountID]);
const personalDetails = getPersonalDetailsOrDefault(personalDetailsData?.[accountID] ?? allPersonalDetails?.[accountID]);
if (!personalDetails) {
return '';
}
Expand Down Expand Up @@ -3482,7 +3492,12 @@ function getInvoicesChatName(report: OnyxEntry<Report>): string {
/**
* Get the title for a report.
*/
function getReportName(report: OnyxEntry<Report>, policy?: OnyxEntry<Policy>, parentReportActionParam?: OnyxInputOrEntry<ReportAction>): string {
function getReportName(
report: OnyxEntry<Report>,
policy?: OnyxEntry<Policy>,
parentReportActionParam?: OnyxInputOrEntry<ReportAction>,
personalDetails?: Partial<PersonalDetailsList>,
): string {
let formattedName: string | undefined;
const parentReportAction = parentReportActionParam ?? ReportActionsUtils.getParentReportAction(report);
const parentReportActionMessage = ReportActionsUtils.getReportActionMessage(parentReportAction);
Expand Down Expand Up @@ -3566,7 +3581,7 @@ function getReportName(report: OnyxEntry<Report>, policy?: OnyxEntry<Policy>, pa
}

if (isSelfDM(report)) {
formattedName = getDisplayNameForParticipant(currentUserAccountID, undefined, undefined, true);
formattedName = getDisplayNameForParticipant(currentUserAccountID, undefined, undefined, true, personalDetails);
}

if (isInvoiceRoom(report)) {
Expand All @@ -3586,7 +3601,7 @@ function getReportName(report: OnyxEntry<Report>, policy?: OnyxEntry<Policy>, pa
}
});
const isMultipleParticipantReport = participantsWithoutCurrentUser.length > 1;
return participantsWithoutCurrentUser.map((accountID) => getDisplayNameForParticipant(accountID, isMultipleParticipantReport)).join(', ');
return participantsWithoutCurrentUser.map((accountID) => getDisplayNameForParticipant(accountID, isMultipleParticipantReport, true, false, personalDetails)).join(', ');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/HeaderView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function HeaderView({report, personalDetails, parentReport, parentReportAction,
const isTaskReport = ReportUtils.isTaskReport(report);
const reportHeaderData = !isTaskReport && !isChatThread && report.parentReportID ? parentReport : report;
// Use sorted display names for the title for group chats on native small screen widths
const title = ReportUtils.getReportName(reportHeaderData, undefined, parentReportAction);
const title = ReportUtils.getReportName(reportHeaderData, undefined, parentReportAction, personalDetails);
const subtitle = ReportUtils.getChatRoomSubtitle(reportHeaderData);
const parentNavigationSubtitleData = ReportUtils.getParentNavigationSubtitle(reportHeaderData);
const reportDescription = ReportUtils.getReportDescriptionText(report);
Expand Down

0 comments on commit 1147c3b

Please sign in to comment.