Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update invoice rooms to use correct avatars and show correct threads subtitles #41316

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,14 @@ function isInvoiceRoom(report: OnyxEntry<Report>): boolean {
return getChatType(report) === CONST.REPORT.CHAT_TYPE.INVOICE;
}

function isCurrentUserInvoiceReceiver(report: OnyxEntry<Report>): boolean {
if (report?.invoiceReceiver?.type === CONST.REPORT.INVOICE_RECEIVER_TYPE.INDIVIDUAL) {
return currentUserAccountID === report.invoiceReceiver.accountID;
}

return false;
}

/**
* Whether the provided report belongs to a Control policy and is an expense chat
*/
Expand Down Expand Up @@ -1929,8 +1937,20 @@ function getIcons(
return [domainIcon];
}
if (isAdminRoom(report) || isAnnounceRoom(report) || isChatRoom(report) || isArchivedRoom(report)) {
const workspaceIcon = getWorkspaceIcon(report, policy);
return [workspaceIcon];
const icons = [getWorkspaceIcon(report, policy)];

if (isInvoiceRoom(report)) {
if (report?.invoiceReceiver?.type === CONST.REPORT.INVOICE_RECEIVER_TYPE.INDIVIDUAL) {
icons.push(...getIconsForParticipants([report?.invoiceReceiver.accountID], personalDetails));
} else {
const receiverPolicy = getPolicy(report?.invoiceReceiver?.policyID);
if (!isEmptyObject(receiverPolicy)) {
icons.push(getWorkspaceIcon(report, receiverPolicy));
}
}
}

return icons;
}
if (isPolicyExpenseChat(report) || isExpenseReport(report)) {
const workspaceIcon = getWorkspaceIcon(report, policy);
Expand Down Expand Up @@ -6673,6 +6693,7 @@ export {
buildOptimisticInvoiceReport,
buildOptimisticInviteReportAction,
getInvoiceChatByParticipants,
isCurrentUserInvoiceReceiver,
};

export type {
Expand Down
6 changes: 5 additions & 1 deletion src/pages/home/report/ReportActionItemCreated.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ function ReportActionItemCreated(props: ReportActionItemCreatedProps) {
return null;
}

const icons = ReportUtils.getIcons(props.report, props.personalDetails);
let icons = ReportUtils.getIcons(props.report, props.personalDetails);
const shouldDisableDetailPage = ReportUtils.shouldDisableDetailPage(props.report);

if (ReportUtils.isInvoiceRoom(props.report) && ReportUtils.isCurrentUserInvoiceReceiver(props.report)) {
icons = [...icons].reverse();
}

return (
<OfflineWithFeedback
pendingAction={props.report?.pendingFields?.addWorkspaceRoom ?? props.report?.pendingFields?.createChat}
Expand Down
16 changes: 9 additions & 7 deletions src/pages/home/report/ReportActionItemSingle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,9 @@ function ReportActionItemSingle({
const {avatar, login, pendingFields, status, fallbackIcon} = personalDetails[actorAccountID ?? -1] ?? {};
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
let actorHint = (login || (displayName ?? '')).replace(CONST.REGEX.MERGED_ACCOUNT_PREFIX, '');
const displayAllActors = useMemo(
() => action?.actionName === CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW && iouReport && !ReportUtils.isInvoiceReport(iouReport),
[action?.actionName, iouReport],
);
const isWorkspaceActor = ReportUtils.isInvoiceReport(iouReport ?? {}) || (ReportUtils.isPolicyExpenseChat(report) && (!actorAccountID || displayAllActors));
const displayAllActors = useMemo(() => action?.actionName === CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW && iouReport, [action?.actionName, iouReport]);
const isInvoiceReport = ReportUtils.isInvoiceReport(iouReport ?? {});
const isWorkspaceActor = isInvoiceReport || (ReportUtils.isPolicyExpenseChat(report) && (!actorAccountID || displayAllActors));
let avatarSource = UserUtils.getAvatar(avatar ?? '', actorAccountID);

if (isWorkspaceActor) {
Expand All @@ -110,10 +108,14 @@ function ReportActionItemSingle({
const primaryDisplayName = displayName;
if (displayAllActors) {
// The ownerAccountID and actorAccountID can be the same if the a user submits an expense back from the IOU's original creator, in that case we need to use managerID to avoid displaying the same user twice
const secondaryAccountId = iouReport?.ownerAccountID === actorAccountID ? iouReport?.managerID : iouReport?.ownerAccountID;
const secondaryAccountId = iouReport?.ownerAccountID === actorAccountID || isInvoiceReport ? iouReport?.managerID : iouReport?.ownerAccountID;
const secondaryUserAvatar = personalDetails?.[secondaryAccountId ?? -1]?.avatar ?? '';
const secondaryDisplayName = ReportUtils.getDisplayNameForParticipant(secondaryAccountId);
displayName = `${primaryDisplayName} & ${secondaryDisplayName}`;

if (!isInvoiceReport) {
displayName = `${primaryDisplayName} & ${secondaryDisplayName}`;
}

secondaryAvatar = {
source: UserUtils.getAvatar(secondaryUserAvatar, secondaryAccountId),
type: CONST.ICON_TYPE_AVATAR,
Expand Down
Loading