Skip to content

Commit

Permalink
Merge pull request #42085 from rezkiy37/fix/41306-archive-invoice-room
Browse files Browse the repository at this point in the history
Fix archived invoice room titles
  • Loading branch information
mountiny authored May 30, 2024
2 parents 35386ee + 8f7139b commit dc17b1b
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3216,6 +3216,10 @@ function getReportName(report: OnyxEntry<Report>, policy: OnyxEntry<Policy> = nu
formattedName = getMoneyRequestReportName(report, policy);
}

if (isInvoiceRoom(report)) {
formattedName = getInvoicesChatName(report);
}

if (isArchivedRoom(report)) {
formattedName += ` (${Localize.translateLocal('common.archived')})`;
}
Expand All @@ -3224,10 +3228,6 @@ function getReportName(report: OnyxEntry<Report>, policy: OnyxEntry<Policy> = nu
formattedName = getDisplayNameForParticipant(currentUserAccountID, undefined, undefined, true);
}

if (isInvoiceRoom(report)) {
formattedName = getInvoicesChatName(report);
}

if (formattedName) {
return formattedName;
}
Expand Down Expand Up @@ -3306,7 +3306,15 @@ function getParentNavigationSubtitle(report: OnyxEntry<Report>): 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 {
Expand Down Expand Up @@ -5669,28 +5677,25 @@ function temporary_getMoneyRequestOptions(
* Invoice sender, invoice receiver and auto-invited admins cannot leave
*/
function canLeaveInvoiceRoom(report: OnyxEntry<Report>): 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;
Expand All @@ -5714,6 +5719,10 @@ function canLeaveInvoiceRoom(report: OnyxEntry<Report>): boolean {
*/
function canLeaveRoom(report: OnyxEntry<Report>, isPolicyEmployee: boolean): boolean {
if (isInvoiceRoom(report)) {
if (isArchivedRoom(report)) {
return false;
}

const invoiceReport = getReport(report?.iouReportID ?? '');

if (invoiceReport?.ownerAccountID === currentUserAccountID) {
Expand Down Expand Up @@ -6634,8 +6643,8 @@ function canLeaveChat(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>): 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);
Expand Down

0 comments on commit dc17b1b

Please sign in to comment.