diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index b8e4c448fdc2..458196329eb5 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3207,6 +3207,10 @@ function getReportName(report: OnyxEntry, policy: OnyxEntry = nu formattedName = getMoneyRequestReportName(report, policy); } + if (isInvoiceRoom(report)) { + formattedName = getInvoicesChatName(report); + } + if (isArchivedRoom(report)) { formattedName += ` (${Localize.translateLocal('common.archived')})`; } @@ -3215,10 +3219,6 @@ function getReportName(report: OnyxEntry, policy: OnyxEntry = nu formattedName = getDisplayNameForParticipant(currentUserAccountID, undefined, undefined, true); } - if (isInvoiceRoom(report)) { - formattedName = getInvoicesChatName(report); - } - if (formattedName) { return formattedName; } @@ -3297,7 +3297,15 @@ function getParentNavigationSubtitle(report: OnyxEntry): ParentNavigatio } if (isInvoiceReport(report) || isInvoiceRoom(parentReport)) { - return {reportName: `${getPolicyName(parentReport)} & ${getInvoicePayerName(parentReport)}`}; + let reportName = `${getPolicyName(parentReport)} & ${getInvoicePayerName(parentReport)}`; + + if (isArchivedRoom(parentReport)) { + reportName += ` (${Localize.translateLocal('common.archived')})`; + } + + return { + reportName, + }; } return { @@ -5598,28 +5606,25 @@ function temporary_getMoneyRequestOptions( * Invoice sender, invoice receiver and auto-invited admins cannot leave */ function canLeaveInvoiceRoom(report: OnyxEntry): boolean { - if (!isInvoiceRoom(report)) { - return false; - } - - const invoiceReport = getReport(report?.iouReportID ?? ''); - - if (invoiceReport?.ownerAccountID === currentUserAccountID) { + if (!report || !report?.invoiceReceiver) { return false; } - if (invoiceReport?.managerID === currentUserAccountID) { + if (report?.statusNum === CONST.REPORT.STATUS_NUM.CLOSED) { return false; } - const isSenderPolicyAdmin = getPolicy(report?.policyID)?.role === CONST.POLICY.ROLE.ADMIN; + const isSenderPolicyAdmin = getPolicy(report.policyID)?.role === CONST.POLICY.ROLE.ADMIN; if (isSenderPolicyAdmin) { return false; } - const isReceiverPolicyAdmin = - report?.invoiceReceiver?.type === CONST.REPORT.INVOICE_RECEIVER_TYPE.BUSINESS ? getPolicy(report?.invoiceReceiver?.policyID)?.role === CONST.POLICY.ROLE.ADMIN : false; + if (report.invoiceReceiver.type === CONST.REPORT.INVOICE_RECEIVER_TYPE.INDIVIDUAL) { + return report?.invoiceReceiver?.accountID !== currentUserAccountID; + } + + const isReceiverPolicyAdmin = getPolicy(report.invoiceReceiver.policyID)?.role === CONST.POLICY.ROLE.ADMIN; if (isReceiverPolicyAdmin) { return false; @@ -5643,6 +5648,10 @@ function canLeaveInvoiceRoom(report: OnyxEntry): boolean { */ function canLeaveRoom(report: OnyxEntry, isPolicyEmployee: boolean): boolean { if (isInvoiceRoom(report)) { + if (isArchivedRoom(report)) { + return false; + } + const invoiceReport = getReport(report?.iouReportID ?? ''); if (invoiceReport?.ownerAccountID === currentUserAccountID) { @@ -6563,8 +6572,8 @@ function canLeaveChat(report: OnyxEntry, policy: OnyxEntry): boo return false; } - if (canLeaveInvoiceRoom(report)) { - return true; + if (isInvoiceRoom(report)) { + return canLeaveInvoiceRoom(report); } return (isChatThread(report) && !!report?.notificationPreference?.length) || isUserCreatedPolicyRoom(report) || isNonAdminOrOwnerOfPolicyExpenseChat(report, policy);