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

Fix archived invoice room titles #42085

Merged
merged 8 commits into from
May 30, 2024
Merged
Changes from all commits
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
45 changes: 27 additions & 18 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3207,6 +3207,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 @@ -3215,10 +3219,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 @@ -3297,7 +3297,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 @@ -5598,28 +5606,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 @@ -5643,6 +5648,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 @@ -6563,8 +6572,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
Loading