Skip to content

Commit

Permalink
Merge pull request #41316 from VickyStash/bugfix/update-invoice-icons…
Browse files Browse the repository at this point in the history
…-display

Update invoice rooms to use correct avatars and show correct threads subtitles
  • Loading branch information
cristipaval authored Apr 30, 2024
2 parents 7932f87 + 8b6a48f commit 54d971a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 22 deletions.
13 changes: 8 additions & 5 deletions src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ function MoneyRequestView({
const isCardTransaction = TransactionUtils.isCardTransaction(transaction);
const cardProgramName = isCardTransaction && transactionCardID !== undefined ? CardUtils.getCardDescription(transactionCardID) : '';
const isApproved = ReportUtils.isReportApproved(moneyRequestReport);
const isInvoice = ReportUtils.isInvoiceReport(moneyRequestReport);
const taxRates = policy?.taxRates;
const formattedTaxAmount = CurrencyUtils.convertToDisplayString(transactionTaxAmount, transactionCurrency);

Expand Down Expand Up @@ -332,18 +333,20 @@ function MoneyRequestView({
);

const shouldShowMapOrReceipt = showMapAsImage || hasReceipt;
const shouldShowReceiptEmptyState = !hasReceipt && (canEditReceipt || isAdmin || isApprover);
const shouldShowReceiptEmptyState = !hasReceipt && !isInvoice && (canEditReceipt || isAdmin || isApprover);
const noticeTypeViolations = transactionViolations?.filter((violation) => violation.type === 'notice').map((v) => ViolationsUtils.getViolationTranslation(v, translate)) ?? [];
const shouldShowNotesViolations = !isReceiptBeingScanned && canUseViolations && ReportUtils.isPaidGroupPolicy(report);

return (
<View style={[StyleUtils.getReportWelcomeContainerStyle(isSmallScreenWidth, true, shouldShowAnimatedBackground)]}>
{shouldShowAnimatedBackground && <AnimatedEmptyStateBackground />}
<View style={shouldShowAnimatedBackground && [StyleUtils.getReportWelcomeTopMarginStyle(isSmallScreenWidth, true)]}>
<ReceiptAuditHeader
notes={noticeTypeViolations}
shouldShowAuditMessage={Boolean(shouldShowNotesViolations && didRceiptScanSucceed)}
/>
{!isInvoice && (
<ReceiptAuditHeader
notes={noticeTypeViolations}
shouldShowAuditMessage={Boolean(shouldShowNotesViolations && didRceiptScanSucceed)}
/>
)}
{shouldShowMapOrReceipt && (
<OfflineWithFeedback
pendingAction={pendingAction}
Expand Down
36 changes: 27 additions & 9 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,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 @@ -1941,8 +1949,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 @@ -3173,15 +3193,15 @@ function getPayeeName(report: OnyxEntry<Report>): string | undefined {
* Get either the policyName or domainName the chat is tied to
*/
function getChatRoomSubtitle(report: OnyxEntry<Report>): string | undefined {
if (isInvoiceRoom(report)) {
return Localize.translateLocal('workspace.common.invoices');
}
if (isChatThread(report)) {
return '';
}
if (isSelfDM(report)) {
return Localize.translateLocal('reportActionsView.yourSpace');
}
if (isInvoiceRoom(report)) {
return Localize.translateLocal('workspace.common.invoices');
}
if (!isDefaultRoom(report) && !isUserCreatedPolicyRoom(report) && !isPolicyExpenseChat(report)) {
return '';
}
Expand All @@ -3195,9 +3215,6 @@ function getChatRoomSubtitle(report: OnyxEntry<Report>): string | undefined {
if (isArchivedRoom(report)) {
return report?.oldPolicyName ?? '';
}
if (isInvoiceRoom(report)) {
return Localize.translateLocal('workspace.common.invoices');
}
return getPolicyName(report);
}

Expand All @@ -3218,7 +3235,7 @@ function getParentNavigationSubtitle(report: OnyxEntry<Report>): ParentNavigatio
return {};
}

if (isInvoiceReport(report)) {
if (isInvoiceReport(report) || isInvoiceRoom(parentReport)) {
return {reportName: `${getPolicyName(parentReport)} & ${getInvoicePayerName(parentReport)}`};
}

Expand Down Expand Up @@ -6705,6 +6722,7 @@ export {
buildOptimisticInviteReportAction,
getInvoiceChatByParticipants,
shouldShowMerchantColumn,
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

0 comments on commit 54d971a

Please sign in to comment.