Skip to content

Commit

Permalink
fix leave option for archived invoice room
Browse files Browse the repository at this point in the history
  • Loading branch information
rezkiy37 committed May 20, 2024
1 parent 8254e6b commit 8f7139b
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5606,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)) {
if (!report || !report?.invoiceReceiver) {
return false;
}

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

if (invoiceReport?.ownerAccountID === currentUserAccountID) {
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 Down Expand Up @@ -6575,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

0 comments on commit 8f7139b

Please sign in to comment.